JavaScript
Clone or download

README.md

swagger-jsdoc

Document your code and keep a live and reusable OpenAPI (Swagger) specification. This specification can be the core of your API-driven project: generate documentation, servers, clients, tests and much more based on the rich OpenAPI ecosystem of tools.

npm Version npm Downloads Circle CI Known Vulnerabilities

Goals

swagger-jsdoc enables you to integrate Swagger using JSDoc comments in your code. Just add @swagger on top of your DocBlock and declare the meaning of your code in yaml complying to the OpenAPI specification.

swagger-jsdoc will parse your documentation from your actual living code and output an OpenAPI specification to integrate any server and client technology as long as both sides comply with the specification.

Thus, the swagger-jsdoc project assumes that you want document your existing working code in a way to "give life" to it, generating a specification which can then be fed into other Swagger tools, and not the vice-versa.

If you prefer to write the OpenAPI specification first and separately, you might check other projects facilitating this, such as

Supported versions

  • OpenAPI 3.x
  • Swagger 2.0

You can find the corresponding documentation in the official repository of the specification.

Install

$ npm install swagger-jsdoc --save

Or using yarn

$ yarn add swagger-jsdoc

Quick Start

Get started by documenting your code.

Note that swagger-jsdoc uses node glob module in the background when taking your files. This means that you can use patterns such as *.js to select all javascript files or **/*.js to select all javascript files in sub-folders recursively.

Example app

There is an example app in the example subdirectory. To use it you can use the following commands:

$ git clone https://github.com/Surnet/swagger-jsdoc.git
$ cd swagger-jsdoc
$ npm install
$ npm start

The swagger spec will be served at http://localhost:3000/api-docs.json

CLI

You can also use the tool via command line interface.

Contributing

  • Fork this project and clone locally
  • Branch for each separate feature
  • Write detailed commit messages, comment unclear code blocks and update unit tests
  • Push to your own repository and create a new PR to merge back into this repository