1.4.2 • Published 4 years ago

serverless-swagger-api v1.4.2

Weekly downloads
288
License
MIT
Repository
github
Last release
4 years ago

Serverless Swagger API

Build Status Maintainability npm version FOSSA Status

This is a serverless plugin that simplifies the process of creating an AWS API Gateway from a swagger file.

Installation

yarn add --dev serverless-swagger-api

Configuration

Lambda Functions

You must manually create your own lambda functions in the serverless configuration. Once the methods are created, they will be referenced in the swagger file.

Swagger File

Add a x-lambda-name property to every path method to bind a part of the api to a lambda.

paths:
  /testPath:
    get:
      x-lambda-name: TestPathLambdaFunction
      ...

CORS Configuration

Add a x-cors property to the path you want to add CORS options responses to.

paths:
  /testPath:
    x-cors: true

If you want to specify a specific attribute, provide one of the following properties

PropertyDescriptionDefault
originA string specifying allowed origins*
headersAn array of headers to be allowedConstructed from the parameters property of every path method
methodsAn array of methods to be allowedConstructed by looking at all methods defined for a path

Plugin Settings

Now you need to tell the swagger api plugin about your configuration file. Add a swaggerApi property to the custom section of your serverless configuration. You can add as many apis as you want by adding children to the swaggerApi.apis property.

updateDeployments

Will automatically update API gateway deployments if not set to false.

usePackageVersion

The info.version value in your OpenAPI file will be overwritten with the version in package.json.

apis

An object containing all of the APIs to be defined in this stack.

custom:
  swaggerApi:
    updateDeployments: true
    usePackageVersion: true
    apis:
      PrimaryApi:
        Name: ${self:provider.stage}-${self:service}-PrimaryApi
        Body: ${file(./some-swagger-file.yaml)}
        Lambda: ExampleLambdaFunction
        Stage: dev
Properties

Each API object has the following properties

NameRequiredDescription
NameYesName of the API that will be used as the Name parameter when creating the AWS::ApiGateway::RestApi CloudFormation object
BodyYesThe swagger/openapi file that defines the API
StageYesThe name of the API Gateway stage that will be created
LambdaNoDefault lambda name that will be used if x-lambda-name isn't provided on a path

Created Resources

IAM Roles

An IAM role is created for each API with the name PrimaryApiServiceRole

License

FOSSA Status

1.4.2

4 years ago

1.4.1

4 years ago

1.4.0

4 years ago

1.3.2

4 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.8

5 years ago

1.2.7

5 years ago

1.2.6

5 years ago

1.2.5

5 years ago

1.2.4

5 years ago

1.2.3

5 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.18

5 years ago

1.0.16

5 years ago

1.0.15

5 years ago

1.0.13

5 years ago

1.0.12

5 years ago

1.0.11

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago