swagger-express-typescript
Automatically generate and serve swagger.json v2.0.
Getting started
First, install swagger-express-typescript.
npm install swagger-express-typescript --save
The Basics
In the examples below, we use inversify-express-utils. inversify-express-utils is not required to work with swagger-express-typescript.
Step 1: configure express
;;;;;;;;; // set up container; // note that you *must* bind your controllers to Controllercontainer.bind TYPE.Controller .to VersionController .inSingletonScope.whenTargetNamed VersionController.TARGET_NAME ; // create server; server.setConfig ; server.setErrorConfig ; ; app.listen config.port ;console.info "Server is listening on port : " + config.port ;
Step 2: Decorate your models
Step 3: Decorate your controllers
Step 4: Test
Start your server and test on url : /api-docs/swagger.json
Extra
Serve swagger-ui in your API
You can serve swagger.json and swagger-ui in your API.
npm install swagger-ui-dist --save
Create index.html in new directory "swagger".
<!-- HTML for static distribution bundle build --> Swagger UI
Configure your server like that.
app.use '/api-docs/swagger', express.static 'swagger' ;app.use '/api-docs/swagger/assets', express.static 'node_modules/swagger-ui-dist' ;
Test it on url "/api-docs/swagger".
Project example
You can quickly test swagger-express-typescript with the project example example-swagger-express-typescript.
Features and API
- Installation
- Configuration
- @ApiModel
- @ApiModelProperty
- @ApiPath
- @ApiOperationGet
- @ApiOperationPost
- @ApiOperationPut
- @ApiOperationPatch
- @ApiOperationDelete
For any questions, suggestions, or feature requests
Help wanted
swagger-express-typescript wants additional maintainers! To maintain and continue to develop this young library, Please post in this issue.