Import functions from OpenAPI spec filet to serverless.yml
npm install serverless-import-swagger
In v0.2, there are breaking changes.
Please be careful when upgrading.
```
$ npm install -g serverless-import-swagger
on application root directory.
Then, run following command and serverless-import-swagger generate service of Serverless Framework. `
$ sis
`Command option.
`
Usage: sis [options]Import functions from OpenAPI spec filet to serverless.yml
Options:
-V, --version output the version number
-C, --config Specify config file path. (defailt "./sis.config.json")
-s, --service-name Specify service name. (default "service")
-i, --input [path] Specify OpenAPI file path. (defailt "./openapi.ya?ml")
-o, --out-dir Specify dist directory of services. (default "./")
-c, --common Specify common config of serverless file path. (default "./serverless.common.ya?ml")
-f, --force If add this option, overwriten serverless.yml by generated definitinos.
-h, --help output usage information
`Example
`
$ sis -i /path/to/swagger.yml -c /path/to/serverless.common.yml -o ./src
`sis.config.json
You can set options using a configuration file. By default, sis.config.json will be applied automatically if it exists. `
{
"all": , // Specify whether to target all of the document. (default true)
"serviceName": , // Specify service name. (default "service")
"basePath": }>, // Specify base path mode enabled. (defualt false)
"input": , // Specify OpenAPI file path. (defailt "./openapi.ya?ml")
"outDir": , // Specify dist directory of services. (default "./")
"common": , // Specify common config of serverless file path. (default "./serverless.common.ya?ml")
"force": , // Specify overwrite enabled. (default false)
"options": {
"cors": , // Specify the addition of cors setting. Accept the format of the Serverless Framework's cors settings. (default false)
"optionsMethod": , // Specify addition of options method for the path. (default false)
"authorizer": , // Specify AWS_IAM authorizers or custom authorizers. (default null)
"operationId": // Specify use of operationId in function name. (default false)
}
}
`
The default values apply to items not set. Base path mode
Due to the limitations of CloudFormation, it is not possible to create a service with a large number of endpoints.
The base path mode splits services based on the top level path.
If base path mode is set to true, the top level path will be the service name. If you specify servicePrefix, a prefix can be added before the service name. x-sis-config
You can use the extension of x-sis-config to write config in the spec file.
The config at the top level apply to the entire file, and the config at operation parameters apply only to that function.
If you disable all in config, only operations for which x-sis-config is set are imported. Caution
Serverless depends on constraints of amazon web service.
For example...+ The maximum number of CloudFormation resources is 200. Therefore, APIs that contain many paths need to be divided using
--base-path` mode.