OpenAPI (AKA Swagger)
As of Relax v2.3 and above, the OpenAPI v2.0 is the default format for documentation in Relax. The previous RelaxDSL has been deprecated and is schedule to sunset at Relax v4.0.
The OpenAPI specification offers a convenient and portable way to describe your API, its requirements, parameters, and data conventions. You may also choose to use this to describe your API in the form of HTTP OPTIONS responses to fulfill CORS requirements or to allow rich hypermedia documentation for your consumers.
By convention, Relax looks for supported formats in the following order (note that the top-level file shares the name of the parent directory):
myResourceDirectory/myapi/myapi.json
- JSON OpenAPI schemamyResourceDirectory/myapi/myapi.yaml
- YAML OpenAPI schemamyResourceDirectory/myapi/Relax.cfc
- Relax programmatic DSL (deprecated)
Example ( a segment of the Forgebox API ):
Note the use of the x-
attributes, which allow for extensions of the Swagger specification, In addition, more complex API's can use the $ref
syntax to denote locations and keys of relative JSON files:
This notates that the definition for the path /echo
is found in paths.json
under the echo
key. Using the $ref
notation allows you to store schema examples and other code samples separate from the main JSON or YAML description of your site.
YAML Support
Per the Swagger formats description:
The files describing the RESTful API in accordance with the Swagger specification are represented as JSON objects and conform to the JSON standards. YAML, being a superset of JSON, can be used as well to represent a Swagger specification file.
Relax includes support for YAML-format API descriptions, as well.
For full descriptions and examples of the schema specification read the official OpenAPI v2 specification.
Last updated