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