1---2name: openapi-spec-writer3description: Generate comprehensive OpenAPI 3.1 specifications from API design requirements and existing endpoints4---56## When to activate78- Creating OpenAPI specs for new APIs9- Documenting existing APIs from code10- Updating specs when adding new endpoints11- Generating specs from database models or route definitions12- Creating API contracts for frontend/backend alignment1314## When NOT to use1516- For GraphQL schema design (use GraphQL SDL)17- For gRPC protobuf definitions18- For WebSocket API documentation1920## Instructions21221. **Gather API requirements.** Resources, relationships, actions, and data models.232. **Define info block.** Title, version, description, contact, license, and servers (dev/staging/prod).243. **Model schemas.** Create reusable components for request/response bodies with proper types, enums, and validation rules.254. **Define paths.** Each endpoint: summary, description, parameters, request body, responses (200, 400, 401, 404, 500).265. **Add security definitions.** Auth schemes and required scopes per endpoint.276. **Include examples.** Request and response examples for every endpoint — critical for developer experience.287. **Validate spec.** Run through OpenAPI validators (spectral, swagger-cli) and fix all warnings.2930## Example3132```yaml33openapi: 3.1.034info:35 title: Users API36 version: 1.2.037 description: User management and authentication service38servers:39 - url: https://api.example.com/v140 description: Production41paths:42 /users:43 get:44 summary: List users45 parameters:46 - name: page47 in: query48 schema: { type: integer, default: 1 }49 - name: limit50 in: query51 schema: { type: integer, default: 20, maximum: 100 }52 responses:53 '200':54 description: Paginated user list55 content:56 application/json:57 schema:58 $ref: '#/components/schemas/UserListResponse'59```