OpenAPI Document Resolution Engine
Load OpenAPI documents, resolve $ref references, flatten operations for UI display, generate request examples (cURL, JavaScript), and build tag-based navigation groups. Everything an API documentation viewer needs.
From document to UI data
import { loadOasDocument } from "@powerduck/oas-document"; // Load from YAML/JSON string or URL const result = await loadOasDocument(yamlString, { autoUpgrade: true, // auto-upgrade to 3.2 if needed }); if (result.ok) { const doc = result.document; // OpenApiDocument console.log(doc.title, doc.version); } else { console.error(result.error); }
Everything an API viewer needs
Built to power the PowerDuck API documentation viewer and request debugger.
Document Loader
loadOasDocument() accepts YAML strings, JSON strings, or URLs. Auto-upgrades older OAS versions to 3.2. Returns a typed OpenApiDocument or a structured error.
$ref Resolution
resolveReference() and createOasResolveContext() resolve component references, external URLs, and handle circular references. All resolved values are cached per document.
Operation Flattening
parseOperations() and flattenOperations() convert the paths object into a flat list of display-ready operations with resolved parameters, request bodies, and responses.
Request Examples
buildCurlExample() and buildJavaScriptExample() generate runnable code snippets. generateRequestExamples() creates example bodies from request body schemas.
Schema Field Extraction
flattenSchemaFields() walks a schema tree and produces a flat list of typed fields with paths, types, constraints, and descriptions — perfect for form generation.
Navigation Groups
buildNavigationGroups() groups operations by tags, producing the sidebar structure needed for API documentation UIs.
Core functions
| Parameter | Type | Description |
|---|---|---|
| input | string | YAML/JSON string or URL |
| options.autoUpgrade | boolean | Auto-upgrade OAS < 3.2 default: false |
LoadOasDocumentResult { ok: boolean; document?: OpenApiDocument; error?: string }OpenApiOperation[] — each with resolved parameters, requestBody, responses
Includes method, path with substituted params, headers, and request body from schema examples.
OasSchemaField[] — path, type, description, constraints, required
OasNavigationGroup[] — { tag, description, operations[] }Create context with createOasResolveContext(doc). Handles local pointers and external references.