npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

serverless-import-swagger

v0.2.2

Published

Import functions from OpenAPI spec filet to serverless.yml

Downloads

2,434

Readme

serverless-import-swagger

Import functions from OpenAPI spec file to serverless.yml of Serverless Framework

Build Status

Note

In v0.2, there are breaking changes.
Please be careful when upgrading.

Install

$ npm install -g serverless-import-swagger

Usage

Quick start

Add a file named openapi.yaml 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 <path>           Specify config file path. (defailt "./sis.config.json")
  -s, --service-name <string>  Specify service name. (default "service")
  -i, --input [path]            Specify OpenAPI file path. (defailt "./openapi.ya?ml")
  -o, --out-dir <path>          Specify dist directory of services. (default "./")
  -c, --common <path>           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": <boolean>, // Specify whether to target all of the document. (default true)
  "serviceName": <string>, // Specify service name. (default "service")
  "basePath": <boolean | { "servicePrefix": <string> }>, // Specify base path mode enabled. (defualt false)
  "input": <string[] | null>, // Specify OpenAPI file path. (defailt "./openapi.ya?ml")
  "outDir": <string | null>, // Specify dist directory of services. (default "./")
  "common": <string | null>, // Specify common config of serverless file path. (default "./serverless.common.ya?ml")
  "force": <boolean>, // Specify overwrite enabled. (default false)
  "options": {
    "cors": <boolean | any>, // Specify the addition of cors setting. Accept the format of the Serverless Framework's cors settings. (default false) 
    "optionsMethod": <boolean>, // Specify addition of options method for the path. (default false)
    "authorizer": <string | null>, // Specify AWS_IAM authorizers or custom authorizers. (default null)
    "operationId": <boolean> // 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.
  • The function name of AWS Lambda must be 64 characters or less. For that reason, if long function names are generated, they can not be deployed.
  • API Gateway requires that path parameters in the same hierarchy be unique. Serverless also suffers from similar restrictions.