Openapi Spec Generation

作者 wshobson46891e7e60da无许可证收录于 2026年10月8日更新于 2026年10月8日

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.

AI 生成的概览

指导创建、维护和验证 REST API 的 OpenAPI 3.1 规范。

功能
该技能提供编写、维护和验证 RESTful API 的 OpenAPI 3.1 规范的模式与指导。内容涵盖规范结构、设计优先、代码优先和混合方法,以及复用、示例、错误文档和版本控制等最佳实践。它还指向一个包含模板和完整示例的参考文件。
适用场景
适用于创建 API 文档、从现有代码生成规范、在实现前设计 API 契约、根据规范验证实现或生成客户端 SDK。也适合搭建 API 文档门户。
运行要求
无脚本,仅为说明性内容。依赖技能文件夹中的参考文件获取模板和示例。

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

yaml
openapi: 3.1.0info:  title: API Title  version: 1.0.0servers:  - url: https://api.example.com/v1paths:  /resources:    get: ...components:  schemas: ...  securitySchemes: ...

2. Design Approaches

ApproachDescriptionBest For
Design-FirstWrite spec before codeNew APIs, contracts
Code-FirstGenerate spec from codeExisting APIs
HybridAnnotate code, generate specEvolving 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

来源与署名

来源:wshobson/agents位于plugins/documentation-generation/skills/openapi-spec-generation提交46891e7

许可证: 无许可证

内容归原作者所有。SourceWeft 从公开仓库中收录这些内容。

举报或申请下架