* Extract body fields from a requestBody schema. * Throws if spec hasn't been loaded yet.
(endpoint: EndpointInfo)
| 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 |
no test coverage detected