MCPcopy Create free account
hub / github.com/Effect-TS/effect / makeResolver

Function makeResolver

packages/tools/ai-codegen/src/Generator.ts:514–529  ·  view source on GitHub ↗
(spec: Schema.Json)

Source from the content-addressed store, hash-verified

512
513/** Resolves component schemas using the same dialect conversion as the OpenAPI generator. */
514const 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.

Callers 1

Generator.tsFile · 0.70

Calls 5

trimMethod · 0.80
hasMethod · 0.65
setMethod · 0.65
getMethod · 0.65
convertFunction · 0.50

Tested by

no test coverage detected