Backend · Skill
Write an OpenAPI spec
write-openapi-spec
Writes an OpenAPI 3.1 document for an API that already has routes - paths, reusable schemas, examples, and a security scheme - and checks the file parses. Use when the user wants an OpenAPI file, a Swagger document, or to document existing endpoints as a contract.
Works with: Any AI Not yet model-tested; testing Jan 2027
Paste it into ChatGPT, Claude, Gemini or any AI chat, then tell it about your project. How it works
Install in Claude Code, Cursor or Codex (optional)
Only for AI coding tools that read skill folders. Run one line in a terminal, in your project folder. It downloads this skill's text files from TheSkillVault and nothing else; you can read them first with “View raw SKILL.md”.
Claude Code (all your projects)
curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/write-openapi-spec/raw' -o ~/'.claude/skills/write-openapi-spec/SKILL.md' && curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/write-openapi-spec/files/LICENSE.txt' -o ~/'.claude/skills/write-openapi-spec/LICENSE.txt'Cursor (this project)
curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/write-openapi-spec/raw' -o '.cursor/skills/write-openapi-spec/SKILL.md' && curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/write-openapi-spec/files/LICENSE.txt' -o '.cursor/skills/write-openapi-spec/LICENSE.txt'Codex and other Agent Skills tools (this project)
curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/write-openapi-spec/raw' -o '.agents/skills/write-openapi-spec/SKILL.md' && curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/write-openapi-spec/files/LICENSE.txt' -o '.agents/skills/write-openapi-spec/LICENSE.txt'
Or connect the whole library over MCP
Add TheSkillVault to Cursor or add this to your app's MCP settings (read-only; help):
{
"mcpServers": {
"theskillvault": {
"url": "https://theskillvault.ai/mcp"
}
}
}OpenAPI is the contract file other people and tools read. Write it from the routes you already have. Share shapes with $ref so a field is described once.
When to use
- Handlers exist and there is no
openapi.yaml. - A Swagger page or a generated client is out of date.
- The same error shape is copied under every path.
When not to use
- The routes, status codes, and error shape are not chosen yet. Settle that contract first.
- The task is only to speed up a SQL query.
Steps
- Set
openapi: 3.1.0, plusinfo.titleandinfo.version. Put the public base URL underservers. Do not hard-code a laptop address. - Add one path item per route you ship. Name the method, the summary, and the success response. Match the path the server actually mounts, including a version prefix if you use one.
- Move repeated bodies into
components.schemas. Point at them with$ref. Use the same name for a field in every schema. - Mark fields that must be sent with the schema's field list, and give each of those fields an example that is obviously fake.
- Document the error body once, then
$refit from the error responses you actually emit. - Add
components.securitySchemesfor the auth you use (a bearer token, a cookie, or an API key header). Attach it to the paths that check auth. Leave public paths unmarked. - Lint the file. Redocly, Spectral, or
@apidevtools/swagger-parserwill do. The file must parse, and every$refmust resolve. - If the handlers drift, update the spec in the same change. A spec that lies is worse than no spec.
openapi: 3.1.0
info:
title: Orders
version: 1.4.0
paths:
/orders:
post:
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/NewOrder"
responses:
"201":
description: Created
components:
schemas:
NewOrder:
type: object
properties:
sku:
type: string
examples: ["mug-01"]
Gotchas
- Do not paste live tokens, passwords, or customer payloads into examples. Use fake values such as
sku-demo. - OpenAPI 3.1 uses JSON Schema. A 3.0
nullable: trueis not the 3.1 form. Usetype: ["string", "null"]when a value may be null. - A path that does not match the router will generate a client that calls the wrong URL.
- Security on the whole file also locks public routes. Override those with
security: [].
Portability
The file is tool-neutral. If you use FastAPI, Nest, or tsoa, generate this document from the code and then read the diff. If you use Go or Rails, a hand-written file plus a lint step is enough. The same $ref habit works in either style.
Done when
openapi.yamlparses as 3.1 and every shipped route is listed.- Shared bodies and the error shape are
$refs, with fake examples. - Auth is declared, and no real secret is in the file.
Example prompt
"Write an OpenAPI 3.1 file for the order routes in this server. Reuse the error schema, and do not include real customer data."
---
Adapted from "openapi-spec-generation" in wshobson/agents (MIT, Copyright (c) 2024 Seth Hobson). See LICENSE.txt.
Bundled files
Licence
Adapted from Seth Hobson (wshobson/agents, openapi-spec-generation) (Copyright (c) 2024 Seth Hobson), MIT License. Adapted by TheSkillVault: rewritten as a short code-first checklist (paths, components, examples, security, lint) with one original fragment; dropped the design-first catalogue; added secret handling, gotchas and done-when.
Licence: MIT License. Attribution when you reuse it: Based on work by Seth Hobson (wshobson/agents, openapi-spec-generation) (Copyright (c) 2024 Seth Hobson, MIT License), https://github.com/wshobson/agents/tree/7e2fb559cf4b824b27f1fec49fe88f7511066d26/plugins/documentation-generation/skills/openapi-spec-generation; adapted by TheSkillVault, https://theskillvault.ai