Swagger API Documentation
The Swagger API Documentation component provides an automated way to generate and serve interactive API documentation.
Installation
Install the component using the servercn CLI:
npx servercn-cli add swagger-docsImplementation Guide
Configuration
The configuration file defines the metadata for your API and where Swagger should look for documentation comments.
Run the Script
Run the script to generate the swagger.json file.
It will generate a swagger.json file in the docs directory.
Setup Swagger
Create a swagger.ts file in the src/configs directory.
Integration with App
Update your main app.ts to initialize the Swagger documentation.
Update swagger.json file (Optional)
Update the swagger.json file with the new API documentation.
Accessing the Docs
Once your server is running, navigate to:
http://localhost:8000/api/docs
You will see the Swagger UI dashboard where you can explore and test your API.
Don't forget to run `node src/swagger.config.ts` command and update the base url, routes... in `swagger.json` file.