-
-
Notifications
You must be signed in to change notification settings - Fork 0
Getting Started
Amish Faldu edited this page Oct 5, 2022
·
4 revisions
To install this package in your project use below command
npm i @amishfaldu/swagger-docs --save-exact
The optional --save-exact will pin this dependency to a specific latest version.
This library uses typescript decorator and reflect metadata feature. This is not enabled by default, to enable it add the following 2 lines to your tsconfig.json file
{
...,
"compilerOptions": {
...
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
...
},
...
}
That's it! Your typescript configuration is completed
This will show simplest use of swagger-docs, for more complex examples go here
Follow the steps to write your first hello world in swagger-docs
- Define route that your app will be serving. To do that we will define a
controllerclass, which basically functions as router to store all your related routes.@Controller({ route: "" }) class HelloWorld { @Get() hello(): string { return "Hello World!" } } - Create web app using express
const app = express(); - Create swagger configuration
const swaggerConfig = new SwaggerConfig() .setTitle("Hello world swagger") .setVersion("1.0.0") .setDescription("Hello world swagger description") .finalizeConfig(); - Bootstrap controllers and prepare your app to serve swagger UI
const swaggerDocs = new SwaggerDocs(swaggerConfig); swaggerDocs.bootstrapControllersToApp([HelloWorld]); swaggerDocs.setup(app, "api-explorer"); - Start express server
app.listen(3000, () => { console.log("Listening"); });
Now go to http://localhost:3000/api-explorer. You can see beautiful swagger API docs for your hello world API.

Next you can start looking for more complex examples and start integrating library with your project.
-
- SwaggerConfig
- SwaggerDocs
-
- Controller
- RouteMiddleware
-
-
- PathParam
- QueryParam
- Header
- Body
- Request
- Response
- Next
- File
-
- Get
- Put
- Post
- Delete
- Options
- Head
- Patch
- Trace
-
- RouteResponseBody
- RouteRequestBody
- RouteTag
- RouteSummary
- RouteDescription
- RouteExternalDocs
- RouteDeprecated
- RouteSecurity
- RouteServers
-
-
- IsArray
- IsBoolean
- IsNumber
- IsObject
- IsString
- IsEnum