— MIT Licensed — 100% TypeScript

Parse, Upgrade & Validate OpenAPI Documents

The foundation layer of the PowerDuck ecosystem. Parse OpenAPI documents from YAML or JSON, upgrade OAS 2.0/3.0/3.1 to 3.2, validate against the spec, and dereference $ref pointers — all in a single, typed package.

$npm install @powerduck/openapi-parser
OAS 2.0–3.2YAML & JSON$ref DereferenceType-Safe TypesValidation Diagnostics
Quick Start

Four operations, zero ceremony

import { validate } from "@powerduck/openapi-parser";

const result = await validate(yamlString);
if (result.valid) {
  console.log("Document is valid OpenAPI");
} else {
  for (const issue of result.errors) {
    console.error(issue.message, issue.path);
  }
}
Features

The OpenAPI foundation

Every PowerDuck tool depends on this package for parsing, upgrading, and validating OpenAPI documents.

02

Upgrade to 3.2

upgradeOasTo32() migrates older OAS documents to the 3.2 specification. Handles breaking changes, converts formats, and produces a valid 3.2 document.

03

Deep Validation

validate() checks document structure, schema correctness, and reference integrity. Returns detailed diagnostics with JSON Pointer paths.

04

Dereference

dereference() resolves all $ref pointers including external URLs and circular references, producing a fully resolved document.

05

Rich Type Exports

Type-safe exports for Oas32Document, SchemaObject, OperationObject, ParameterObject, ResponseObject, and more — all from @scalar/openapi-types.

06

Error Types

OpenApiUpgradeError with typed UpgradeErrorCode values. Use isOpenApiUpgradeError() for safe runtime error discrimination.

API Reference

Core API

functionvalidate(input)Validate an OpenAPI document (YAML string, JSON string, or object)

Wraps @scalar/openapi-parser validate. Accepts YAML/JSON strings or parsed objects. Returns { valid, errors, warnings } with OpenApiValidationIssue[].

functionupgradeOasTo32(input, options?)Upgrade OAS 2.0/3.0/3.1 to OpenAPI 3.2
ParameterTypeDescription
inputstring | objectOAS document (YAML, JSON, or parsed object)
options.continueOnErrorbooleanContinue upgrade even if warnings occur default: false
Returns
UpgradedDocument { ok: boolean; document?: Oas32Document; error?: OpenApiUpgradeError }
functiondereference(input)Resolve all $ref pointers in a document

Wraps @scalar/openapi-parser dereference. Handles local, remote, and circular references.

functionupgrade(input)Upgrade an OpenAPI document to the latest version

Wraps @scalar/openapi-parser upgrade. Low-level upgrade function; prefer upgradeOasTo32() for typed 3.2 output.

classOpenApiUpgradeErrorTyped error thrown when OAS upgrade fails

Properties: code (UpgradeErrorCode), message, source. Use isOpenApiUpgradeError() for runtime type guards.

enumUpgradeErrorCodeDiscriminated error codes for upgrade failures

Enumerates specific failure modes: unsupported version, invalid document, reference resolution failures, and migration errors.

4
OAS Versions
3.2
Latest Spec
0.3.6
Current Version
MIT
License