MCPcopy
hub / github.com/Surnet/swagger-jsdoc

github.com/Surnet/swagger-jsdoc @v6.3.0 sqlite

repository ↗ · DeepWiki ↗ · release v6.3.0 ↗
21 symbols 39 edges 37 files 13 documented · 62%
README

swagger-jsdoc

This library reads your JSDoc-annotated source code and generates an OpenAPI (Swagger) specification.

npm Downloads CI

Getting started

Imagine having API files like these:

/**
 * @openapi
 * /:
 *   get:
 *     description: Welcome to swagger-jsdoc!
 *     responses:
 *       200:
 *         description: Returns a mysterious string.
 */
app.get('/', (req, res) => {
  res.send('Hello World!');
});

The library will take the contents of @openapi (or @swagger) with the following configuration:

const swaggerJsdoc = require('swagger-jsdoc');

const options = {
  definition: {
    openapi: '3.0.0',
    info: {
      title: 'Hello World',
      version: '1.0.0',
    },
  },
  apis: ['./src/routes*.js'], // files containing annotations as above
};

const openapiSpecification = swaggerJsdoc(options);

The resulting openapiSpecification will be a swagger tools-compatible (and validated) specification.

swagger-jsdoc example screenshot

System requirements

  • Node.js 20.x or higher

You are viewing swagger-jsdoc v6 which is published in CommonJS module system.

Installation

npm install swagger-jsdoc --save

Or

yarn add swagger-jsdoc

Supported specifications

  • OpenAPI 3.x
  • Swagger 2
  • AsyncAPI 2.0

Validation of swagger docs

By default swagger-jsdoc tries to parse all docs to it's best capabilities. If you'd like to you can instruct an Error to be thrown instead if validation failed by setting the options flag failOnErrors to true. This is for instance useful if you want to verify that your swagger docs validate using a unit test.

const swaggerJsdoc = require('swagger-jsdoc');

const options = {
  failOnErrors: true, // Whether or not to throw when parsing errors. Defaults to false.
  definition: {
    openapi: '3.0.0',
    info: {
      title: 'Hello World',
      version: '1.0.0',
    },
  },
  apis: ['./src/routes*.js'],
};

const openapiSpecification = swaggerJsdoc(options);

Documentation

Click on the version you are using for further details:

Core symbols most depended-on inside this repo

mergeDeep
called by 3
src/utils.js
isTagPresentInTags
called by 2
src/utils.js
prepare
called by 1
src/specification.js
getVersion
called by 1
src/specification.js
format
called by 1
src/specification.js
clean
called by 1
src/specification.js
finalize
called by 1
src/specification.js
organize
called by 1
src/specification.js

Shape

Function 21

Languages

TypeScript100%

Modules by API surface

src/utils.js10 symbols
src/specification.js7 symbols
docusaurus/src/pages/index.js2 symbols
examples/eventDriven/src/modules/userSignUp.ts1 symbols
examples/eventDriven/src/modules/userSignIn.ts1 symbols

Dependencies from manifests, versioned

@apidevtools/swagger-parser12.1.0 · 1×
@docusaurus/core2.0.1 · 1×
@docusaurus/eslint-plugin2.0.1 · 1×
@docusaurus/module-type-aliases2.0.1 · 1×
@docusaurus/preset-classic2.0.1 · 1×
@mdx-js/react1.6.22 · 1×
body-parser1.20.4 · 1×
clsx1.2.1 · 1×
commander6.2.0 · 1×
doctrine3.0.0 · 1×
eslint8.57.1 · 1×
eslint-config-airbnb-base15.0.0 · 1×

For agents

$ claude mcp add swagger-jsdoc \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact