Skip to content

Example of how to split long swagger.yaml file into multiple files following the pattern of your API endpoints.

License

Notifications You must be signed in to change notification settings

matoushavlena/swagger-express-api-splitter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

#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.

About

Example of how to split long swagger.yaml file into multiple files following the pattern of your API endpoints.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published