MCPcopy Create free account
hub / github.com/ReAPI-com/mcp-openapi / processSchema

Method processSchema

src/core/SpecProcessor.ts:121–158  ·  view source on GitHub ↗

* Processes a schema object, merging allOf if present * @param schema The schema to process * @returns The processed schema

(schema: SchemaOrRef)

Source from the content-addressed store, hash-verified

119 * @returns The processed schema
120 */
121 private processSchema(schema: SchemaOrRef): SchemaObject {
122 if (!this.isSchemaObject(schema)) {
123 return schema as SchemaObject;
124 }
125
126 // Process nested schemas first
127 if (schema.properties) {
128 for (const [key, prop] of Object.entries(schema.properties)) {
129 schema.properties[key] = this.processSchema(prop as SchemaOrRef);
130 }
131 }
132
133 // Process array items if present
134 if (schema.type === "array" && schema.items) {
135 schema.items = this.processSchema(schema.items as SchemaOrRef);
136 }
137
138 // Handle empty or non-existent allOf
139 if (!schema.allOf || !Array.isArray(schema.allOf)) {
140 return schema;
141 }
142
143 // If allOf is empty, remove it and return the rest of the schema
144 if (schema.allOf.length === 0) {
145 const { allOf, ...rest } = schema;
146 return rest;
147 }
148
149 // Process each schema in allOf array
150 const processedSchemas = schema.allOf.map((s) => this.processSchema(s));
151
152 // Merge the schemas
153 const mergedSchema = this.mergeSchemas(processedSchemas);
154
155 // Remove the allOf property and merge with any other properties from the original schema
156 const { allOf, ...rest } = schema;
157 return this.mergeSchemas([mergedSchema, rest]);
158 }
159
160 /**
161 * Merges multiple schemas into one

Callers 2

mergeAllOfSchemasMethod · 0.95
processPathItemMethod · 0.95

Calls 2

isSchemaObjectMethod · 0.95
mergeSchemasMethod · 0.95

Tested by

no test coverage detected