Agent skill
nestjs-swagger-setup
Install, repair, and verify OpenAPI documentation in NestJS using `@nestjs/swagger` with `@nestjs/config`-driven `SWAGGER_*` controls, optional bearer auth, explicit JSON endpoint configuration (`jsonDocumentUrl`), and deterministic UI/raw exposure gates. Use when users ask to add Swagger UI, expose or move OpenAPI JSON routes, fix broken Swagger wiring, standardize environment-based docs toggles, or validate production-safe docs behavior.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/other/nestjs-swagger-setup
SKILL.md
NestJS Swagger Setup
Use this workflow to install or repair Swagger UI and OpenAPI JSON endpoints in a NestJS application.
Inputs
Collect before changes:
- Project root path
- Package manager (
npm,pnpm, oryarn) - Existing global prefix usage (
app.setGlobalPrefix(...)) - Desired docs exposure in production (
enabledordisabled)
If a required input is missing, ask one precise question and pause implementation.
Preconditions
- Confirm the target is a NestJS project with
main.tsand a root module. - Confirm Node and dependency compatibility for the workspace.
- Confirm write access to source files and environment files.
If preconditions fail, stop and report the exact blocker.
Deterministic Workflow
- Install required dependencies from project root:
@nestjs/swagger@nestjs/config
- Verify major-version alignment:
- Nest 11 ->
@nestjs/swagger^11 - Nest 10 ->
@nestjs/swagger^10
- Nest 11 ->
- Ensure
ConfigModule.forRoot({ isGlobal: true })is configured in the root module (or preserve an equivalent existing global config strategy). - Create or repair bootstrap helper using reference.md:
src/libs/swagger/setup-swagger.ts
- Wire
setupSwagger(app)inmain.tsafter app creation and beforelisten(...). - Create or update
.envkeys for Swagger behavior:SWAGGER_ENABLEDSWAGGER_PATHSWAGGER_UI_ENABLEDSWAGGER_RAW_ENABLEDSWAGGER_JSON_URLSWAGGER_USE_GLOBAL_PREFIX- optional
SWAGGER_BEARER_AUTH
- Ensure
.envis ignored by git when repository policy requires local secrets. - Preserve unrelated project code and avoid refactoring outside Swagger/config scope.
Route Rules
- Default docs path:
SWAGGER_PATH=api/docs - Default JSON route segment:
SWAGGER_JSON_URL=openapi.json - If
SWAGGER_USE_GLOBAL_PREFIX=true, JSON endpoint is prefixed by the app global prefix. - If
SWAGGER_UI_ENABLED=false, only raw definition endpoints are served whenSWAGGER_RAW_ENABLED=true. - If both UI and raw are disabled, no Swagger surface should be exposed.
Security Defaults
- Default production stance:
SWAGGER_ENABLED=falseunless explicitly required. - If enabled in production, require upstream protection (gateway auth, app guard, or network allowlist).
- Do not use sensitive secrets as feature flags for Swagger enablement.
Verification Gates
- Start the app (
startorstart:dev). - Validate docs UI route when enabled:
http://localhost:<PORT>/<SWAGGER_PATH>
- Validate OpenAPI JSON route when raw is enabled:
- without prefix:
http://localhost:<PORT>/<SWAGGER_JSON_URL> - with prefix:
http://localhost:<PORT>/<global-prefix>/<SWAGGER_JSON_URL>
- without prefix:
- Validate bearer auth button only when
SWAGGER_BEARER_AUTH=true. - Validate the Swagger top bar includes the
Download OpenAPIbutton pointing to configured JSON route. - Report exact pass/fail status for each gate.
Failure Handling
- If dependency installation fails, report command and error context and stop before partial wiring.
- If required files are missing (
main.ts, root module), stop and request the correct project path. - If an existing Swagger setup is present, perform minimal edits instead of replacing unrelated options.
Deliverables
- Updated dependency manifest
- Updated root module config import/wiring
- Updated
main.tsbootstrap call - Added or updated
src/libs/swagger/setup-swagger.ts - Added or updated
.envSwagger variables - Verification summary with concrete tested routes
Checklist
- Dependencies installed and version-aligned
-
ConfigModuleglobally available -
setupSwaggerhelper added or repaired -
setupSwagger(app)called beforelisten(...) -
.envcontains requiredSWAGGER_*keys - Swagger exposure matches UI/raw/global-prefix toggles
-
Download OpenAPIbutton visible and functional when UI enabled - Verification results documented with exact routes
Additional Resources
- Full implementation: reference.md
- Minimal snippets: examples.md
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?