| 512 | |
| 513 | /** Resolves component schemas using the same dialect conversion as the OpenAPI generator. */ |
| 514 | const makeResolver = (spec: Schema.Json) => { |
| 515 | const components = |
| 516 | Predicate.isObject(spec) && Predicate.isObject(spec.components) && Predicate.isObject(spec.components.schemas) |
| 517 | ? spec.components.schemas |
| 518 | : {} |
| 519 | const openapi = Predicate.isObject(spec) && Predicate.isString(spec.openapi) ? spec.openapi : "" |
| 520 | const convert = openapi.trim().startsWith("3.0") ? JsonSchema.fromSchemaOpenApi3_0 : JsonSchema.fromSchemaOpenApi3_1 |
| 521 | const cache = new Map<string, JsonSchema.JsonSchema | undefined>() |
| 522 | return (key: string): JsonSchema.JsonSchema | undefined => { |
| 523 | if (!cache.has(key)) { |
| 524 | const definition = Object.hasOwn(components, key) ? components[key] : undefined |
| 525 | cache.set(key, Predicate.isObject(definition) ? convert(definition).schema : undefined) |
| 526 | } |
| 527 | return cache.get(key) |
| 528 | } |
| 529 | } |
| 530 | |
| 531 | /** |
| 532 | * Layer providing the CodeGenerator service. |