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.
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); } }
The OpenAPI foundation
Every PowerDuck tool depends on this package for parsing, upgrading, and validating OpenAPI documents.
Multi-Version Support
Parse and validate OpenAPI 2.0 (Swagger), 3.0, 3.1, and 3.2. Typed exports for each version let you safely discriminate between document shapes.
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.
Deep Validation
validate() checks document structure, schema correctness, and reference integrity. Returns detailed diagnostics with JSON Pointer paths.
Dereference
dereference() resolves all $ref pointers including external URLs and circular references, producing a fully resolved document.
Rich Type Exports
Type-safe exports for Oas32Document, SchemaObject, OperationObject, ParameterObject, ResponseObject, and more — all from @scalar/openapi-types.
Error Types
OpenApiUpgradeError with typed UpgradeErrorCode values. Use isOpenApiUpgradeError() for safe runtime error discrimination.
Core API
Wraps @scalar/openapi-parser validate. Accepts YAML/JSON strings or parsed objects. Returns { valid, errors, warnings } with OpenApiValidationIssue[].
| Parameter | Type | Description |
|---|---|---|
| input | string | object | OAS document (YAML, JSON, or parsed object) |
| options.continueOnError | boolean | Continue upgrade even if warnings occur default: false |
UpgradedDocument { ok: boolean; document?: Oas32Document; error?: OpenApiUpgradeError }Wraps @scalar/openapi-parser dereference. Handles local, remote, and circular references.
Wraps @scalar/openapi-parser upgrade. Low-level upgrade function; prefer upgradeOasTo32() for typed 3.2 output.
Properties: code (UpgradeErrorCode), message, source. Use isOpenApiUpgradeError() for runtime type guards.
Enumerates specific failure modes: unsupported version, invalid document, reference resolution failures, and migration errors.