(
ref: string,
definitions: DefinitionCollections | undefined
)
| 1027 | |
| 1028 | /** Resolve a `$ref` path against a definitions map, returning the referenced schema. */ |
| 1029 | export function resolveRef( |
| 1030 | ref: string, |
| 1031 | definitions: DefinitionCollections | undefined |
| 1032 | ): JSONSchema7 | undefined { |
| 1033 | const match = ref.match(/^#\/(definitions|\$defs)\/(.+)$/); |
| 1034 | if (!match || !definitions) return undefined; |
| 1035 | const [, namespace, key] = match; |
| 1036 | const primary = namespace === "$defs" ? definitions.$defs : definitions.definitions; |
| 1037 | const fallback = namespace === "$defs" ? definitions.definitions : definitions.$defs; |
| 1038 | const def = primary?.[key] ?? fallback?.[key]; |
| 1039 | return typeof def === "object" ? (def as JSONSchema7) : undefined; |
| 1040 | } |
| 1041 | |
| 1042 | export function resolveSchema( |
| 1043 | schema: JSONSchema7 | null | undefined, |
no outgoing calls
no test coverage detected
searching dependent graphs…