Repository navigation
Attributes
Radish uses attributes to generate documentation for REST API methods.
When you call Content getter of Documentor instance, Radish scans calling assembly (or any other assemblies specified in parameters of Documentor's constructor) and detects attribute-marked methods to be included in the documentation.
Only one attibute (MethodAttribute) is mandatory and others are optional.
- RadishAttribute
- MethodAttribute
- MethodTitleAttribute
- MethodDescriptionAttribute
- RequestParameterAttribute
- RequestBodyDescriptionAttribute
- RequestBodyExampleAttribute
- ResponseBodyDescriptionAttribute
- ResponseBodyExampleAttribute
- ResponseCodeAttribute
- OrderAttribute
All Radish attributes are derived from abstract RadishAttribute. If you want to [add new attribute](Custom Attributes) that should be recognized by documentor, inherit it from RadishAttribute.
This is a single mandatory attribute required by Radish. If this attribute is specified, method will be included in the documentation.
Defines REST API method type (GET, POST, PUT and etc.) and method route (URL path).
Also you can specify optional identifier of the method within the documentation. This identifier can be used for many purposes, in particular, as html anchor tag. If no identifier is specified, Radish will generate new id from random GUID.
Specify method type and route. Id is not specified, random GUID will be used:
[Method("GET", "/api/pets/")]Specify method type, route and unique method id:
[Method("GET", "/api/pets/", "get-all-pets")]This attribute is used for defining title of the REST API method in the documentation:
[MethodTitle("Get pet")]Use this attribute to describe REST API method definition:
[MethodDescription("Returns Pet object by specified id.")]Used to define query parameters for the REST API method. You should specify at least query parameter name, parameter type and description. Also you can specify:
- is the parameter required or optional;
- order of the query parameter in the documentation output.
More than one instance of this attribute can be specified for the REST API method handler.
If many parameters were defined, they will be grouped into a table and ordered according to order value passed to the attribute constructor.
Minimal usage:
// GET: "/api/pets/{id}"
[RequestParameter("id", "Integer", "Id of the Pet")]Query parameter is optional:
// GET: "/api/pets/{id}"
[RequestParameter("id", "Integer", "Id of the Pet", false)]Specify order of the query parameter in the documentation output:
// GET: "/api/pets/{id}"
[RequestParameter("id", "Integer", "Id of the Pet", 2)]Specify optionalily and order:
// GET: "/api/pets/{id}"
[RequestParameter("id", "Integer", "Id of the Pet", false, 2)]Specify multiple query parameters for the one method, with order:
// GET: "/api/persons/{personId}/pets/{petIndex}"
[RequestParameter("personId", "Integer", "Id of the Person", 1)]
[RequestParameter("petIndex", "Integer", "Zero-based index of the Person's pet", 2)]Use this attribute to describe request body of the REST API method:
// POST: "/api/pets"
[RequestBodyDescription("Json-serialized Pet object to be added")]Use this attribute to give an example of data to be passed as request body for the REST API method:
// POST: "/api/pets"
[RequestBodyExample(@"{""AnimalType"":""Cat"",""Name"":""Lisa""}")]The example above will be formatted in the documentation like:
{
"AnimalType": "Cat",
"Name": "Lisa"
}Radish supports JSON, XML and raw string data formats as parameters of RequestBodyExampleAttribute constructor.
Data format is needed for proper formatting and code highlighting of the data in the output documentation.
Optionally, you can explicitly specify format of the data like this:
// POST: "/api/pets"
[RequestBodyExample(@"{""AnimalType"":""Cat"",""Name"":""Lisa""}", DataFormat.Json)]If no data format was specified, Radish will try to detect it automatically: < and > in the body will be recognized as XML data, { and } as JSON data. In other cases data format assumed to be a raw string without formatting.
Use this attribute to describe response body of the REST API method:
// GET: "/api/pets/{id}"
[ResponseBodyDescription("Json-serialized Pet object matching the specified id.")]Use this attribute to give an example of data to be returned by the REST API method:
// GET: "/api/pets/{id}"
[ResponseBodyExample(@"{""Id"":17,""AnimalType"":""Cat"",""Name"":""Lisa""}")]The example above will be formatted in the documentation like:
{
"Id": 17,
"AnimalType": "Cat",
"Name": "Lisa"
}As well as for RequestBodyExampleAttribute, three data formats are supported: JSON, XML and raw string. To specify data format explicitly, write:
// GET: "/api/pets/{id}"
[ResponseBodyExample(@"{""AnimalType"":""Cat"",""Name"":""Lisa""}", DataFormat.Json)]Use this attribute to describe HTTP status codes to be returned by the REST API method. One or more attributes of this type are allowed:
// GET: "/api/pets/{id}"
[ResponseCode(200, "OK. On successful result.")]
[ResponseCode(404, "Not Found. When pet with specified id was not found.")]This attribute can be used for two purposes: grouping methods together and sorting.
REST API methods can be grouped logically in the documentation into sections. For example, in this demo there are 2 logical groups of REST methods: Persons and Pets.
Also you can optionally specify an order of the REST API method in the documentation output. Methods will be ordered ascending, and methods with smaller order values will be placed first.
If both order and group are specified, ordering will be performed inside the group. About defining groups and theirs orders, read here.
Put the method into the group with key pets:
[Order("pets")]Do not specify a group, but set an order:
[Order(1)]Specify a group and order inside the group:
[Order("pets", 1)]Back to main page of the documentation.