import type { OasSchema } from './Schema.js'; import type { OasRef } from '../ref/Ref.js'; /** * The keywords next to a reference in a one-member `allOf` * (`{ allOf: [{ $ref }], minLength: 3, description: '…' }`), the use-site * flags `nullable`, `readOnly` and `writeOnly` among them: the fields a * reference adds at its site (`RefFields`). * * The parser reads them without knowing the target's type: the reference * stays lazy. Each schema class's `clone(ref)` takes the keywords its type * has ({@link SIBLINGS_BY_TYPE}). A value whose type depends on the target * (`example`, `default`, `enums`, `format`) is kept as written, and `clone` * takes it only when it fits. {@link toSkippedSiblings} names the keywords * `clone` leaves out, for a generator to log. */ export type SiblingKeywords = { /** * Use-site nullability. A `$ref` is a per-reference node: the same * refName may be referenced nullable at one site and non-nullable at * another, so nullability rides the reference, not the shared referent. * Set by the single-member `oneOf`/`anyOf` collapse for the 3.1 * `oneOf:[{$ref},{type:null}]` idiom, and next to a one-member `allOf`. * Generators read it off the reference (`'nullable' in schema ? * schema.nullable`) to render `Foo | null`, while `ModelDriver` builds the * un-nullable shared model from the refName. */ nullable?: boolean; /** * Use-site `readOnly`: set where a property marks a reference read-only, * `{ allOf: [{ $ref }], readOnly: true }` (the 3.0 idiom, as keywords next * to a bare `$ref` are ignored there). Like `nullable`, it rides the * reference: the shared model is not read-only everywhere. Read it through * `isReadOnly`, which also looks at what the reference points to. */ readOnly?: boolean; /** Use-site `writeOnly`, as {@link readOnly}. */ writeOnly?: boolean; /** * The `type` written next to the reference, merged in from the schema that * holds the one-member `allOf`. It must agree with the target's; the copy * always has the target's type. Not `type`, which on an `OasRef` is `'ref'`. */ _type?: unknown; title?: string; description?: string; deprecated?: boolean; example?: unknown; default?: unknown; enums?: unknown[]; extensionFields?: Record; format?: string; minLength?: number; maxLength?: number; pattern?: string; multipleOf?: number; minimum?: number; maximum?: number; exclusiveMinimum?: boolean; exclusiveMaximum?: boolean; minItems?: number; maxItems?: number; uniqueItems?: boolean; properties?: Record>; required?: string[]; additionalProperties?: boolean | OasSchema | OasRef<'schema'>; minProperties?: number; maxProperties?: number; }; /** A keyword `clone` can apply. `_type` only has to agree. */ export type SiblingKeyword = Exclude; /** The keywords each schema class's `clone` takes: the fields its type has. */ export declare const SIBLINGS_BY_TYPE: Record; /** * The keywords of `over` merged over those of `base`, for a reference copied * with what another site adds (`OasRef.clone`): a flag set on either stays * set, a keyword `over` sets wins, extension fields and `properties` merge, * and `required` names add up, as each schema class's `clone` merges them * into a schema. */ export declare const mergeSiblingKeywords: (base: SiblingKeywords, over: SiblingKeywords | undefined) => SiblingKeywords; /** Whether `siblings` holds any keyword. */ export declare const hasSiblingKeywords: (siblings: SiblingKeywords) => boolean; /** Whether the keywords next to a reference change `target` at that site. The engine behind `OasRef.resolve`. */ export declare const changesTarget: (copy: OasSchema, target: OasSchema, siblings: SiblingKeywords) => boolean; /** * Whether the keywords next to a reference change which values `target` * accepts at that site (`minLength` next to a string, `properties` next to an * object), not only how it is described (`description`, `deprecated`, * `default`, `x-*`). The engine behind `OasRef.hasValueSiblings`. */ export declare const changesValues: (copy: OasSchema, target: OasSchema, siblings: SiblingKeywords) => boolean; /** * The keywords next to a reference that `clone` leaves out for `target`, by * their names in the document: one its type does not have (`minLength` next * to an array), a `type` that disagrees with the target's, and an `example`, * `default`, `enum` or `format` whose value does not fit. `nullable` says * whether the site takes `null` among the `enum` members. The engine behind * `OasRef.toSkippedSiblings`. */ export declare const toSkippedSiblings: (target: OasSchema, siblings: SiblingKeywords, nullable: boolean | undefined) => string[]; /** The annotations of `target` with those of `siblings` applied: a sibling's value wins, and extension fields merge. */ export declare const toSiblingAnnotations: (target: OasSchema, siblings: SiblingKeywords | undefined) => { title: string | undefined; description: string | undefined; extensionFields: { [x: string]: unknown; } | undefined; }; /** The value checks the parser makes for `example`, `default` and each `enum` member, by type. */ export declare const isStringValue: (value: unknown) => value is string; export declare const isNumberValue: (value: unknown) => value is number; export declare const isIntegerValue: (value: unknown) => value is number; export declare const isBooleanValue: (value: unknown) => value is boolean; export declare const isArrayValue: (value: unknown) => value is unknown[]; export declare const isObjectValue: (value: unknown) => value is Record; /** {@link isStringValue} and the others, keyed by the type they check for. A union or unknown takes any value. */ export declare const VALUE_CHECKS: Record boolean>; /** The formats a number and an integer take. A string takes any format. */ export declare const isNumberFormat: (value: unknown) => value is "float" | "double"; export declare const isIntegerFormat: (value: unknown) => value is "int32" | "int64"; /** `value` when it passes `check`, else `undefined`: for `example`, `default` and `format`. */ export declare const toSiblingValue: (value: unknown, check: (value: unknown) => value is T) => T | undefined; /** * `enums` when every member passes `check`, or is `null` at a nullable site, * else `undefined`. The parser reports the members that do not. */ export declare const toSiblingEnums: (enums: unknown[] | undefined, check: (value: unknown) => value is T, nullable: boolean | undefined) => (T | null)[] | undefined;