import { O as OpenAPIDocument } from './types-Dzi0PpYX.cjs'; import { S as SpecHygieneIssue } from './lint-fVgIO4pF.cjs'; /** * Opaque reader that turns a URI into a parsed JSON-compatible value. * Multiple readers can be layered via {@link composeReaders} so the * resolver can accept different URI schemes uniformly. * * @public */ interface DocumentReader { read(uri: string): Promise; /** Returns true if this reader can handle the given URI. */ canRead(uri: string): boolean; } /** * Read files from the local filesystem. JSON only; `.yaml` / `.yml` * paths throw with a clear install hint. Pair with * `oav`' `createYamlFileReader` via * {@link composeReaders} for YAML support. * * @param cwd - Optional base directory. Defaults to `process.cwd()`. * @returns A {@link DocumentReader}. * * @example * ```ts * const reader = createFileReader("/abs/spec"); * await reader.read("openapi.json"); * ``` * * @public */ declare function createFileReader(cwd?: string): DocumentReader; /** * Read documents over HTTP/HTTPS. JSON only; pair with * `oav`'s `createSmartHttpReader` for YAML (it claims all * `http(s)` URIs and dispatches by `Content-Type`, so it shadows this * reader in a compose chain; that's fine; JSON endpoints still parse * as JSON there). * * @returns A {@link DocumentReader}. * * @example * ```ts * const reader = createHttpReader(); * await reader.read("https://example.com/spec.json"); * ``` * * @public */ declare function createHttpReader(): DocumentReader; /** * In-memory reader, keyed by string URI. Primarily used in tests. * String sources are parsed as JSON; pre-parsed object sources pass * through. YAML strings need pre-parsing via * `oav`' `parseYamlString` before they're added to * the map. * * @param sources - Map of URI → JSON string (or already-parsed value). * @returns A {@link DocumentReader}. * * @example * ```ts * const reader = createMemoryReader(new Map([ * ["main.json", '{"openapi":"3.1.0","info":{"title":"X","version":"1"}}'], * ])); * ``` * * @public */ declare function createMemoryReader(sources: Map): DocumentReader; /** * Try each reader in order until one accepts the URI. Useful for mixing * file / HTTP / memory sources in a single resolver, and for layering * the YAML readers from `oav` ahead of the * JSON-only ones here. * * @param readers - Ordered list of readers. * @returns A composite {@link DocumentReader}. * * @example * ```ts * import { createYamlFileReader } from "@aahoughton/oav"; * const reader = composeReaders([createYamlFileReader(), createFileReader()]); * ``` * * @public */ declare function composeReaders(readers: DocumentReader[]): DocumentReader; /** * Synchronous counterpart of {@link DocumentReader}: same `canRead` * predicate, but `read` returns the parsed value directly instead of a * `Promise`. Backs the synchronous spec loader, which exists for * load-once-at-boot programs and CLIs that can't await. * * The shape is deliberately the async interface with the `Promise` * removed from `read`, so a future decision to make custom sync readers * a public, supported extension point is a pure-additive `export` of * this type rather than a redesign. Because TypeScript is structural, a * caller can already satisfy it today with a `{ read, canRead }` object * literal passed to `loadSpecSync`'s optional `reader`, without this * name being exported. */ interface SyncDocumentReader { read(uri: string): unknown; /** Returns true if this reader can handle the given URI. */ canRead(uri: string): boolean; } /** * Synchronous {@link createFileReader}. Blocking `readFileSync`; JSON * only, with the same YAML install-hint as the async reader. For * boot-time / CLI loads, not per-request; use the async * {@link createFileReader} for non-blocking contexts. */ declare function createFileReaderSync(cwd?: string): SyncDocumentReader; /** * Synchronous {@link composeReaders}: try each {@link SyncDocumentReader} * in order until one accepts the URI. */ declare function composeReadersSync(readers: SyncDocumentReader[]): SyncDocumentReader; /** * Options accepted by {@link resolveSpec}. * * @public */ interface ResolveSpecOptions { /** Reader used to fetch documents by URI. */ reader: DocumentReader; /** Entry URI. */ entry: string; /** Base directory/URI for resolving relative refs. Defaults to the entry's directory. */ baseUri?: string; /** * Run spec-hygiene lint passes against the resolved document. * Findings land in {@link ResolvedSpec.specHygieneIssues}. Defaults * to `false`. See {@link lintResolvedSpec}. */ lint?: boolean; } /** * Output of {@link resolveSpec}: the stitched OpenAPI document plus a record * of how every external file was inlined. * * @public */ interface ResolvedSpec { document: OpenAPIDocument; /** URIs of every external file that was loaded during resolution. */ sources: string[]; /** * Spec-hygiene findings from {@link lintResolvedSpec}. Empty unless * {@link ResolveSpecOptions.lint} was set. Same name and shape as * {@link Validator.specHygieneIssues} on the validator side. */ specHygieneIssues: readonly SpecHygieneIssue[]; } /** * Load an OpenAPI 3.1 document and inline all external `$ref`s, producing a * single self-contained document. Circular references are materialized under * `$defs.__ext__/` so the compiler can resolve them via the * identity-keyed schema cache; non-circular external refs are fully inlined. * * The synchronous mirror is `resolveSpecSync` (reachable via * `oav/spec/internals`); both share the pure URI / ref-rewriting helpers * in `./resolver-shared.ts` and are pinned to identical behavior by the * parity suite. Keep any change to the walk here mirrored there. * * @param options - Reader + entry URI. * @returns Resolved document + the list of files loaded. * * @example * ```ts * const reader = composeReaders([createFileReader()]); * const { document } = await resolveSpec({ reader, entry: "openapi.yaml" }); * ``` * * @public */ declare function resolveSpec(options: ResolveSpecOptions): Promise; export { type DocumentReader as D, type ResolvedSpec as R, type SyncDocumentReader as S, type ResolveSpecOptions as a, createFileReader as b, composeReaders as c, createHttpReader as d, createMemoryReader as e, composeReadersSync as f, createFileReaderSync as g, resolveSpec as r };