fork of hey-api/openapi-ts because I need some additional things
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #746 from hey-api/fix/client-fetch-body

fix: handle formData parameters in generated types

authored by

Lubos and committed by
GitHub
24ed655e 0e14810c

+38 -10
+5
.changeset/brown-carrots-yawn.md
··· 1 + --- 2 + '@hey-api/openapi-ts': patch 3 + --- 4 + 5 + fix: handle formData parameters in generated types
+10 -5
packages/openapi-ts/src/utils/write/types.ts
··· 265 265 } 266 266 267 267 if (operation.parameters.length > 0) { 268 - const bodyParameter = operation.parameters 269 - .filter((parameter) => parameter.in === 'body') 270 - .sort(sorterByName)[0]; 268 + let bodyParameter = operation.parameters.find( 269 + (parameter) => parameter.in === 'body', 270 + ); 271 + if (!bodyParameter) { 272 + bodyParameter = operation.parameters.find( 273 + (parameter) => parameter.in === 'formData', 274 + ); 275 + } 271 276 const bodyParameters: OperationParameter = { 277 + mediaType: null, 272 278 ...emptyModel, 273 279 ...bodyParameter, 274 280 in: 'body', 275 281 isRequired: bodyParameter ? bodyParameter.isRequired : false, 276 - // mediaType: null, 277 282 name: 'body', 278 283 prop: 'body', 279 284 }; ··· 379 384 response.responseTypes.includes('error'), 380 385 ); 381 386 382 - if (isStandaloneClient(config)) { 387 + if (isStandalone) { 383 388 // create type export for operation error 384 389 generateType({ 385 390 client,
+10 -1
packages/openapi-ts/test/__snapshots__/test/generated/v3_hey-api_client-axios/types.gen.ts.snap
··· 1174 1174 }; 1175 1175 1176 1176 export type PostApiFormDataData = { 1177 + /** 1178 + * A reusable request body 1179 + */ 1180 + body?: ModelWithString; 1177 1181 query?: { 1178 1182 /** 1179 1183 * This is a reusable parameter ··· 1414 1418 1415 1419 export type ComplexTypesError = unknown; 1416 1420 1417 - export type MultipartRequestData = unknown; 1421 + export type MultipartRequestData = { 1422 + body?: { 1423 + content?: (Blob | File); 1424 + data?: ModelWithString | null; 1425 + }; 1426 + }; 1418 1427 1419 1428 export type MultipartResponseResponse = { 1420 1429 file?: (Blob | File);
+10 -1
packages/openapi-ts/test/__snapshots__/test/generated/v3_hey-api_client-fetch/types.gen.ts.snap
··· 1174 1174 }; 1175 1175 1176 1176 export type PostApiFormDataData = { 1177 + /** 1178 + * A reusable request body 1179 + */ 1180 + body?: ModelWithString; 1177 1181 query?: { 1178 1182 /** 1179 1183 * This is a reusable parameter ··· 1414 1418 1415 1419 export type ComplexTypesError = unknown; 1416 1420 1417 - export type MultipartRequestData = unknown; 1421 + export type MultipartRequestData = { 1422 + body?: { 1423 + content?: (Blob | File); 1424 + data?: ModelWithString | null; 1425 + }; 1426 + }; 1418 1427 1419 1428 export type MultipartResponseResponse = { 1420 1429 file?: (Blob | File);
+3 -3
packages/openapi-ts/test/sample.cjs
··· 17 17 }, 18 18 services: { 19 19 // asClass: true, 20 - export: false, 20 + // export: false, 21 21 // name: '^Parameters', 22 22 }, 23 23 types: { 24 24 // dates: 'types+transform', 25 25 // enums: 'typescript', 26 - include: 27 - '^(ModelWithOneOfAndProperties|CompositionWithOneOfAndProperties)', 26 + // include: 27 + // '^(ModelWithOneOfAndProperties|CompositionWithOneOfAndProperties)', 28 28 // name: 'PascalCase', 29 29 }, 30 30 // useOptions: false,