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

swagger-tools-oas3

v1.2.0

Published

Swagger-UI and API Rest Routing for Open API v3.

Downloads

109

Readme

swagger-tools-oas3

This tool helps to setup a Express.js server along with Swagger UI. It also includes a middleware to validate the request and response against the provided OpenAPI 3.0 specification. The original project is not maintained anymore and has some vulnerabilities. This fork aims to fix those vulnerabilities and keep the project up to date.

Table of Contents

Usage

Installation

Install the package using npm:

npm install swagger-tools-oas3

Middleware Options

The expressAppConfig function accepts the following options:

  • definitionPath: The path to your OpenAPI 3.0 specification file.
  • appOptions: An object containing additional configuration options:
    • routing: An object specifying the routing options, such as the path to your controller files.
      const options = {
        routing: {
            controllers: path.join(__dirname, './controllers'),
        }
      };
    • parserLimit: (Optional) The limit for body parsing (default: '1mb').
      const options = {
        routing: {
            controllers: path.join(__dirname, './controllers'),
        },
        parserLimit: '1mb'
      };
    • app: (Optional) An existing Express.js app instance to use.
      const options = {
        routing: {
            controllers: path.join(__dirname, './controllers'),
        },
        app: express()
      };
    • cors: (Optional) CORS configuration options.
      const options = {
        routing: {
            controllers: path.join(__dirname, './controllers'),
        },
        cors: {
          origin: 'http://example.com'
        }
      };
    • internalLogs: (Optional) A boolean value to enable/disable internal logs (default: true).
      const options = {
        routing: {
            controllers: path.join(__dirname, './controllers'),
        },
        internalLogs: false
      };
    • logging: (Optional) An object specifying the logging options (Takes options of morgan).
      const options = {
        routing: {
            controllers: path.join(__dirname, './controllers'),
        },
        logging: {
          format: 'combined'
        }
      };

Example

const options = {
    routing: {
        controllers: path.join(__dirname, './controllers'),
    }
};

const expressAppConfig = oas3Tools.expressAppConfig(path.join(__dirname, './api/openapi.yaml'), options);

const app = expressAppConfig.getApp();

Changelogs

1.2.0

  • Updated dependencies to the latest version.
  • Added helmet middleware to secure the app.
  • Updated the code to only add CORS and Morgan middleware if the options are provided.
  • Removed the debug package as it is marked as vulnerable. replaced it with a simple console.log.
  • Also added an option to disable internal logs.
  • Added examples of all options in documentation.

1.1.0

  • Updated dependencies to the latest version.
  • Fixed the Swagger UI not showing the configured spec.
  • Removed body-parser and used express inbuilt body-parser instead.
  • Added option to add middleware before the validation middleware.
  • Removed all the unused dependencies.
  • Updated the tsconfig.json to target es2019, to fix the issue with the latest version of node (Supports Node.js 12+).

1.0.0

  • Initial release, forked from oas3-tools of bug-hunters.
  • Updated dependencies to fix vulnerabilities.
  • Added option to pass limit for body-parser.

Note: This is a forked project from https://github.com/bug-hunters/oas3-tools which was originally forked from https://github.com/apigee-127/swagger-tools.