MCPcopy Create free account
hub / github.com/vercel/vercel / getBodyFields

Method getBodyFields

packages/cli/src/util/openapi/openapi-cache.ts:160–212  ·  view source on GitHub ↗

* Extract body fields from a requestBody schema. * Throws if spec hasn't been loaded yet.

(endpoint: EndpointInfo)

Source from the content-addressed store, hash-verified

158 * Throws if spec hasn't been loaded yet.
159 */
160 getBodyFields(endpoint: EndpointInfo): BodyField[] {
161 this.ensureLoaded();
162
163 if (!endpoint.requestBody?.content) return [];
164
165 // Get the JSON content schema
166 const jsonContent = endpoint.requestBody.content['application/json'];
167 if (!jsonContent?.schema) return [];
168
169 const schema = this.resolveSchemaRef(jsonContent.schema);
170 if (!schema?.properties) return [];
171
172 const requiredFields = new Set(schema.required || []);
173 const fields: BodyField[] = [];
174
175 for (const [name, propSchema] of Object.entries(schema.properties) as [
176 string,
177 Schema,
178 ][]) {
179 const resolvedProp = this.resolveSchemaRef(propSchema);
180
181 // Get enum values from the schema, handling array items
182 let enumValues = resolvedProp?.enum || propSchema.enum;
183 if (
184 !enumValues &&
185 (resolvedProp?.type === 'array' || propSchema.type === 'array')
186 ) {
187 const items = resolvedProp?.items || propSchema.items;
188 if (items) {
189 const resolvedItems = this.resolveSchemaRef(items);
190 enumValues = resolvedItems?.enum || items.enum;
191 }
192 }
193
194 fields.push({
195 name,
196 required: requiredFields.has(name),
197 description: resolvedProp?.description || propSchema.description,
198 type: resolvedProp?.type || propSchema.type,
199 enumValues,
200 });
201 }
202
203 // Sort by required first, then alphabetically
204 fields.sort((a, b) => {
205 if (a.required !== b.required) {
206 return a.required ? -1 : 1;
207 }
208 return a.name.localeCompare(b.name);
209 });
210
211 return fields;
212 }
213
214 /**
215 * Extract `x-vercel-cli.displayColumns` from the 200 response schema of an

Callers 5

getWebhookEventsFunction · 0.95
spec-url.test.tsFile · 0.80
promptEndpointSelectionFunction · 0.80
runTagOperationFunction · 0.80

Calls 5

ensureLoadedMethod · 0.95
resolveSchemaRefMethod · 0.95
sortMethod · 0.80
pushMethod · 0.65
hasMethod · 0.45

Tested by

no test coverage detected