ColdBox Relax
Search…
cbSwagger Companion Module
The cbSwagger module for ColdBox allows you to quickly scaffold your documentation by performing an auto-discovery of your routes and the associated component metadata. To operate, the module requires that SES routing be enabled in your application. For more information read the official documentation.

Installation ( via Commandbox )

box install cbswagger
Note: Omit the box from your command, if you are already in the Commandbox interactive shell

Configure cbSwagger to auto-detect your API Routes

By default, cbSwagger looks for routes beginning with api. By adding a cbSwagger configuration key to your Coldbox configuration, you can add additional metadata to the OpenAPI JSON produced by the module entry point. A full configuration example is provided below:
1
cbswagger = {
2
// The route prefix to search. Routes beginning with this prefix will be determined to be api routes
3
"routes":["api"],
4
//A base path prefix for your API - leave blank if all routes are configured to the root of the site
5
"basePath":"",
6
//The API host
7
"host":"",
8
// Information about your API
9
"info":{
10
//The contact information
11
"contact":{
12
"name":"",
13
"email":""
14
},
15
//A title for your API
16
"title":"",
17
//A descritpion of your API
18
"description":"",
19
//A url to the License of your API
20
"license":{
21
"name":"",
22
"url":""
23
},
24
//A terms of service URL for your API
25
"termsOfService":"",
26
//The version of your API
27
"version":""
28
},
29
//An array of all of the request body formats your your API is configured to consume
30
"consumes": ["application/json","multipart/form-data","application/x-www-form-urlencoded"],
31
//An array of all of the response body formats your API delivers
32
"produces": ["application/json"]
33
};
Copied!

Handler Introspection & Documentation attributes

cbSwagger will automatically introspect your API handlers provided by your routing configuration. You may provide additional function attributes, which will be picked up and included in your documentation. Some notes on function attributes:
  • Attributes which are not part of the swagger path specification should be prefixed with an x-, x-attributes are an official part of the OpenAPI Specification and may be used to provide additional information for your developers and consumers
  • You may also provide paths to JSON files which describe complex objects which may not be expressed within the attributes themselves. This is ideal to provide an endpoint for parameters and responses If the atttribute ends with .json, this will be included in the generated OpenAPI document as a $ref include.
Example:
1
//(POST) /api/v1/users
2
function add(event,rc,prc)
3
description="Adds a new user"
4
parameters="/includes/resources/users.add.parameters.json"
5
responses="/includes/resources/users.add.responses.json"
6
x-SomeAdditionalInfo="Here is some additional information on this path"
7
{
8
9
...[ Your code here ]...
10
11
}
Copied!
Last modified 3yr ago