$npx -y skills add girijashankarj/cursor-handbook --skill openapi-generatorGenerate OpenAPI 3.x specifications from code, requirements, or existing APIs. Use when the user asks to create an API spec, Swagger doc, or OpenAPI definition.
| 1 | # Skill: OpenAPI Generator |
| 2 | |
| 3 | Generate complete OpenAPI 3.0/3.1 specifications from code, requirements, or existing endpoints. |
| 4 | |
| 5 | ## Trigger |
| 6 | When the user asks to generate an OpenAPI spec, create Swagger documentation, document API endpoints, or produce an API contract. |
| 7 | |
| 8 | ## Prerequisites |
| 9 | - [ ] API endpoints identified (routes, methods, paths) |
| 10 | - [ ] Request/response schemas known or inferable from code |
| 11 | - [ ] Authentication method known |
| 12 | |
| 13 | ## Steps |
| 14 | |
| 15 | ### Step 1: Gather API Information |
| 16 | - [ ] Scan route files to identify all endpoints |
| 17 | - [ ] Identify HTTP methods for each endpoint (GET, POST, PUT, PATCH, DELETE) |
| 18 | - [ ] Identify path parameters, query parameters, request bodies |
| 19 | - [ ] Identify response shapes and status codes |
| 20 | - [ ] Identify authentication/authorization requirements |
| 21 | - [ ] Check for existing schema definitions (Zod, JSON Schema, TypeScript interfaces) |
| 22 | |
| 23 | ### Step 2: Define API Metadata |
| 24 | ```yaml |
| 25 | openapi: "3.0.3" |
| 26 | info: |
| 27 | title: "{{CONFIG.project.name}} API" |
| 28 | description: "API documentation for {{CONFIG.project.name}}" |
| 29 | version: "1.0.0" |
| 30 | contact: |
| 31 | name: "API Support" |
| 32 | email: "[API_SUPPORT_EMAIL]" |
| 33 | servers: |
| 34 | - url: "[API_BASE_URL]/api/v1" |
| 35 | description: "Production" |
| 36 | - url: "[API_BASE_URL_STAGING]/api/v1" |
| 37 | description: "Staging" |
| 38 | ``` |
| 39 | |
| 40 | ### Step 3: Define Security Schemes |
| 41 | ```yaml |
| 42 | components: |
| 43 | securitySchemes: |
| 44 | BearerAuth: |
| 45 | type: http |
| 46 | scheme: bearer |
| 47 | bearerFormat: JWT |
| 48 | ApiKeyAuth: |
| 49 | type: apiKey |
| 50 | in: header |
| 51 | name: X-API-Key |
| 52 | ``` |
| 53 | |
| 54 | ### Step 4: Define Reusable Schemas |
| 55 | |
| 56 | #### Response Envelope |
| 57 | ```yaml |
| 58 | components: |
| 59 | schemas: |
| 60 | SuccessResponse: |
| 61 | type: object |
| 62 | properties: |
| 63 | data: |
| 64 | type: object |
| 65 | meta: |
| 66 | $ref: "#/components/schemas/Meta" |
| 67 | ErrorResponse: |
| 68 | type: object |
| 69 | properties: |
| 70 | error: |
| 71 | $ref: "#/components/schemas/Error" |
| 72 | meta: |
| 73 | $ref: "#/components/schemas/Meta" |
| 74 | Meta: |
| 75 | type: object |
| 76 | properties: |
| 77 | correlationId: |
| 78 | type: string |
| 79 | format: uuid |
| 80 | timestamp: |
| 81 | type: string |
| 82 | format: date-time |
| 83 | Error: |
| 84 | type: object |
| 85 | properties: |
| 86 | code: |
| 87 | type: string |
| 88 | message: |
| 89 | type: string |
| 90 | details: |
| 91 | type: array |
| 92 | items: |
| 93 | type: object |
| 94 | PaginationMeta: |
| 95 | type: object |
| 96 | properties: |
| 97 | cursor: |
| 98 | type: string |
| 99 | nullable: true |
| 100 | pageSize: |
| 101 | type: integer |
| 102 | hasMore: |
| 103 | type: boolean |
| 104 | ``` |
| 105 | |
| 106 | #### Entity Schemas |
| 107 | - [ ] Convert TypeScript interfaces / Zod schemas to OpenAPI schema objects |
| 108 | - [ ] Define `required` fields |
| 109 | - [ ] Add `format` hints (uuid, email, date-time, uri) |
| 110 | - [ ] Add `example` values for each field |
| 111 | - [ ] Add `description` for non-obvious fields |
| 112 | - [ ] Define enums for constrained values |
| 113 | |
| 114 | ### Step 5: Define Endpoints |
| 115 | |
| 116 | For each endpoint: |
| 117 | ```yaml |
| 118 | paths: |
| 119 | /resource: |
| 120 | get: |
| 121 | summary: "List resources" |
| 122 | description: "Returns a paginated list of resources" |
| 123 | operationId: "listResources" |
| 124 | tags: |
| 125 | - "Resources" |
| 126 | security: |
| 127 | - BearerAuth: [] |
| 128 | parameters: |
| 129 | - name: cursor |
| 130 | in: query |
| 131 | schema: |
| 132 | type: string |
| 133 | description: "Pagination cursor" |
| 134 | - name: pageSize |
| 135 | in: query |
| 136 | schema: |
| 137 | type: integer |
| 138 | default: 20 |
| 139 | minimum: 1 |
| 140 | maximum: 100 |
| 141 | responses: |
| 142 | "200": |
| 143 | description: "Successful response" |
| 144 | content: |
| 145 | application/json: |
| 146 | schema: |
| 147 | allOf: |
| 148 | - $ref: "#/components/schemas/SuccessResponse" |
| 149 | - type: object |
| 150 | properties: |
| 151 | data: |
| 152 | type: array |
| 153 | items: |
| 154 | $ref: "#/components/schemas/Resource" |
| 155 | meta: |
| 156 | allOf: |
| 157 | - $ref: "#/components/schemas/Meta" |
| 158 | - $ref: "#/components/schemas/PaginationMeta" |
| 159 | "401": |
| 160 | description: "Unauthorized" |
| 161 | content: |
| 162 | application/json: |
| 163 | schema: |
| 164 | $ref: "#/components/schemas/ErrorResponse" |
| 165 | post: |
| 166 | summary: "Create resource" |
| 167 | operationId: "createResource" |
| 168 | tags: |
| 169 | - "Resources" |
| 170 | security: |
| 171 | - BearerAuth: [] |
| 172 | requestBody: |
| 173 | required: true |
| 174 | content: |
| 175 | application/json: |
| 176 | schema: |
| 177 | $ref: "#/components/schemas/CreateResourceRequest" |
| 178 | responses: |
| 179 | "201": |
| 180 | description: "Created" |
| 181 | content: |
| 182 | application/json: |
| 183 | schema: |
| 184 | allOf: |
| 185 | - $ref: "#/components/schemas/Su |