Firstly install swagger if not already present
Check if swagger already installed:
which swagger
Alternatively install swagger:
npm i -g swaggger
To create a new application:
swagger project create <project-name>
To edit the swagger configuration file:
swagger project edit
To start/run the project:
swagger project start
To run the test suite:
swagger project test
To run swagger with debugger tools:
DEBUG=swagger-tools* swagger project start
Once a project is generated, there will be a directory called api and a test. Inside api you will find a folder called swagger. That'e where the magic happens. In the swagger.yaml file you will be able to edit the endpoints for your API.
This is a sample of an endpoint in Swagger:
/check:
# binds a127 app logic to a route
x-swagger-router-controller: check_postcode
get:
description: Returns whether the given postcode is served by Harper
# used as the method name of the controller
operationId: check_postcode
parameters:
- name: postcode
in: query
description: The postcode to be checked
required: false
type: string
responses:
"200":
description: Success
schema:
# a pointer to a definition
$ref: "#/definitions/PostcodeResponse"
# responses may fall through to errors
default:
description: Error
schema:
$ref: "#/definitions/ErrorResponse"
Please note that the above config refer to definitions/ErrorResponse which is normally defined at the bottom of the file in the definitions section: