BasicTemplateSet - AlexanderKrutov/Radish GitHub Wiki
Note: It's recommended to familiarize with key concepts before reading this article.
Designation
This is a base class for two predefined template sets used by Radish: SimpleTemplateSet and BootstrapTemplateSet.
The BasicTemplateSet class is needed as a layer because two template sets use the same templating logic, including common tags, replacement rules and template names.
The difference between template sets is only in appearance of output content.
If you want to create your own template set to display documentation with custom styles and formatting, without changing logic of templates, you should inherit from BasicTemplateSet.
Templates and Tags
Below is a comprehensive information about templates and their tags defined in BasicTemplateSet (and therefore in two descendant template sets).
Page
Template for whole documentation page. Inherited from AbstractTemplateSet. Tags:
{{title}}— title of the documentation page. Will be displayed at the top of the documentation page. To set the title, please use aTitleproperty ofBasicTemplateSet{{methods-list}}— list of REST API methods. Will be replaced by rendering results ofMethodtemplate{{json-methods-list}}— will be replaced by JSON object that contains info about REST API methods. Used for navigation and for searching by methods.
MethodsGroup
Template for displaying information about group of methods. There are two tags defined:
{{title}}— for displaying group's title{{description}}— for displaying group's description
Method
Template for displaying information about particular REST API method.
Replacements of following four tags are taken from the values of appropriate properties of MethodAttribute:
{{method}}— prints REST API method type defined byMethodAttribute.MethodType, like GET, POST, PUT and etc.{{id}}— prints unique id of a method defined byMethodAttribute.Id{{title}}— prints method title defined byMethodAttribute.Title{{description}}— prints a method description defined byMethodAttribute.Description
Other tags will be replaced by otputs of nested templates:
{{request-parameters-list}}— will be replaced by RequestParametersList template output{{request-body}}— will be replaced by RequestBodyDescription template output{{request-body-example}}— will be replaced by RequestBodyExample template output{{response-body}}— will be replaced by ResponseBodyDescription template output{{response-body-example}}— will be replaced by ResponseBodyExample template output{{response-codes-list}}— will be replaced by ResponseCodesList template output
RequestParametersList
Template for rendering header and a table of request parameters of the method. Header of the table is a text: Request Parameters;. Only one tag is defined:
{{request-parameters-list}}— prints the table itself
RequestParameter
Displays particular row from the table of parameters. Information for each row is taken from RequestParameterAttribute. Tags are:
{{name}}— prints name of the request parameter as defined byRequestParameterAttribute.Namevalue{{type}}— prints type of the parameter as defined byRequestParameterAttribute.Typevalue{{required}}— prints True or False word depend on value ofRequestParameterAttribute.Required{{description}}— prints description of the parameter as defined byRequestParameterAttribute.Descriptionvalue
RequestBodyDescription
Used for displaying documentation section that contains description of the request body. Section has header text: Request. Only one tag is defined:
{{description}}— prints the description of the request body
RequestBodyExample
Template for documentation section with an example of REST API method request body. Has title Request example at the top. Uses tags:
{{data}}— prints request body data itself, in JSON, XML or raw text form, as defined byRequestBodyExampleAttribute.Datavalue{{data-format}}— prints request body data format type (Json, Xml or Raw) string depend onRequestBodyExampleAttribute.Formatvalue{{id}}— prints REST API method unique key
ResponseBodyDescription
Used for displaying documentation section that contains description of the response body. Section has header text: Response. Only one tag is defined:
{{description}}— prints the description of the response body
ResponseBodyExample
Template for documentation section with an example of REST API method response body. Has title Response example at the top. Uses tags:
{{data}}— prints response body data itself, in JSON, XML or raw text form, as defined byResponseBodyExampleAttribute.Datavalue{{data-format}}— prints response body data format type (Json, Xml or Raw) string depend onResponseBodyExampleAttribute.Formatvalue{{id}}— prints REST API method unique key
ResponseCodesList
Template for rendering header and a list of HTTP status codes of the method. Header of the table is a text: Response Codes;. Only one tag is defined:
{{response-codes-list}}— prints the list itself
ResponseCode
Displays particular item from the list of response codes. Information for each item is taken from ResponseCodeAttribute. Tags are:
{{code}}— prints the HTTP status code as defined byResponseCodeAttribute.Codevalue{{description}}— — prints the explanation of HTTP status code as defined byResponseCodeAttribute.Descriptionvalue
Summary
To summarize this article, here is a tree of nesting levels of the templates and related tags that were described above.
Repeatable sections are marked with * symbol:
Page
├─ Title
├─ MethodsGroup
│ ├─ {{title}}
│ └─ {{description}}
└─ Method*
├─ {{method}}
├─ {{id}}
├─ {{title}}
├─ {{description}}
├─ RequestParametersList
│ └─ RequestParameter*
│ ├─ {{name}}
│ ├─ {{type}}
│ ├─ {{required}}
│ └─ {{description}}
├─ RequestBodyDescription
│ └─ {{description}}
├─ RequestBodyExample
│ ├─ {{data}}
│ ├─ {{data-format}}
│ └─ {{id}}
├─ ResponseBodyDescription
│ └─ {{description}}
├─ ResponseBodyExample
│ ├─ {{data}}
│ ├─ {{data-format}}
│ └─ {{id}}
└─ ResponseCodesList
└─ ResponseCode*
├─ {{code}}
└─ {{description}}