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.
swagger-jsdoc enables you to integrate Swagger
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.
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
- OpenAPI 3.x
- Swagger 2.0
You can find the corresponding documentation in the official repository of the specification.
$ npm install swagger-jsdoc --save
$ yarn add swagger-jsdoc
Get started by documenting your code.
swagger-jsdoc uses node glob module in the background when taking your files. This means that you can use patterns such as
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
You can also use the tool via command line interface.
- 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