(ref: string, definitions?: DefinitionCollections)
| 971 | |
| 972 | /** Extract the generated type name from a `$ref` path (e.g. "#/definitions/Model" → "Model"). */ |
| 973 | export function refTypeName(ref: string, definitions?: DefinitionCollections): string { |
| 974 | const baseName = ref.split("/").pop()!; |
| 975 | const match = ref.match(/^#\/(definitions|\$defs)\/(.+)$/); |
| 976 | if (!match || match[1] !== "$defs" || !definitions) return baseName; |
| 977 | |
| 978 | const key = match[2]; |
| 979 | const legacyDefinition = definitions.definitions?.[key]; |
| 980 | const draftDefinition = definitions.$defs?.[key]; |
| 981 | if ( |
| 982 | legacyDefinition !== undefined && |
| 983 | draftDefinition !== undefined && |
| 984 | stableStringify(legacyDefinition) !== stableStringify(draftDefinition) |
| 985 | ) { |
| 986 | return `Draft${baseName}`; |
| 987 | } |
| 988 | |
| 989 | return baseName; |
| 990 | } |
| 991 | |
| 992 | export function parseExternalSchemaRef(ref: string): { schemaFile: string; definitionName: string } | undefined { |
| 993 | const match = ref.match(/^([^#]+)#\/(?:definitions|\$defs)\/(.+)$/); |
no test coverage detected
searching dependent graphs…