MCPcopy Create free account
hub / github.com/middleapi/orpc / resolveOpenAPIJsonSchemaRef

Function resolveOpenAPIJsonSchemaRef

packages/openapi/src/openapi-utils.ts:171–179  ·  view source on GitHub ↗
(doc: OpenAPI.Document, schema: JSONSchema)

Source from the content-addressed store, hash-verified

169const OPENAPI_JSON_SCHEMA_REF_PREFIX = /* @__PURE__ */ '#/components/schemas/'
170
171export function resolveOpenAPIJsonSchemaRef(doc: OpenAPI.Document, schema: JSONSchema): JSONSchema {
172 if (typeof schema !== 'object' || !schema.$ref?.startsWith(OPENAPI_JSON_SCHEMA_REF_PREFIX)) {
173 return schema
174 }
175
176 const name = schema.$ref.slice(OPENAPI_JSON_SCHEMA_REF_PREFIX.length)
177 const resolved = doc.components?.schemas?.[name]
178 return resolved as JSONSchema ?? schema
179}
180
181/**
182 * Simplifies composed object JSON Schemas (using anyOf, oneOf, allOf) by flattening nested compositions

Calls

no outgoing calls

Tested by

no test coverage detected