import { Swagger, SwaggerLookup } from '@atlassian/atlassian-openapi'; import { OpenApiDocument } from './oas31'; /** * `SwaggerLookup.InternalLookup` (from `@atlassian/atlassian-openapi`) is not * missing external-ref support by oversight -- its own source comment says * so: "Any references that don't start with a # are external, and thus not * handled." It assumes whoever calls it already has one, fully self-contained * document, and its internal chain-walk (`performLookup`) has no cycle guard * of its own -- a purely local reference cycle (two components in one * document naming each other) recurses forever. * * `CrossDocumentLookup` is a second `Lookup` implementation that resolves * both a bare (`#`-prefixed) `$ref` and a cross-document `$ref` * (`#`) through the *same* recursive walk, against a map * of every other document the caller already knows about -- exactly the * shape `MergeOptions.externalDocuments` already takes, plus each declared * input's own document keyed by its `sourceIdentity`. No fetching happens * here or anywhere in this library (see `external-references.ts`'s own * docstring); assembling that map is the caller's job, done once per merge in * `paths-and-components.ts`. * * This does not delegate to `InternalLookup` -- it reimplements the same * resolution directly (the same `SwaggerTypeChecks` predicates * `InternalLookup` itself uses, already public exports, and the same * schema-title-backfill rule), so that a single `seen` set can guard *every* * hop, local or cross-document, against a cycle. That single walk is also * what closes the purely-local cycle case: it isn't a separate feature, it * falls out of not having two different resolution mechanisms to keep a * cycle guard in sync with. * * `typeof null === 'object'` in JavaScript, and every `SwaggerTypeChecks` * predicate this class calls relies on that to mean "a real object" -- * so a `null` in a structural slot (an empty YAML value: a component name * with nothing written after it) throws a raw `TypeError` from deep inside * one of them, same as it always did before `safe-type-checks.ts` existed * (see ai-planning/40-proposal-null-safe-document-walking.md §2.1). This * class does its own `jsonpointer` fetch rather than going through * `InternalLookup`, so it did not inherit that module's guard for free -- * every fetched value is passed through {@link required} before any * `SwaggerTypeChecks` call sees it, for the same reason and with the same * "fail clearly, don't crash or guess" answer proposal 40 already gave * everywhere else in this library. * * @see 45-proposal-external-ref-equality-in-dedup.md, Option C. * @see 46-proposal-local-reference-cycle-guard.md, Option B. */ export declare class CrossDocumentLookup implements SwaggerLookup.Lookup { private readonly localDocument; private readonly knownDocuments; constructor(localDocument: OpenApiDocument, knownDocuments?: Readonly>); getCallback(c: Swagger.Callback | Swagger.Reference): Swagger.Callback | undefined; getExample(e: Swagger.Example | Swagger.Reference): Swagger.Example | undefined; getHeaders(h: Swagger.Header | Swagger.Reference): Swagger.Header | undefined; getLink(link: Swagger.Link | Swagger.Reference): Swagger.Link | undefined; getParam(p: Swagger.ParameterOrRef): Swagger.Parameter | undefined; getRequestBody(b: Swagger.RequestBody | Swagger.Reference): Swagger.RequestBody | undefined; getResponse(r: Swagger.Response | Swagger.Reference): Swagger.Response | undefined; getSecurityScheme(ss: Swagger.SecurityScheme | Swagger.Reference): Swagger.SecurityScheme | undefined; /** * Unlike every other accessor, a security scheme named this way is always * local: a Security Requirement Object names a scheme declared in the SAME * document (`{ apiKey: [] }`, an object key, never a `$ref`), so there is no * cross-document form of this lookup to support. Matches `InternalLookup`'s * own `getSecuritySchemeByName`: build the bare ref it would have named, * and resolve that. */ getSecuritySchemeByName(name: string): Swagger.SecurityScheme | undefined; getSchema(s: Swagger.Schema | Swagger.Reference): Swagger.Schema | undefined; private resolve; /** * The single recursive walk both a bare ref and a cross-document ref go * through, at every hop. * * @param identity `undefined` for the top-level local document, otherwise * the identity `doc` was reached under -- both threaded through so a bare * ref discovered partway through (another document's own local alias) * resolves against *that* document, not back against the original * caller's. * @param expected Threaded through purely so a `null` structural slot names * what kind of object was expected there, via {@link required}. */ private resolveFrom; } /** * Assembles the map `CrossDocumentLookup` resolves cross-document refs * against: every declared input's own document, keyed by its * `sourceIdentity`, plus `externalDocuments`. * * An identity claimed by more than one input (`ambiguousIdentities`, issue * #104 §5.2) is left out entirely -- there is no principled way to pick which * input a ref meant, matching how `resolveIdentityFragment` in * `external-references.ts` already treats the same situation as unresolved * rather than guessed at. Declared inputs take precedence over * `externalDocuments` on a genuine key collision, mirroring that same * function's own lookup order. */ export declare function buildKnownDocuments(inputs: ReadonlyArray<{ oas: OpenApiDocument; sourceIdentity?: string; }>, ambiguousIdentities: ReadonlySet, externalDocuments: Readonly>): Record; //# sourceMappingURL=cross-document-lookup.d.ts.map