Skip to content

Latest commit

 

History

History
executable file
·
27 lines (19 loc) · 1.45 KB

README.md

File metadata and controls

executable file
·
27 lines (19 loc) · 1.45 KB

#swagger-express-api-splitter

This is an example of a code that allows you to split your long swagger.yaml file into multiple yaml files following the API pattern of your app. For each of the REST API endpoint, you keep 3 files:

  • JS implementation - for example /api/controllers/UsersController.js
  • Swagger model definition - for example /api/definitions/UsersDefinition.yaml
  • Swagger path description - for example /api/paths/UsersPath.yaml

Then we use the gulp script, that watches for changes in these files and automatically compiles the swagger.yaml file which is consumed by SwaggerExpress. This allows you to break your swagger implementation into several files that are easier to maintain:

alt Folder Structure

#Dependencies

  • swagger-express-mw
  • swagger-tools
  • gulp

#Demo

  • npm install
  • gulp
  • node app.js

After that, you can open http://localhost:3000/docs/ and you should see your Swagger documentation.

alt Swagger Docs

#Additional info The swagger.yaml file is automatically generated using gulp. Gulp is watching for changes and compiles the file on fly. Everytime time you do changes in API folder, you need to restart the node.js server. You can use nodemon to simplify this process.