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

Function expandArrayableSchema

packages/openapi/src/schema-utils.ts:205–228  ·  view source on GitHub ↗
(schema: JSONSchema)

Source from the content-addressed store, hash-verified

203}
204
205export function expandArrayableSchema(schema: JSONSchema): undefined | [items: JSONSchema, array: JSONSchema & { type: 'array', items?: JSONSchema }] {
206 const schemas = expandUnionSchema(schema)
207
208 if (schemas.length !== 2) {
209 return undefined
210 }
211
212 const arraySchema = schemas.find(
213 s => typeof s === 'object' && s.type === 'array' && Object.keys(s).filter(k => LOGIC_KEYWORDS.includes(k)).every(k => k === 'type' || k === 'items'),
214 ) as JSONSchema & { type: 'array', items?: JSONSchema }
215
216 if (arraySchema === undefined) {
217 return undefined
218 }
219
220 const items1 = arraySchema.items
221 const items2 = schemas.find(s => s !== arraySchema) as JSONSchema
222
223 if (stringifyJSON(items1) !== stringifyJSON(items2)) {
224 return undefined
225 }
226
227 return [items2, arraySchema]
228}
229
230const PRIMITIVE_SCHEMA_TYPES = new Set<string>([
231 JSONSchemaTypeName.String,

Callers 2

toOpenAPIParametersFunction · 0.90

Calls 3

stringifyJSONFunction · 0.90
expandUnionSchemaFunction · 0.85
findMethod · 0.45

Tested by

no test coverage detected