UNPKG

juniper

Version:

ESM JSON Schema builder for static Typescript inference.

49 lines 1.59 kB
import type { JsonSchema } from './types.js'; /** * Merge and `allOf` schema with existing schema's `allOf`. * * Optimization to re-use schema objects. * * __Modifies schema in place.__ * * Also returns object for convenience. * * @example * mergeAllOf( * { * type: 'string', * allOf: [{ pattern: 'a' }, { pattern: 'b' }], * }, * [{ minLength: 1 }, { maxLength: 5 }, { enum: ['abc', 'abcd'] }] * ) -> { * type: 'string', * allOf: [ * { pattern: 'a', minLength: 1 }, * { pattern: 'b', maxLength: 5 }, * { enum: ['abc', 'abcd'] } * ] * } * * @param base - base schema object. Modified in place. * @param allOf - schema objects to append/merge to `allOf`. * @returns base object, with `allOf` merged */ export declare const mergeAllOf: <S extends JsonSchema<any>>(base: S, allOf: NonNullable<S["allOf"]>) => S; /** * Dedupe attributes between `$ref` and schema. * Apply defaults in case of "hidden" properties. * * @param params - required params * @param params.baseSchema - schema that includes `$ref` * @param params.defaultValues - dictionary of default values (defined per schema) * @param params.refPath - path to ref * @param params.refSchema - schema pointed to by `$ref` * @returns json schema with `$ref` */ export declare const mergeRef: <T>({ baseSchema, defaultValues, refPath, refSchema, }: { baseSchema: JsonSchema<T>; defaultValues: Record<string, unknown>; refPath: string; refSchema: JsonSchema<T>; }) => JsonSchema<T>; //# sourceMappingURL=utils.d.ts.map