— MIT Licensed — Resolution Engine

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.

$npm install @powerduck/oas-document
$ref ResolutionOperation FlatteningcURL ExamplesNavigation GroupsSchema Fields
Quick Start

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);
}
Features

Everything an API viewer needs

Built to power the PowerDuck API documentation viewer and request debugger.

02

$ref Resolution

resolveReference() and createOasResolveContext() resolve component references, external URLs, and handle circular references. All resolved values are cached per document.

03

Operation Flattening

parseOperations() and flattenOperations() convert the paths object into a flat list of display-ready operations with resolved parameters, request bodies, and responses.

04

Request Examples

buildCurlExample() and buildJavaScriptExample() generate runnable code snippets. generateRequestExamples() creates example bodies from request body schemas.

05

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.

06

Navigation Groups

buildNavigationGroups() groups operations by tags, producing the sidebar structure needed for API documentation UIs.

API Reference

Core functions

functionloadOasDocument(input, options?)Load and parse an OpenAPI document
ParameterTypeDescription
inputstringYAML/JSON string or URL
options.autoUpgradebooleanAuto-upgrade OAS < 3.2 default: false
Returns
LoadOasDocumentResult { ok: boolean; document?: OpenApiDocument; error?: string }
functionflattenOperations(operations, doc)Resolve refs and flatten operations for UI display
Returns
OpenApiOperation[] — each with resolved parameters, requestBody, responses
functionbuildCurlExample(operation, doc, options?)Generate a runnable cURL command

Includes method, path with substituted params, headers, and request body from schema examples.

functionflattenSchemaFields(schema, doc, path?)Extract typed fields from a schema tree
Returns
OasSchemaField[] — path, type, description, constraints, required
functionbuildNavigationGroups(operations, doc)Group operations by tag for sidebar UI
Returns
OasNavigationGroup[] — { tag, description, operations[] }
functionresolveReference(ref, context)Resolve a $ref pointer using a resolve context

Create context with createOasResolveContext(doc). Handles local pointers and external references.

50+
Core Functions
3.2
OpenAPI Target
0.1.3
Current Version
MIT
License