openapi-spec-generation
wshobson/agents
Generate and maintain OpenAPI 3.1 specifications from code, design-first specs, and validation patterns.
What is openapi-spec-generation?
This skill provides comprehensive patterns for creating, maintaining, and validating OpenAPI 3.1 specifications for RESTful APIs. Use it when documenting APIs, generating SDKs, designing API contracts, or ensuring implementations comply with specifications.
- Generate OpenAPI specs from existing code or design-first specifications
- Create and maintain OpenAPI 3.1 structure with proper schema organization
- Validate API implementations against OpenAPI contracts
- Support design-first, code-first, and hybrid specification approaches
- Document error codes, security schemes, and server configurations
- Enable SDK generation and API documentation portal setup
How to install openapi-spec-generation
npx skills add https://github.com/wshobson/agents --skill openapi-spec-generationHow to use openapi-spec-generation
- 1.Define your API structure using OpenAPI 3.1 format with proper info, servers, and paths sections
- 2.Choose your approach: design-first (spec before code), code-first (generate from code), or hybrid (annotate and generate)
- 3.Create reusable schemas in the components section and reference them with $ref throughout your spec
- 4.Document all endpoints with descriptions, parameters, request bodies, and response schemas
- 5.Define security schemes and error responses for all operations
- 6.Validate your spec against OpenAPI 3.1 standards and test with actual API calls
- 7.Use the spec to generate SDKs, client libraries, or documentation portals
Use cases
- Creating API documentation from scratch for new REST APIs
- Generating OpenAPI specs from existing codebases
- Designing API contracts before implementation begins
- Validating that API implementations match their specifications
- Generating client SDKs from OpenAPI specifications
- API developers and architects
- Backend engineers building REST APIs
- API product managers designing contracts
- DevOps engineers managing API documentation
- SDK maintainers generating client libraries
openapi-spec-generation FAQ
Design-first (spec before code) works best for new APIs and establishing contracts. For existing APIs, use code-first generation. Hybrid approaches work well for evolving APIs where you annotate code and generate specs.
Use $ref to reference schemas defined in the components/schemas section. This keeps your spec DRY and makes updates easier.
Document all possible error codes your API can return, including HTTP status codes, error messages, and any error-specific fields. Be explicit about which endpoints return which errors.
Include the version in your URL path (e.g., /v1/) or as a header parameter. Use semantic versioning for spec changes and update the version field in the info section.
Yes. Once you have a valid OpenAPI 3.1 spec, you can use tools and generators to automatically create client libraries in various languages.
Full instructions (SKILL.md)
Source of truth, from wshobson/agents.
name: openapi-spec-generation description: Generate and maintain OpenAPI 3.1 specifications from code, design-first specs, and validation patterns. Use when creating API documentation, generating SDKs, or ensuring API contract compliance.
OpenAPI Spec Generation
Comprehensive patterns for creating, maintaining, and validating OpenAPI 3.1 specifications for RESTful APIs.
When to Use This Skill
- Creating API documentation from scratch
- Generating OpenAPI specs from existing code
- Designing API contracts (design-first approach)
- Validating API implementations against specs
- Generating client SDKs from specs
- Setting up API documentation portals
Core Concepts
1. OpenAPI 3.1 Structure
openapi: 3.1.0
info:
title: API Title
version: 1.0.0
servers:
- url: https://api.example.com/v1
paths:
/resources:
get: ...
components:
schemas: ...
securitySchemes: ...
2. Design Approaches
| Approach | Description | Best For |
|---|---|---|
| Design-First | Write spec before code | New APIs, contracts |
| Code-First | Generate spec from code | Existing APIs |
| Hybrid | Annotate code, generate spec | Evolving APIs |
Templates and detailed worked examples
Full template library and detailed worked examples live in references/details.md. Read that file when you need the concrete templates.
Best Practices
Do's
- Use $ref - Reuse schemas, parameters, responses
- Add examples - Real-world values help consumers
- Document errors - All possible error codes
- Version your API - In URL or header
- Use semantic versioning - For spec changes
Don'ts
- Don't use generic descriptions - Be specific
- Don't skip security - Define all schemes
- Don't forget nullable - Be explicit about null
- Don't mix styles - Consistent naming throughout
- Don't hardcode URLs - Use server variables
Related skills
More from wshobson/agents and the wider catalog.
tailwind-design-system
Build production-ready design systems with Tailwind CSS v4, design tokens, and component libraries.
typescript-advanced-types
Master TypeScript's advanced type system: generics, conditional types, mapped types, and utility types for type-safe applications.
nodejs-backend-patterns
Build production-ready Node.js backends with Express/Fastify, middleware patterns, auth, and database integration.
python-performance-optimization
Profile and optimize Python code using cProfile, memory profilers, and performance best practices.
brand-landingpage
Brand-first landing page designer with guided interviews and Stitch-powered iteration.
python-testing-patterns
Implement comprehensive testing strategies with pytest, fixtures, mocking, and test-driven development.