Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Generate OpenAPI 3.x specifications from existing code, routes, or descriptions with proper schemas and documentation.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/details.md
1# openapi-spec-generation — templates and worked examples23## Templates45### Template 1: Complete API Specification67```yaml8openapi: 3.1.09info:10title: User Management API11description: |12API for managing users and their profiles.1314## Authentication15All endpoints require Bearer token authentication.1617## Rate Limiting18- 1000 requests per minute for standard tier19- 10000 requests per minute for enterprise tier20version: 2.0.021contact:22name: API Support23email: [email protected]24url: https://docs.example.com25license:26name: MIT27url: https://opensource.org/licenses/MIT2829servers:30- url: https://api.example.com/v231description: Production32- url: https://staging-api.example.com/v233description: Staging34- url: http://localhost:3000/v235description: Local development3637tags:38- name: Users39description: User management operations40- name: Profiles41description: User profile operations42- name: Admin43description: Administrative operations4445paths:46/users:47get:48operationId: listUsers49summary: List all users50description: Returns a paginated list of users with optional filtering.51tags:52- Users53parameters:54- $ref: "#/components/parameters/PageParam"55- $ref: "#/components/parameters/LimitParam"56- name: status57in: query58description: Filter by user status59schema:60$ref: "#/components/schemas/UserStatus"61- name: search62in: query63description: Search by name or email64schema:65type: string66minLength: 267maxLength: 10068responses:69"200":70description: Successful response71content:72application/json:73schema:74$ref: "#/components/schemas/UserListResponse"75examples:76default:77$ref: "#/components/examples/UserListExample"78"400":79$ref: "#/components/responses/BadRequest"80"401":81$ref: "#/components/responses/Unauthorized"82"429":83$ref: "#/components/responses/RateLimited"84security:85- bearerAuth: []8687post:88operationId: createUser89summary: Create a new user90description: Creates a new user account and sends welcome email.91tags:92- Users93requestBody:94required: true95content:96application/json:97schema:98$ref: "#/components/schemas/CreateUserRequest"99examples:100standard:101summary: Standard user102value:103email: [email protected]104name: John Doe105role: user106admin:107summary: Admin user108value:109email: [email protected]110name: Admin User111role: admin112responses:113"201":114description: User created successfully115content:116application/json:117schema:118$ref: "#/components/schemas/User"119headers:120Location:121description: URL of created user122schema:123type: string124format: uri125"400":126$ref: "#/components/responses/BadRequest"127"409":128description: Email already exists129content:130application/json:131schema:132$ref: "#/components/schemas/Error"133security:134- bearerAuth: []135136/users/{userId}:137parameters:138- $ref: "#/components/parameters/UserIdParam"139140get:141operationId: getUser142summary: Get user by ID143tags:144- Users145responses:146"200":147description: Successful response148content:149application/json:150schema:151$ref: "#/components/schemas/User"152"404":153$ref: "#/components/responses/NotFound"154security:155- bearerAuth: []156157patch:158operationId: updateUser159summary: Update user160tags:161- Users162requestBody:163required: true164content:165application/json:166schema:167$ref: "#/components/schemas/UpdateUserRequest"168responses:169"200":170description: User updated171content:172application/json:173schema:174$ref: "#/components/schemas/User"175"400":176$ref: "#/components/responses/BadRequest"177"404":178$ref: "#/components/responses/NotFound"179security:180- bearerAuth: []181182delete:183operationId: deleteUser184summary: Delete user185tags:186- Users187- Admin188responses:189"204":190description: User deleted191"404":192$ref: "#/components/responses/NotFound"193security:194- bearerAuth: []195- apiKey: []196197components:198schemas:199User:200type: object201required:202- id203204- name205- status206- createdAt207properties:208id:209type: string210format: uuid211readOnly: true212description: Unique user identifier213email:214type: string215format: email216description: User email address217name:218type: string219minLength: 1220maxLength: 100221description: User display name222status:223$ref: "#/components/schemas/UserStatus"224role:225type: string226enum: [user, moderator, admin]227default: user228avatar:229type: string230format: uri231nullable: true232metadata:233type: object234additionalProperties: true235description: Custom metadata236createdAt:237type: string238format: date-time239readOnly: true240updatedAt:241type: string242format: date-time243readOnly: true244245UserStatus:246type: string247enum: [active, inactive, suspended, pending]248description: User account status249250CreateUserRequest:251type: object252required:253254- name255properties:256email:257type: string258format: email259name:260type: string261minLength: 1262maxLength: 100263role:264type: string265enum: [user, moderator, admin]266default: user267metadata:268type: object269additionalProperties: true270271UpdateUserRequest:272type: object273minProperties: 1274properties:275name:276type: string277minLength: 1278maxLength: 100279status:280$ref: "#/components/schemas/UserStatus"281role:282type: string283enum: [user, moderator, admin]284metadata:285type: object286additionalProperties: true287288UserListResponse:289type: object290required:291- data292- pagination293properties:294data:295type: array296items:297$ref: "#/components/schemas/User"298pagination:299$ref: "#/components/schemas/Pagination"300301Pagination:302type: object303required:304- page305- limit306- total307- totalPages308properties:309page:310type: integer311minimum: 1312limit:313type: integer314minimum: 1315maximum: 100316total:317type: integer318minimum: 0319totalPages:320type: integer321minimum: 0322hasNext:323type: boolean324hasPrev:325type: boolean326327Error:328type: object329required:330- code331- message332properties:333code:334type: string335description: Error code for programmatic handling336message:337type: string338description: Human-readable error message339details:340type: array341items:342type: object343properties:344field:345type: string346message:347type: string348requestId:349type: string350description: Request ID for support351352parameters:353UserIdParam:354name: userId355in: path356required: true357description: User ID358schema:359type: string360format: uuid361362PageParam:363name: page364in: query365description: Page number (1-based)366schema:367type: integer368minimum: 1369default: 1370371LimitParam:372name: limit373in: query374description: Items per page375schema:376type: integer377minimum: 1378maximum: 100379default: 20380381responses:382BadRequest:383description: Invalid request384content:385application/json:386schema:387$ref: "#/components/schemas/Error"388example:389code: VALIDATION_ERROR390message: Invalid request parameters391details:392- field: email393message: Must be a valid email address394395Unauthorized:396description: Authentication required397content:398application/json:399schema:400$ref: "#/components/schemas/Error"401example:402code: UNAUTHORIZED403message: Authentication required404405NotFound:406description: Resource not found407content:408application/json:409schema:410$ref: "#/components/schemas/Error"411example:412code: NOT_FOUND413message: User not found414415RateLimited:416description: Too many requests417content:418application/json:419schema:420$ref: "#/components/schemas/Error"421headers:422Retry-After:423description: Seconds until rate limit resets424schema:425type: integer426X-RateLimit-Limit:427description: Request limit per window428schema:429type: integer430X-RateLimit-Remaining:431description: Remaining requests in window432schema:433type: integer434435examples:436UserListExample:437value:438data:439- id: "550e8400-e29b-41d4-a716-446655440000"440email: "[email protected]"441name: "John Doe"442status: "active"443role: "user"444createdAt: "2024-01-15T10:30:00Z"445pagination:446page: 1447limit: 20448total: 1449totalPages: 1450hasNext: false451hasPrev: false452453securitySchemes:454bearerAuth:455type: http456scheme: bearer457bearerFormat: JWT458description: JWT token from /auth/login459460apiKey:461type: apiKey462in: header463name: X-API-Key464description: API key for service-to-service calls465466security:467- bearerAuth: []468```469470For advanced code-first generation patterns and tooling, see [references/code-first-and-tooling.md](references/code-first-and-tooling.md):471472- **Template 2: Python/FastAPI** — Pydantic models with `Field` validation, enum types, full CRUD endpoints with `response_model` and `status_code`, exporting the spec as JSON473- **Template 3: TypeScript/tsoa** — Decorator-based controllers (`@Route`, `@Get`, `@Security`, `@Example`, `@Response`) that generate OpenAPI from TypeScript types474- **Template 4: Validation & Linting** — Spectral ruleset (`.spectral.yaml`) with custom rules for operationId, security, naming conventions; Redocly config with MIME type enforcement and code sample generation475- **SDK Generation** — `openapi-generator-cli` for TypeScript (fetch), Python, and Go clients476