Parse OpenAPI 3.x / Swagger 2.x specs and extract endpoint information
Parse OpenAPI specifications and extract structured endpoint information for code generation.
When this skill is invoked, Claude MUST perform these steps in order:
Determine source type:
http:// or https:// â Remote URLFor Remote URL:
WebFetch tool to fetch the contentâ Spec not found at URLâ Failed to fetch: <error>For Local File:
Read tool to read the file.yaml or .yml extension â Parse as YAML.json extension or no extension â Parse as JSONâ File not found: <path>â Invalid format: <error>Check for valid OpenAPI/Swagger structure:
Version Check:
openapi field (e.g., "3.0.0", "3.1.0") â OpenAPI 3.xswagger field (e.g., "2.0") â Swagger 2.0â Not a valid OpenAPI/Swagger specRequired Fields:
info object with title and versionpaths objectâ Missing required field: <field>Report:
đ OpenAPI: <title> v<version>
Spec version: <openapi/swagger version>
Endpoints: <count>
If Swagger 2.0, convert to OpenAPI 3.0 format internally:
| Swagger 2.0 | OpenAPI 3.0 |
|---|---|
definitions |
components.schemas |
parameters (body) |
requestBody |
produces/consumes |
content with media types |
securityDefinitions |
components.securitySchemes |
Extract and store:
{
"title": "<info.title>",
"version": "<info.version>",
"description": "<info.description or null>",
"servers": ["<server urls>"],
"specVersion": "<openapi or swagger version>"
}
For each path in paths object:
Parse each method (GET, POST, PUT, PATCH, DELETE)
Extract:
path: The URL pathmethod: HTTP methodoperationId: Unique identifier (generate if missing)tags: Array of tags (use ["default"] if none)summary: Brief descriptiondescription: Full descriptionparameters: Path, query, header parametersrequestBody: Request body schemaresponses: Response schemas by status codesecurity: Required security schemesGenerate hash for each endpoint (for change detection)
Resolve all $ref references:
$ref strings in the speccomponents.schemas// Circular reference to <TypeName>Organize endpoints by their primary tag:
{
"users": {
"description": "<tag description>",
"endpoints": [
{ "method": "GET", "path": "/users", "operationId": "listUsers" },
{ "method": "POST", "path": "/users", "operationId": "createUser" }
],
"schemas": ["User", "CreateUserRequest"]
}
}
For each schema in components.schemas:
For full error code reference, see ../../docs/ERROR-CODES.md.
Error: "[E201/E202] â Failed to parse spec: <parse error message>"
Cause: Malformed JSON/YAML syntax
Fix: Validate at jsonlint.com or yamlint.com
Action: Abort and show line number if available
Error: "[E203] â Not a valid OpenAPI/Swagger specification"
Cause: Missing 'openapi' or 'swagger' field
Fix: Verify file is OpenAPI 3.x or Swagger 2.0 format
Action: Abort operation
Warning: "[E205] â ī¸ Unresolved reference: <$ref path>"
Cause: Reference points to non-existent definition
Fix: Check $ref path is correct
Recovery: Use `unknown` type, continue processing
Info: "[E206] âšī¸ Circular reference detected in <schema name>"
Cause: Self-referencing data structure
Recovery: Use type reference instead of inline expansion
Warning: "[E207] â ī¸ Unsupported feature: <feature name> (skipping)"
Features: callbacks, links, webhooks
Recovery: Skip feature, continue processing
Info: "[E405] âšī¸ Missing operationId for <method> <path>"
Recovery: Generate from method + path (e.g., `get_users_id`)
| OpenAPI Type | TypeScript Type |
|---|---|
string |
string |
string (format: date, date-time) |
string |
string (format: uuid) |
string |
string (format: email) |
string |
string (format: binary) |
Blob | File |
string (enum) |
'value1' | 'value2' |
integer |
number |
integer (format: int64) |
number |
number |
number |
boolean |
boolean |
array |
T[] |
object |
{ [key: string]: unknown } |
object (with properties) |
{ prop1: T1; prop2?: T2 } |
null |
null |
oneOf |
T1 | T2 |
anyOf |
T1 | T2 |
allOf |
T1 & T2 |
$ref |
ReferencedTypeName |
required array â propName: Typerequired â propName?: Typenullable: true â propName: Type \| nullFor comprehensive edge case handling (circular references, Swagger 2.0 conversion, large specs, etc.), see ../../docs/EDGE-CASES.md.
Return this structure to the calling command:
{
"meta": {
"title": "My API",
"version": "2.0.0",
"specVersion": "3.0.3",
"servers": ["https://api.example.com"]
},
"hash": {
"spec": "sha256:abc123...",
"fetchedAt": "2024-01-13T12:00:00Z",
"source": "https://api.example.com/openapi.json"
},
"tags": {
"users": {
"description": "User management",
"endpoints": [
{
"method": "GET",
"path": "/users/{id}",
"operationId": "getUser",
"hash": "a1b2c3d4",
"parameters": [...],
"responses": {...}
}
],
"schemas": ["User", "GetUserRequest"]
}
},
"schemas": {
"User": {
"hash": "x1y2z3",
"definition": {
"type": "object",
"properties": {...},
"required": [...]
}
}
},
"stats": {
"endpointCount": 25,
"tagCount": 5,
"schemaCount": 18
}
}