Serverless plugin to resolve $ref
syntax of OpenAPI3
npm install --save serverless-openapi3-plugin
plugins:
- serverless-openapi3-plugin
custom:
openApiPath: './resources/open-api/index.yaml' # OpenApi File
When you want to use $ref
syntax in OpenApi File, use this plugin.
The example project uses example API of Amazon API Gateway.
.
├── resources
│ ├── api-gateway.yaml # ApiGateway Resource
│ └── open-api
│ ├── index.yaml # OpenApi Entry File
│ ├── components
│ │ └── schemas.yaml
│ └── paths
│ ├── pets-id.yaml
│ ├── pets.yaml
│ └── root.yaml
└── serverless.yml
# serverless.yaml
...
resources:
- ${file(./resources/api-gateway.yaml)}
# resources/api-gateway.yaml
Resources:
RestApi:
Type: AWS::ApiGateway::RestApi
Properties:
Name: rest-api
Body: ${file(./resources/open-api/index.yaml)} # OpenApi Entry File
# resources/open-api/index.yaml
paths:
/pets:
$ref: './paths/pets.yaml'
/pets/{petId}:
$ref: './paths/pets-id.yaml'
/:
$ref: './paths/root.yaml'
components:
schemas:
$ref: './components/schemas.yaml'