Swagger Skill
Add inline Swagger/OpenAPI JSDoc to Next.js App Router API routes, with an optional combined TSDoc pass for the same file.
Inputs
| Variable |
Description |
Example |
${input:files} |
Route file path(s) to document |
app/api/users/route.ts |
${input:mode} |
swagger (default) or combined for Swagger + TSDoc |
swagger |
When to Use
Use this skill when:
- The user asks for Swagger or OpenAPI docs on a
route.ts file
- The user wants
@swagger JSDoc blocks added above Next.js route handlers
- The user wants both Swagger and TSDoc added to the same route file (
${input:mode}=combined)
- The task requires route docs that match the real HTTP contract without changing runtime behavior
Workflow
- Read
${input:files} and identify every exported handler: GET, POST, PATCH, PUT, DELETE.
- Read adjacent helpers, response builders, validators, auth checks, parsers, and existing repo Swagger patterns before documenting.
- Add or update one
@swagger block immediately above each exported handler.
- In
combined mode, also add TSDoc above exported handlers and non-trivial internal helpers.
- Preserve formatting, ordering, and runtime behavior.
Swagger Requirements
For each handler, document:
operationId, summary, description, and tags
- auth model and
security when required
- every supported query, path, and header parameter with types, defaults, enums, constraints, and examples
- JSON request body schema for methods that accept one
- success responses with accurate status codes, schemas, and at least one example
- common error responses (
400, 401, 404, 429, 500) when applicable
- pagination, sorting, filtering, search, and
Link header behavior when present
- caching, invalidation toggles, batching, concurrency, and upstream latency notes when relevant
Swagger Precision Rules
- Match actual code paths, defaults, auth behavior, query parsing, pagination, and JSON field names.
- Prefer existing component schema references when the repo already defines them; otherwise inline a schema that matches the actual payload shape.
- Mark
required fields accurately.
- Use snake_case response field names when the API uses them.
- If the route returns a standard error envelope, document it consistently across all handlers.
TSDoc Requirements (combined mode only)
Add TSDoc above:
- every exported handler, type, interface, and const in the file
- internal helpers that are non-trivial or reused
For exported symbols, document:
- purpose and why the symbol exists
- parameter semantics and constraints
- return shape and consumption expectations
- error behavior or failure paths
- noteworthy ordering, caching, batching, or concurrency behavior
- at least one
@example when it adds value
For internal helpers, document only a short purpose, key parameters, and notable non-obvious behavior.
Required tags when relevant: @param, @returns, @throws, @remarks, @example, @see, @deprecated, @defaultValue.
Constraints
- Do not modify runtime logic.
- Only add or edit comments and, when necessary, non-executing type-only imports for documentation references.
- Place Swagger JSDoc immediately above the exported handler it documents.
- Keep existing formatting and code style.
- ASCII only. Do not use Unicode punctuation or bullets.
Output Behavior
- Apply documentation inline in
${input:files}.
- Generate separate
@swagger blocks for each HTTP method in the same route file.
- In combined mode, keep Swagger focused on the HTTP contract and TSDoc focused on code semantics.
Quality Bar
- Prefer precise schemas over vague descriptions.
- Do not restate obvious implementation details.
- Inspect parsing helpers and response builders when behavior is unclear before documenting.
- Follow existing repo conventions first, then fill gaps carefully.
Common Mistakes
- Documenting the wrong status codes — read the actual response builder or
NextResponse calls; don't assume 200 is always the success code.
- Missing required fields on request body schemas — check validators (Zod, Joi, class-validator) to determine which fields are truly required.
- Stale
operationId after renaming — if a handler was renamed or moved, update operationId to avoid collisions in the generated spec.
- Inconsistent error envelopes — if the repo uses a shared error shape, use it in every
4xx/5xx response, not just some.
- Over-documenting in TSDoc what Swagger already covers — in combined mode, TSDoc on a handler should add semantic context (why it exists, ordering invariants), not repeat the HTTP contract already in
@swagger.
1---2name: swagger3description: Use when the user wants Swagger/OpenAPI JSDoc added or updated on Next.js App Router route handlers, or wants combined Swagger and TSDoc on the same route file.4---56# Swagger Skill78Add inline Swagger/OpenAPI JSDoc to Next.js App Router API routes, with an optional combined TSDoc pass for the same file.910## Inputs1112| Variable | Description | Example |13|----------|-------------|---------|14| `${input:files}` | Route file path(s) to document | `app/api/users/route.ts` |15| `${input:mode}` | `swagger` (default) or `combined` for Swagger + TSDoc | `swagger` |1617## When to Use1819Use this skill when:20- The user asks for Swagger or OpenAPI docs on a `route.ts` file21- The user wants `@swagger` JSDoc blocks added above Next.js route handlers22- The user wants both Swagger and TSDoc added to the same route file (`${input:mode}=combined`)23- The task requires route docs that match the real HTTP contract without changing runtime behavior2425## Workflow26271. Read `${input:files}` and identify every exported handler: `GET`, `POST`, `PATCH`, `PUT`, `DELETE`.282. Read adjacent helpers, response builders, validators, auth checks, parsers, and existing repo Swagger patterns before documenting.293. Add or update one `@swagger` block immediately above each exported handler.304. In `combined` mode, also add TSDoc above exported handlers and non-trivial internal helpers.315. Preserve formatting, ordering, and runtime behavior.3233## Swagger Requirements3435For each handler, document:36- `operationId`, `summary`, `description`, and `tags`37- auth model and `security` when required38- every supported query, path, and header parameter with types, defaults, enums, constraints, and examples39- JSON request body schema for methods that accept one40- success responses with accurate status codes, schemas, and at least one example41- common error responses (`400`, `401`, `404`, `429`, `500`) when applicable42- pagination, sorting, filtering, search, and `Link` header behavior when present43- caching, invalidation toggles, batching, concurrency, and upstream latency notes when relevant4445## Swagger Precision Rules4647- Match actual code paths, defaults, auth behavior, query parsing, pagination, and JSON field names.48- Prefer existing component schema references when the repo already defines them; otherwise inline a schema that matches the actual payload shape.49- Mark `required` fields accurately.50- Use snake_case response field names when the API uses them.51- If the route returns a standard error envelope, document it consistently across all handlers.5253## TSDoc Requirements (combined mode only)5455Add TSDoc above:56- every exported handler, type, interface, and const in the file57- internal helpers that are non-trivial or reused5859For exported symbols, document:60- purpose and why the symbol exists61- parameter semantics and constraints62- return shape and consumption expectations63- error behavior or failure paths64- noteworthy ordering, caching, batching, or concurrency behavior65- at least one `@example` when it adds value6667For internal helpers, document only a short purpose, key parameters, and notable non-obvious behavior.6869Required tags when relevant: `@param`, `@returns`, `@throws`, `@remarks`, `@example`, `@see`, `@deprecated`, `@defaultValue`.7071## Constraints7273- Do not modify runtime logic.74- Only add or edit comments and, when necessary, non-executing type-only imports for documentation references.75- Place Swagger JSDoc immediately above the exported handler it documents.76- Keep existing formatting and code style.77- ASCII only. Do not use Unicode punctuation or bullets.7879## Output Behavior8081- Apply documentation inline in `${input:files}`.82- Generate separate `@swagger` blocks for each HTTP method in the same route file.83- In combined mode, keep Swagger focused on the HTTP contract and TSDoc focused on code semantics.8485## Quality Bar8687- Prefer precise schemas over vague descriptions.88- Do not restate obvious implementation details.89- Inspect parsing helpers and response builders when behavior is unclear before documenting.90- Follow existing repo conventions first, then fill gaps carefully.9192## Common Mistakes9394- **Documenting the wrong status codes** — read the actual response builder or `NextResponse` calls; don't assume `200` is always the success code.95- **Missing required fields on request body schemas** — check validators (Zod, Joi, class-validator) to determine which fields are truly required.96- **Stale `operationId` after renaming** — if a handler was renamed or moved, update `operationId` to avoid collisions in the generated spec.97- **Inconsistent error envelopes** — if the repo uses a shared error shape, use it in every `4xx`/`5xx` response, not just some.98- **Over-documenting in TSDoc what Swagger already covers** — in combined mode, TSDoc on a handler should add semantic context (why it exists, ordering invariants), not repeat the HTTP contract already in `@swagger`.