Generating an OpenAPI document and browsing it in a docs UI, straight from route schemas.
OpenAPIModule.forRoot()with APIinfo- Route schemas doubling as API documentation — no separate spec to maintain
summaryanddescriptionon each routedescribe()for field-level docs andnamed()for reusable components- Versioned paths appearing in the generated document
npm install
npm run devThe JSON document:
curl http://localhost:8787/api/openapi.jsonopenapi 3.0.0
info {"title": "Users API", "version": "1.0.0", ...}
paths ['/api/v1/users', '/api/v1/users/{id}']
User is emitted once and referenced everywhere it appears:
{"type":"object","properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/User"}}},"required":["data"],"additionalProperties":false}The docs UI:
open http://localhost:8787/api/docsThe endpoints themselves work as normal:
curl -X POST http://localhost:8787/api/v1/users \
-H 'Content-Type: application/json' \
-d '{"name":"Ada","email":"[email protected]"}'role is omitted above and defaults to member.
src/app.module.ts—OpenAPIModule.forRoot()src/users/users.schemas.ts— schemas withdescribe()andnamed()src/users/users.controller.ts—summary/descriptionper route
If this example helped, please star the Stratal repo — it is the simplest way to support the project and helps other developers find it.