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
$refreferences within an OpenAPI specification. - Flattening: Merges
allOfschemas 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$refproperties 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$reffound in these paths will be ignored.
- Returns: The fully dereferenced document.
- Parameters:
-
flattenAllOf(apiDoc: any): Promise<any>
FlattensallOfproperties in an OpenAPI document, merging schemas into a single object.- Parameters:
apiDoc: The OpenAPI document object to be flattened.
- Returns: The document with
allOfproperties flattened.
- Parameters:
-
selectFirstOfOneOf(apiDoc: any): Promise<any>
SimplifiesoneOfarrays by selecting the first schema.- Parameters:
apiDoc: The OpenAPI document object to process.
- Returns: The document with
oneOfarrays simplified.
- Parameters:
-
selectFirstOfAnyOf(apiDoc: any): Promise<any>
SimplifiesanyOfarrays by selecting the first schema.- Parameters:
apiDoc: The OpenAPI document object to process.
- Returns: The document with
anyOfarrays simplified.
- Parameters:
Run tests using Deno’s testing suite:
deno test --allow-readMIT License.