serverless_swagger v1.0.3
Serverless Swagger
Maps swagger configuration to serverless handlers.
Installation
If you don't have a serverless project, create one now:
sls create -t aws-nodejs --path MyService
cd MyService
yarn initInside your serverless project directory:
yarn add swagger_serverlessAdd the following to serverless.yml:
plugins:
- serverless_swaggerConfiguration
The plugin looks for a swagger.yml in your serverless project.
You can provide a different name by specifying a custom variable:
custom:
swagger_file: swagger.ymlGeneration
A complete set of JS handlers and the appropriate serverless.yml configuration can be generated
sls swaggerExisting files should not be overwritten, meaning that the swagger can be updated and new functions generated without losing customisations.
Generated files can be output to a specified directory using the --output flag and a destination directory (which must exist).
sls swagger --output outputMapping
At deploy, each function will be mapped to API Gateway events based on the swagger specification.
Functions are mapped by parsing the path and method in the swagger spec to a function name in serverless.yml.
For example, given the following serverless.yml and swagger.yml definitions
functions:
getClientById:
handler: getClientById/handler.main
getClientByName:
handler: getClientByName/handler.main paths:
/client/{id}:
get:
summary: "Get client id"
/blah
get:
summary: "Get blah" The getClientById function will be mapped to an API gateway event in the form:
events:
- http:
method: get
path: /client/{id}The getClientByName does not match any summary information and will not have an event