A Deno module to recursively dereference and flatten OpenAPI specifications. This module provides functions to handle $ref
, allOf
, oneOf
, and anyOf
structures, creating a fully dereferenced and optionally flattened document.
See the project on jsr for more info.
- Full dereferencing: Resolves all
$ref
references within an OpenAPI specification. - Flattening: Merges
allOf
schemas into a single object. - Selective processing: Allows dereferencing from a specific path within the document.
- Path-based exclusion: Optionally skip dereferencing for specific paths within the document using
ignorePaths
.
To use the module, import it from Deno Land:
import {
dereferenceApi,
flattenAllOf,
selectFirstOfOneOf,
selectFirstOfAnyOf
} from "jsr:@stackql/deno-openapi-dereferencer";
import { dereferenceApi } from "jsr:@stackql/deno-openapi-dereferencer";
const apiDoc = await Deno.readTextFile("./path/to/openapi.yaml");
const dereferencedDoc = await dereferenceApi(apiDoc);
console.log(dereferencedDoc);
import { flattenAllOf } from "jsr:@stackql/deno-openapi-dereferencer";
const flattenedDoc = await flattenAllOf(dereferencedDoc);
console.log(flattenedDoc);
import { dereferenceApi } from "jsr:@stackql/deno-openapi-dereferencer";
const apiDoc = await Deno.readTextFile("./path/to/openapi.yaml");
const ignorePaths = ["$.components.x-stackQL-resources"]; // Exclude specific paths
const dereferencedDoc = await dereferenceApi(apiDoc, "$", ignorePaths);
console.log(dereferencedDoc);
-
dereferenceApi(apiDoc: any, startAt: string = "$", ignorePaths?: string[]): Promise<any>
Dereferences$ref
properties from a specified path in the OpenAPI document.- Parameters:
apiDoc
: The OpenAPI document object to be dereferenced.startAt
(optional): JSONPath to specify the starting point for dereferencing. Defaults to the root ("$"
).ignorePaths
(optional): Array of JSONPath expressions. Any$ref
found in these paths will be ignored.
- Returns: The fully dereferenced document.
- Parameters:
-
flattenAllOf(apiDoc: any): Promise<any>
FlattensallOf
properties in an OpenAPI document, merging schemas into a single object.- Parameters:
apiDoc
: The OpenAPI document object to be flattened.
- Returns: The document with
allOf
properties flattened.
- Parameters:
-
selectFirstOfOneOf(apiDoc: any): Promise<any>
SimplifiesoneOf
arrays by selecting the first schema.- Parameters:
apiDoc
: The OpenAPI document object to process.
- Returns: The document with
oneOf
arrays simplified.
- Parameters:
-
selectFirstOfAnyOf(apiDoc: any): Promise<any>
SimplifiesanyOf
arrays by selecting the first schema.- Parameters:
apiDoc
: The OpenAPI document object to process.
- Returns: The document with
anyOf
arrays simplified.
- Parameters:
Run tests using Deno’s testing suite:
deno test --allow-read
MIT License.