openapi-spec-generation
Write, generate and lint OpenAPI 3.1 specifications, design-first or from code (FastAPI, tsoa), and generate SDKs from them. Use when creating or fixing an API contract, migrating a 3.0 spec to 3.1, or adding Spectral or Redocly linting to CI.
- License 许可
- MIT
- 最近更新
- 2026-11-10
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- openapi-spec-generation
- description
- Write, generate and lint OpenAPI 3.1 specifications, design-first or from code (FastAPI, tsoa), and generate SDKs from them. Use when creating or fixing an API contract, migrating a 3.0 spec to 3.1, or adding Spectral or Redocly linting to CI.
- last_verified
- 1793059200000
02 资源文件 2
- 参考文档references/code-first-and-tooling.md11.4 KB
- 参考文档references/details.md11.9 KB
03 SKILL.md 正文
OpenAPI Spec Generation
Write OpenAPI 3.1 specifications that lint clean, and keep them in step with the code.
When to Use This Skill
- Writing an API contract before the code exists (design-first)
- Generating a spec from an existing FastAPI or tsoa codebase (code-first)
- Migrating a 3.0 spec to 3.1
- Adding spec linting to CI, or generating client SDKs
Procedure
-
Pick the approach. Design-first for a new API or a contract other teams consume. Code-first when the code exists and is the source of truth: FastAPI emits 3.1 from
app.openapi(), tsoa from its decorators. -
Start from the template in
references/details.md(Template 1). Setopenapi: 3.1.0, realservers, and onesecuritySchemesentry per auth method. -
Define each schema once under
components/schemasand$refit. Give every operation anoperationId, asummary, adescription, and its 4xx responses. -
Write 3.1 schemas, not 3.0 ones. 3.1 schemas are JSON Schema 2020-12. See the table below.
-
Lint. Both must pass before the spec is committed:
npx @redocly/cli@2 lint openapi.yaml npx @stoplight/spectral-cli@6 lint openapi.yaml --fail-severity=warnRulesets for both are in
references/code-first-and-tooling.md(Template 4). Redocly rejects 3.0 keywords such asnullablein a 3.1 document. -
Add the lint to CI and fail the build on errors. For code-first, export the spec in CI and diff it against the committed one so a code change can't drift silently.
3.0 to 3.1 changes
| 3.0 | 3.1 |
|---|---|
nullable: true |
type: [string, "null"], or anyOf with {type: "null"} for a $ref |
example: inside a schema |
examples: (a list) inside a schema; media-type example/examples are unchanged |
exclusiveMinimum: true + minimum: 0 |
exclusiveMinimum: 0 |
type: string, format: binary for uploads |
contentMediaType: application/octet-stream |
$ref siblings ignored |
$ref may have sibling keywords such as description |
# Nullable scalar
avatar:
type: [string, "null"]
format: uri
# Nullable reference
manager:
anyOf:
- $ref: "#/components/schemas/User"
- type: "null"
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 |
References
references/details.md: Template 1, a complete 3.1 spec that passes both linters.references/code-first-and-tooling.md: FastAPI and tsoa code-first templates, the Spectral and Redocly rulesets, and SDK generation.
Don'ts
- Don't use 3.0 keywords in a 3.1 spec:
nullable, booleanexclusiveMinimum. - Don't skip security: every operation is covered by a security requirement or is
marked public with
security: []. - Don't mix naming styles: properties and path parameters are camelCase throughout.
- Don't hardcode environments: list each one under
servers, or use server variables. - Don't publish numbers you haven't measured: rate limits and quotas come from the gateway config, not from a guess.
04 同仓库更多 Skills
no-description
暂无简介
good-skill
Fixture skill that satisfies every rule.
broken-link
Links to a reference file that does not exist.
Bad_Name
Name violates the kebab-case rule and does not match the directory.
skill-authoring
Write, review, and validate portable agent skills in SKILL.md format. Use when creating a new skill, editing an existing one, or asked whether a skill follows the Agent Skills spec.
weigh-bags
Record scale readings for each bag — empty (tare), outbound, current, final — and reconcile them against the itemised inventory to find unaccounted weight. Use when the user gives a bag weight, says how heavy something is, weighs their luggage, or asks how close to the limit they are. Appends to bags.yaml and runs scripts/reconcile.py.