Swagger UI and API Documentation
Your API documentation is generated automatically from your code. This guide explains how to access, use, and generate the documentation.
Zero-Config Documentation
The framework generates OpenAPI documentation without any manual configuration. All metadata comes from your package.json:
This produces documentation with:
- Title: "Auth Service" (derived from package name)
- Version: "1.0.0"
- Description: "Backend authentication service"
No separate config files to maintain. Update your package.json and the docs update automatically.
Accessing Swagger UI
During Development
Start your service:
Open Swagger UI in your browser:
The port depends on your service configuration. Each service runs on its own port (check .tsdevstack/config.json).
Swagger is served directly by each service, not through Kong gateway.
Raw OpenAPI JSON
Access the JSON specification directly:
Useful for importing into API tools like Postman or Insomnia.
Build-Time JSON Generation
Generate an OpenAPI JSON file for client generation or deployment:
This creates ./docs/openapi.json containing the complete API specification.
How It Works
The generation script creates a temporary NestJS application, extracts the OpenAPI document, writes it to disk, and shuts down. No HTTP server is started.
Generating TypeScript Clients
After generating the OpenAPI spec, create a TypeScript client:
Or run both in sequence:
Testing Authenticated Endpoints
Swagger UI is served by the service itself, so "Try it out" sends requests straight to the service port, not through Kong. That works for @Public() endpoints such as login. Protected endpoints answer 401 there, even with a valid token: services only accept identity that Kong vouched for (see Protected Routes).
To call protected endpoints, go through the gateway:
Protected endpoints still show a lock icon in Swagger UI, which is useful for reading which endpoints need a token.
Routing Depends on the OpenAPI Document
The generated docs/openapi.json is also what the gateway routes are built from. Every path and method in it gets an exact Kong route; anything missing from it is not reachable through the gateway (404). After adding or changing endpoints, regenerate the document and the gateway config with npx tsdevstack sync. See Gateway Routing.
How Endpoints Are Documented
Swagger automatically detects:
- Routes from
@Controller()and HTTP method decorators (@Get,@Post, etc.) - Groupings from
@ApiTags() - Descriptions from
@ApiOperation() - Request schemas from DTO parameters with
@ApiProperty() - Response schemas from
@ApiResponse()decorators - Security requirements from guards and security decorators
- Validation rules from
class-validatordecorators
Add a new endpoint and it appears in Swagger automatically on the next restart.
Common Tasks
Update Documentation Metadata
Edit your package.json:
Restart the service to see changes in Swagger UI.
Refresh After Code Changes
In development mode, restart your service:
For generated files:
Add Endpoint Documentation
Add decorators to your controller method:
See OpenAPI Decorators for the complete decorator reference.
Security Schemes
The framework automatically configures two security schemes:
Bearer Authentication (JWT)
- Type: HTTP Bearer
- Format: JWT
- Used for user authentication
API Key Authentication
- Type: API Key
- Header:
x-api-key - Used for partner integrations
Both schemes appear in the "Authorize" dialog when endpoints require them.