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 #2893 from hey-api/copilot/fix-body-parameter-ignored

authored by

Lubos and committed by
GitHub
e9719170 a3cf6481

+361 -91
+5
.changeset/fluffy-suits-care.md
··· 1 + --- 2 + "@hey-api/openapi-ts": patch 3 + --- 4 + 5 + fix(parser): handle OpenAPI 2.0 body as JSON by default if not explicitly defined
+23 -6
packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/external/types.gen.ts
··· 176 176 export type GetExternalModelResponse = GetExternalModelResponses[keyof GetExternalModelResponses]; 177 177 178 178 export type PostExternalModelData = { 179 - body?: never; 179 + /** 180 + * Request body using external model 181 + */ 182 + body: ExternalSharedExternalSharedModel; 180 183 path?: never; 181 184 query?: never; 182 185 url: '/external-model'; ··· 217 220 export type GetExternalUuidResponse = GetExternalUuidResponses[keyof GetExternalUuidResponses]; 218 221 219 222 export type PutExternalUuidData = { 220 - body?: never; 223 + /** 224 + * Request body using external UUID 225 + */ 226 + body?: ExternalSharedExternalSharedModelWithUuid; 221 227 path?: never; 222 228 query?: never; 223 229 url: '/external-uuid'; ··· 252 258 export type GetExternalNestedResponse = GetExternalNestedResponses[keyof GetExternalNestedResponses]; 253 259 254 260 export type PostExternalNestedData = { 255 - body?: never; 261 + /** 262 + * Request body using external nested object 263 + */ 264 + body?: ExternalSharedExternalNested; 256 265 path?: never; 257 266 query?: never; 258 267 url: '/external-nested'; ··· 292 301 export type GetExternalMixedResponse = GetExternalMixedResponses[keyof GetExternalMixedResponses]; 293 302 294 303 export type PostExternalMixedData = { 295 - body?: never; 304 + /** 305 + * Request body with mixed external properties 306 + */ 307 + body?: { 308 + id?: ExternalSharedId; 309 + name?: ExternalSharedName; 310 + uuid?: ExternalSharedExternalSharedModelWithUuid; 311 + deep?: ExternalSharedDeep; 312 + }; 296 313 path?: never; 297 314 query?: never; 298 315 url: '/external-mixed'; ··· 324 341 export type GetExternalArrayResponse = GetExternalArrayResponses[keyof GetExternalArrayResponses]; 325 342 326 343 export type PostExternalArrayData = { 327 - body?: never; 344 + body: Array<ExternalSharedExternalSharedModel>; 328 345 path?: never; 329 346 query?: never; 330 347 url: '/external-array'; ··· 354 371 }; 355 372 356 373 export type PostExternalUnionData = { 357 - body?: never; 374 + body: unknown; 358 375 path?: never; 359 376 query?: never; 360 377 url: '/external-union';
+5 -1
packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@angular/common/default-class/sdk.gen.ts
··· 105 105 export const callWithWeirdParameterNames = <ThrowOnError extends boolean = false>(options: Options<CallWithWeirdParameterNamesData, ThrowOnError>) => { 106 106 return (options.client ?? client).post<unknown, unknown, ThrowOnError>({ 107 107 url: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}', 108 - ...options 108 + ...options, 109 + headers: { 110 + 'Content-Type': 'application/json', 111 + ...options.headers 112 + } 109 113 }); 110 114 }; 111 115
+4 -1
packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@angular/common/default-class/types.gen.ts
··· 600 600 }; 601 601 602 602 export type CallWithWeirdParameterNamesData = { 603 - body?: never; 603 + /** 604 + * This is the parameter that is sent as request body 605 + */ 606 + body: string; 604 607 headers: { 605 608 /** 606 609 * This is the parameter that goes into the request header
+5 -1
packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@angular/common/default/sdk.gen.ts
··· 105 105 export const callWithWeirdParameterNames = <ThrowOnError extends boolean = false>(options: Options<CallWithWeirdParameterNamesData, ThrowOnError>) => { 106 106 return (options.client ?? client).post<unknown, unknown, ThrowOnError>({ 107 107 url: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}', 108 - ...options 108 + ...options, 109 + headers: { 110 + 'Content-Type': 'application/json', 111 + ...options.headers 112 + } 109 113 }); 110 114 }; 111 115
+4 -1
packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@angular/common/default/types.gen.ts
··· 600 600 }; 601 601 602 602 export type CallWithWeirdParameterNamesData = { 603 - body?: never; 603 + /** 604 + * This is the parameter that is sent as request body 605 + */ 606 + body: string; 604 607 headers: { 605 608 /** 606 609 * This is the parameter that goes into the request header
+5 -1
packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/sdk/default/sdk.gen.ts
··· 105 105 export const callWithWeirdParameterNames = <ThrowOnError extends boolean = false>(options: Options<CallWithWeirdParameterNamesData, ThrowOnError>) => { 106 106 return (options.client ?? client).post<unknown, unknown, ThrowOnError>({ 107 107 url: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}', 108 - ...options 108 + ...options, 109 + headers: { 110 + 'Content-Type': 'application/json', 111 + ...options.headers 112 + } 109 113 }); 110 114 }; 111 115
+4 -1
packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/sdk/default/types.gen.ts
··· 600 600 }; 601 601 602 602 export type CallWithWeirdParameterNamesData = { 603 - body?: never; 603 + /** 604 + * This is the parameter that is sent as request body 605 + */ 606 + body: string; 604 607 headers: { 605 608 /** 606 609 * This is the parameter that goes into the request header
+5 -1
packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/sdk/throwOnError/sdk.gen.ts
··· 105 105 export const callWithWeirdParameterNames = <ThrowOnError extends boolean = true>(options: Options<CallWithWeirdParameterNamesData, ThrowOnError>) => { 106 106 return (options.client ?? client).post<unknown, unknown, ThrowOnError>({ 107 107 url: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}', 108 - ...options 108 + ...options, 109 + headers: { 110 + 'Content-Type': 'application/json', 111 + ...options.headers 112 + } 109 113 }); 110 114 }; 111 115
+4 -1
packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/sdk/throwOnError/types.gen.ts
··· 600 600 }; 601 601 602 602 export type CallWithWeirdParameterNamesData = { 603 - body?: never; 603 + /** 604 + * This is the parameter that is sent as request body 605 + */ 606 + body: string; 604 607 headers: { 605 608 /** 606 609 * This is the parameter that goes into the request header
+5 -1
packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@pinia/colada/fetch/sdk.gen.ts
··· 105 105 export const callWithWeirdParameterNames = <ThrowOnError extends boolean = false>(options: Options<CallWithWeirdParameterNamesData, ThrowOnError>) => { 106 106 return (options.client ?? client).post<unknown, unknown, ThrowOnError>({ 107 107 url: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}', 108 - ...options 108 + ...options, 109 + headers: { 110 + 'Content-Type': 'application/json', 111 + ...options.headers 112 + } 109 113 }); 110 114 }; 111 115
+4 -1
packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@pinia/colada/fetch/types.gen.ts
··· 600 600 }; 601 601 602 602 export type CallWithWeirdParameterNamesData = { 603 - body?: never; 603 + /** 604 + * This is the parameter that is sent as request body 605 + */ 606 + body: string; 604 607 headers: { 605 608 /** 606 609 * This is the parameter that goes into the request header
+5 -1
packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/axios/sdk.gen.ts
··· 105 105 export const callWithWeirdParameterNames = <ThrowOnError extends boolean = false>(options: Options<CallWithWeirdParameterNamesData, ThrowOnError>) => { 106 106 return (options.client ?? client).post<unknown, unknown, ThrowOnError>({ 107 107 url: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}', 108 - ...options 108 + ...options, 109 + headers: { 110 + 'Content-Type': 'application/json', 111 + ...options.headers 112 + } 109 113 }); 110 114 }; 111 115
+4 -1
packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/axios/types.gen.ts
··· 600 600 }; 601 601 602 602 export type CallWithWeirdParameterNamesData = { 603 - body?: never; 603 + /** 604 + * This is the parameter that is sent as request body 605 + */ 606 + body: string; 604 607 headers: { 605 608 /** 606 609 * This is the parameter that goes into the request header
+5 -1
packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/fetch/sdk.gen.ts
··· 105 105 export const callWithWeirdParameterNames = <ThrowOnError extends boolean = false>(options: Options<CallWithWeirdParameterNamesData, ThrowOnError>) => { 106 106 return (options.client ?? client).post<unknown, unknown, ThrowOnError>({ 107 107 url: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}', 108 - ...options 108 + ...options, 109 + headers: { 110 + 'Content-Type': 'application/json', 111 + ...options.headers 112 + } 109 113 }); 110 114 }; 111 115
+4 -1
packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/angular-query-experimental/fetch/types.gen.ts
··· 600 600 }; 601 601 602 602 export type CallWithWeirdParameterNamesData = { 603 - body?: never; 603 + /** 604 + * This is the parameter that is sent as request body 605 + */ 606 + body: string; 604 607 headers: { 605 608 /** 606 609 * This is the parameter that goes into the request header
+5 -1
packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/axios/sdk.gen.ts
··· 105 105 export const callWithWeirdParameterNames = <ThrowOnError extends boolean = false>(options: Options<CallWithWeirdParameterNamesData, ThrowOnError>) => { 106 106 return (options.client ?? client).post<unknown, unknown, ThrowOnError>({ 107 107 url: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}', 108 - ...options 108 + ...options, 109 + headers: { 110 + 'Content-Type': 'application/json', 111 + ...options.headers 112 + } 109 113 }); 110 114 }; 111 115
+4 -1
packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/axios/types.gen.ts
··· 600 600 }; 601 601 602 602 export type CallWithWeirdParameterNamesData = { 603 - body?: never; 603 + /** 604 + * This is the parameter that is sent as request body 605 + */ 606 + body: string; 604 607 headers: { 605 608 /** 606 609 * This is the parameter that goes into the request header
+5 -1
packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/fetch/sdk.gen.ts
··· 105 105 export const callWithWeirdParameterNames = <ThrowOnError extends boolean = false>(options: Options<CallWithWeirdParameterNamesData, ThrowOnError>) => { 106 106 return (options.client ?? client).post<unknown, unknown, ThrowOnError>({ 107 107 url: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}', 108 - ...options 108 + ...options, 109 + headers: { 110 + 'Content-Type': 'application/json', 111 + ...options.headers 112 + } 109 113 }); 110 114 }; 111 115
+4 -1
packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/react-query/fetch/types.gen.ts
··· 600 600 }; 601 601 602 602 export type CallWithWeirdParameterNamesData = { 603 - body?: never; 603 + /** 604 + * This is the parameter that is sent as request body 605 + */ 606 + body: string; 604 607 headers: { 605 608 /** 606 609 * This is the parameter that goes into the request header
+5 -1
packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/axios/sdk.gen.ts
··· 105 105 export const callWithWeirdParameterNames = <ThrowOnError extends boolean = false>(options: Options<CallWithWeirdParameterNamesData, ThrowOnError>) => { 106 106 return (options.client ?? client).post<unknown, unknown, ThrowOnError>({ 107 107 url: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}', 108 - ...options 108 + ...options, 109 + headers: { 110 + 'Content-Type': 'application/json', 111 + ...options.headers 112 + } 109 113 }); 110 114 }; 111 115
+4 -1
packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/axios/types.gen.ts
··· 600 600 }; 601 601 602 602 export type CallWithWeirdParameterNamesData = { 603 - body?: never; 603 + /** 604 + * This is the parameter that is sent as request body 605 + */ 606 + body: string; 604 607 headers: { 605 608 /** 606 609 * This is the parameter that goes into the request header
+5 -1
packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/fetch/sdk.gen.ts
··· 105 105 export const callWithWeirdParameterNames = <ThrowOnError extends boolean = false>(options: Options<CallWithWeirdParameterNamesData, ThrowOnError>) => { 106 106 return (options.client ?? client).post<unknown, unknown, ThrowOnError>({ 107 107 url: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}', 108 - ...options 108 + ...options, 109 + headers: { 110 + 'Content-Type': 'application/json', 111 + ...options.headers 112 + } 109 113 }); 110 114 }; 111 115
+4 -1
packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/solid-query/fetch/types.gen.ts
··· 600 600 }; 601 601 602 602 export type CallWithWeirdParameterNamesData = { 603 - body?: never; 603 + /** 604 + * This is the parameter that is sent as request body 605 + */ 606 + body: string; 604 607 headers: { 605 608 /** 606 609 * This is the parameter that goes into the request header
+5 -1
packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/axios/sdk.gen.ts
··· 105 105 export const callWithWeirdParameterNames = <ThrowOnError extends boolean = false>(options: Options<CallWithWeirdParameterNamesData, ThrowOnError>) => { 106 106 return (options.client ?? client).post<unknown, unknown, ThrowOnError>({ 107 107 url: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}', 108 - ...options 108 + ...options, 109 + headers: { 110 + 'Content-Type': 'application/json', 111 + ...options.headers 112 + } 109 113 }); 110 114 }; 111 115
+4 -1
packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/axios/types.gen.ts
··· 600 600 }; 601 601 602 602 export type CallWithWeirdParameterNamesData = { 603 - body?: never; 603 + /** 604 + * This is the parameter that is sent as request body 605 + */ 606 + body: string; 604 607 headers: { 605 608 /** 606 609 * This is the parameter that goes into the request header
+5 -1
packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/fetch/sdk.gen.ts
··· 105 105 export const callWithWeirdParameterNames = <ThrowOnError extends boolean = false>(options: Options<CallWithWeirdParameterNamesData, ThrowOnError>) => { 106 106 return (options.client ?? client).post<unknown, unknown, ThrowOnError>({ 107 107 url: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}', 108 - ...options 108 + ...options, 109 + headers: { 110 + 'Content-Type': 'application/json', 111 + ...options.headers 112 + } 109 113 }); 110 114 }; 111 115
+4 -1
packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/svelte-query/fetch/types.gen.ts
··· 600 600 }; 601 601 602 602 export type CallWithWeirdParameterNamesData = { 603 - body?: never; 603 + /** 604 + * This is the parameter that is sent as request body 605 + */ 606 + body: string; 604 607 headers: { 605 608 /** 606 609 * This is the parameter that goes into the request header
+5 -1
packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/axios/sdk.gen.ts
··· 105 105 export const callWithWeirdParameterNames = <ThrowOnError extends boolean = false>(options: Options<CallWithWeirdParameterNamesData, ThrowOnError>) => { 106 106 return (options.client ?? client).post<unknown, unknown, ThrowOnError>({ 107 107 url: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}', 108 - ...options 108 + ...options, 109 + headers: { 110 + 'Content-Type': 'application/json', 111 + ...options.headers 112 + } 109 113 }); 110 114 }; 111 115
+4 -1
packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/axios/types.gen.ts
··· 600 600 }; 601 601 602 602 export type CallWithWeirdParameterNamesData = { 603 - body?: never; 603 + /** 604 + * This is the parameter that is sent as request body 605 + */ 606 + body: string; 604 607 headers: { 605 608 /** 606 609 * This is the parameter that goes into the request header
+5 -1
packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/fetch/sdk.gen.ts
··· 105 105 export const callWithWeirdParameterNames = <ThrowOnError extends boolean = false>(options: Options<CallWithWeirdParameterNamesData, ThrowOnError>) => { 106 106 return (options.client ?? client).post<unknown, unknown, ThrowOnError>({ 107 107 url: '/api/v{api-version}/parameters/{parameter.path.1}/{parameter-path-2}/{PARAMETER-PATH-3}', 108 - ...options 108 + ...options, 109 + headers: { 110 + 'Content-Type': 'application/json', 111 + ...options.headers 112 + } 109 113 }); 110 114 }; 111 115
+4 -1
packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@tanstack/vue-query/fetch/types.gen.ts
··· 600 600 }; 601 601 602 602 export type CallWithWeirdParameterNamesData = { 603 - body?: never; 603 + /** 604 + * This is the parameter that is sent as request body 605 + */ 606 + body: string; 604 607 headers: { 605 608 /** 606 609 * This is the parameter that goes into the request header
+1
packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/fastify/default/fastify.gen.ts
··· 14 14 Querystring: CallWithParametersData['query']; 15 15 }>; 16 16 callWithWeirdParameterNames: RouteHandler<{ 17 + Body: CallWithWeirdParameterNamesData['body']; 17 18 Headers: CallWithWeirdParameterNamesData['headers']; 18 19 Params: CallWithWeirdParameterNamesData['path']; 19 20 Querystring: CallWithWeirdParameterNamesData['query'];
+4 -1
packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/fastify/default/types.gen.ts
··· 600 600 }; 601 601 602 602 export type CallWithWeirdParameterNamesData = { 603 - body?: never; 603 + /** 604 + * This is the parameter that is sent as request body 605 + */ 606 + body: string; 604 607 headers: { 605 608 /** 606 609 * This is the parameter that goes into the request header
+1 -1
packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/valibot/default/valibot.gen.ts
··· 533 533 }); 534 534 535 535 export const vCallWithWeirdParameterNamesData = v.object({ 536 - body: v.optional(v.never()), 536 + body: v.string(), 537 537 path: v.object({ 538 538 'parameter.path.1': v.optional(v.string()), 539 539 'parameter-path-2': v.optional(v.string()),
+1 -7
packages/openapi-ts-tests/main/test/__snapshots__/test/generated/v2/sdk.gen.ts.snap
··· 409 409 * @param data.parameterHeader This is the parameter that goes into the header 410 410 * @param data.parameterQuery This is the parameter that goes into the query params 411 411 * @param data.parameterForm This is the parameter that goes into the form data 412 - * @param data.parameterBody This is the parameter that is sent as request body 413 412 * @param data.parameterPath This is the parameter that goes into the path 414 413 * @throws ApiError 415 414 */ ··· 428 427 }, 429 428 formData: { 430 429 parameterForm: data.parameterForm 431 - }, 432 - body: data.parameterBody 430 + } 433 431 }); 434 432 } 435 433 ··· 437 435 * @param data The data for the request. 438 436 * @param data.parameterHeader This is the parameter that goes into the request header 439 437 * @param data.parameterQuery This is the parameter that goes into the request query params 440 - * @param data.parameterForm This is the parameter that goes into the request form data 441 438 * @param data.parameterBody This is the parameter that is sent as request body 442 439 * @param data.parameterPath1 This is the parameter that goes into the path 443 440 * @param data.parameterPath2 This is the parameter that goes into the path ··· 460 457 query: { 461 458 default: data._default, 462 459 'parameter-query': data.parameterQuery 463 - }, 464 - formData: { 465 - parameter_form: data.parameterForm 466 460 }, 467 461 body: data.parameterBody 468 462 });
-8
packages/openapi-ts-tests/main/test/__snapshots__/test/generated/v2/types.gen.ts.snap
··· 679 679 680 680 export type CallWithParametersData = { 681 681 /** 682 - * This is the parameter that is sent as request body 683 - */ 684 - parameterBody: string; 685 - /** 686 682 * This is the parameter that goes into the form data 687 683 */ 688 684 parameterForm: string; ··· 709 705 * This is the parameter that is sent as request body 710 706 */ 711 707 parameterBody: string; 712 - /** 713 - * This is the parameter that goes into the request form data 714 - */ 715 - parameterForm: string; 716 708 /** 717 709 * This is the parameter that goes into the request header 718 710 */
+1 -1
packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/mini/default/zod.gen.ts
··· 548 548 }); 549 549 550 550 export const zCallWithWeirdParameterNamesData = z.object({ 551 - body: z.optional(z.never()), 551 + body: z.string(), 552 552 path: z.object({ 553 553 'parameter.path.1': z.optional(z.string()), 554 554 'parameter-path-2': z.optional(z.string()),
+1 -1
packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/v3/default/zod.gen.ts
··· 546 546 }); 547 547 548 548 export const zCallWithWeirdParameterNamesData = z.object({ 549 - body: z.never().optional(), 549 + body: z.string(), 550 550 path: z.object({ 551 551 'parameter.path.1': z.string().optional(), 552 552 'parameter-path-2': z.string().optional(),
+1 -1
packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/v4/default/zod.gen.ts
··· 548 548 }); 549 549 550 550 export const zCallWithWeirdParameterNamesData = z.object({ 551 - body: z.optional(z.never()), 551 + body: z.string(), 552 552 path: z.object({ 553 553 'parameter.path.1': z.optional(z.string()), 554 554 'parameter-path-2': z.optional(z.string()),
+1 -1
packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/mini/default/zod.gen.ts
··· 548 548 }); 549 549 550 550 export const zCallWithWeirdParameterNamesData = z.object({ 551 - body: z.optional(z.never()), 551 + body: z.string(), 552 552 path: z.object({ 553 553 'parameter.path.1': z.optional(z.string()), 554 554 'parameter-path-2': z.optional(z.string()),
+1 -1
packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/v3/default/zod.gen.ts
··· 546 546 }); 547 547 548 548 export const zCallWithWeirdParameterNamesData = z.object({ 549 - body: z.never().optional(), 549 + body: z.string(), 550 550 path: z.object({ 551 551 'parameter.path.1': z.string().optional(), 552 552 'parameter-path-2': z.string().optional(),
+1 -1
packages/openapi-ts-tests/zod/v4/__snapshots__/2.0.x/v4/default/zod.gen.ts
··· 548 548 }); 549 549 550 550 export const zCallWithWeirdParameterNamesData = z.object({ 551 - body: z.optional(z.never()), 551 + body: z.string(), 552 552 path: z.object({ 553 553 'parameter.path.1': z.optional(z.string()), 554 554 'parameter-path-2': z.optional(z.string()),
+163 -4
packages/openapi-ts/src/openApi/2.0.x/parser/__tests__/operation.test.ts
··· 1 1 import { describe, expect, it } from 'vitest'; 2 2 3 3 import type { IR } from '../../../../ir/types'; 4 - import type { SecuritySchemeObject } from '../../types/spec'; 4 + import type { ParameterObject, SecuritySchemeObject } from '../../types/spec'; 5 5 import { parsePathOperation } from '../operation'; 6 6 7 7 type ParseOperationProps = Parameters<typeof parsePathOperation>[0]; 8 8 9 - describe('operation', () => { 10 - const context = { 9 + const createContext = () => 10 + ({ 11 11 config: { 12 + parser: { 13 + pagination: { 14 + keywords: ['after', 'before', 'cursor', 'offset', 'page', 'start'], 15 + }, 16 + }, 12 17 plugins: {}, 13 18 }, 19 + dereference: <T>(obj: any): T => obj as T, 14 20 ir: { 21 + components: { 22 + schemas: {}, 23 + }, 15 24 paths: {}, 16 25 servers: [], 17 26 }, 18 - } as unknown as IR.Context; 27 + resolveRef: () => 28 + // Mock implementation 29 + undefined, 30 + }) as unknown as IR.Context; 31 + 32 + describe('operation', () => { 33 + const context = createContext(); 19 34 20 35 it('should parse operation correctly', () => { 21 36 const method = 'get'; ··· 89 104 ], 90 105 summary: 'Test Operation', 91 106 }); 107 + }); 108 + 109 + it('should parse body parameter when consumes is undefined', () => { 110 + const context = createContext(); 111 + const method = 'post'; 112 + const bodyParam: ParameterObject = { 113 + description: 'Request body', 114 + in: 'body', 115 + name: 'body', 116 + required: true, 117 + schema: { 118 + properties: { 119 + id: { type: 'string' }, 120 + name: { type: 'string' }, 121 + }, 122 + required: ['id'], 123 + type: 'object', 124 + }, 125 + }; 126 + const operation: ParseOperationProps['operation'] = { 127 + operationId: 'createItem', 128 + requestBody: [bodyParam], 129 + responses: { 130 + '201': { 131 + description: 'Created', 132 + }, 133 + }, 134 + summary: 'Create an item', 135 + }; 136 + const path = '/items'; 137 + const securitySchemesMap = new Map<string, SecuritySchemeObject>(); 138 + const state: ParseOperationProps['state'] = { 139 + ids: new Map<string, string>(), 140 + }; 141 + 142 + parsePathOperation({ 143 + context, 144 + method, 145 + operation, 146 + path, 147 + securitySchemesMap, 148 + state, 149 + }); 150 + 151 + const result = context.ir.paths?.[path]?.[method]; 152 + expect(result).toBeDefined(); 153 + expect(result?.body).toBeDefined(); 154 + expect(result?.body?.mediaType).toBe('application/json'); 155 + expect(result?.body?.required).toBe(true); 156 + expect(result?.body?.schema.type).toBe('object'); 157 + }); 158 + 159 + it('should parse body parameter with array schema', () => { 160 + const context = createContext(); 161 + const method = 'post'; 162 + const bodyParam: ParameterObject = { 163 + description: 'add items', 164 + in: 'body', 165 + name: 'request', 166 + required: true, 167 + schema: { 168 + items: { 169 + properties: { 170 + count: { type: 'number' }, 171 + id: { type: 'integer' }, 172 + }, 173 + type: 'object', 174 + }, 175 + type: 'array', 176 + }, 177 + }; 178 + const operation: ParseOperationProps['operation'] = { 179 + operationId: 'addItems', 180 + requestBody: [bodyParam], 181 + responses: { 182 + '201': { 183 + description: 'Created', 184 + }, 185 + }, 186 + }; 187 + const path = '/api/v1/items'; 188 + const securitySchemesMap = new Map<string, SecuritySchemeObject>(); 189 + const state: ParseOperationProps['state'] = { 190 + ids: new Map<string, string>(), 191 + }; 192 + 193 + parsePathOperation({ 194 + context, 195 + method, 196 + operation, 197 + path, 198 + securitySchemesMap, 199 + state, 200 + }); 201 + 202 + const result = context.ir.paths?.[path]?.[method]; 203 + expect(result).toBeDefined(); 204 + expect(result?.body).toBeDefined(); 205 + expect(result?.body?.mediaType).toBe('application/json'); 206 + expect(result?.body?.required).toBe(true); 207 + expect(result?.body?.schema.type).toBe('array'); 208 + }); 209 + 210 + it('should use consumes when specified', () => { 211 + const context = createContext(); 212 + const method = 'post'; 213 + const bodyParam: ParameterObject = { 214 + description: 'XML body', 215 + in: 'body', 216 + name: 'body', 217 + required: true, 218 + schema: { 219 + type: 'object', 220 + }, 221 + }; 222 + const operation: ParseOperationProps['operation'] = { 223 + consumes: ['application/xml'], 224 + operationId: 'createXml', 225 + requestBody: [bodyParam], 226 + responses: { 227 + '201': { 228 + description: 'Created', 229 + }, 230 + }, 231 + }; 232 + const path = '/items'; 233 + const securitySchemesMap = new Map<string, SecuritySchemeObject>(); 234 + const state: ParseOperationProps['state'] = { 235 + ids: new Map<string, string>(), 236 + }; 237 + 238 + parsePathOperation({ 239 + context, 240 + method, 241 + operation, 242 + path, 243 + securitySchemesMap, 244 + state, 245 + }); 246 + 247 + const result = context.ir.paths?.[path]?.[method]; 248 + expect(result).toBeDefined(); 249 + expect(result?.body).toBeDefined(); 250 + expect(result?.body?.mediaType).toBe('application/xml'); 92 251 }); 93 252 });
+16 -1
packages/openapi-ts/src/openApi/2.0.x/parser/operation.ts
··· 115 115 }; 116 116 const requestBodyObjectRequired: Array<string> = []; 117 117 118 + // Check if there are any body parameters (not formData) to determine default media type 119 + const hasBodyParameter = operation.requestBody?.some((param) => { 120 + const resolvedParam = 121 + '$ref' in param ? context.resolveRef<ParameterObject>(param.$ref) : param; 122 + return resolvedParam.in === 'body'; 123 + }); 124 + 118 125 for (const requestBodyParameter of operation.requestBody ?? []) { 119 126 const requestBody = 120 127 '$ref' in requestBodyParameter ··· 129 136 required: undefined, 130 137 type: requestBody.type === 'file' ? 'string' : requestBody.type, 131 138 }; 139 + 140 + // Only default to JSON if we have body parameters and no consumes specified 141 + // FormData parameters without consumes should not get a default media type 142 + let mimeTypes = operation.consumes; 143 + if (!mimeTypes && hasBodyParameter && requestBody.in === 'body') { 144 + mimeTypes = ['application/json']; 145 + } 146 + 132 147 const contents = mediaTypeObjects({ 133 - mimeTypes: operation.consumes, 148 + mimeTypes, 134 149 response: { schema }, 135 150 }); 136 151 // TODO: add support for multiple content types, for now prefer JSON
+2 -11
specs/2.0.x/full.yaml
··· 113 113 in: formData 114 114 type: string 115 115 required: true 116 - - description: This is the parameter that is sent as request body 117 - name: parameterBody 118 - in: body 119 - type: string 120 - required: true 121 116 - description: This is the parameter that goes into the path 122 117 name: parameterPath 123 118 in: path ··· 164 159 in: query 165 160 type: string 166 161 required: true 167 - - description: This is the parameter that goes into the request form data 168 - name: parameter_form 169 - in: formData 170 - type: string 171 - required: true 172 162 - description: This is the parameter that is sent as request body 173 163 name: PARAMETER-BODY 174 164 in: body 175 - type: string 176 165 required: true 166 + schema: 167 + type: string 177 168 - description: api-version should be required in standalone clients 178 169 name: api-version 179 170 in: path
+4 -16
specs/v2.json
··· 130 130 "required": true 131 131 }, 132 132 { 133 - "description": "This is the parameter that is sent as request body", 134 - "name": "parameterBody", 135 - "in": "body", 136 - "type": "string", 137 - "required": true 138 - }, 139 - { 140 133 "description": "This is the parameter that goes into the path", 141 134 "name": "parameterPath", 142 135 "in": "path", ··· 201 194 "required": true 202 195 }, 203 196 { 204 - "description": "This is the parameter that goes into the request form data", 205 - "name": "parameter_form", 206 - "in": "formData", 207 - "type": "string", 208 - "required": true 209 - }, 210 - { 211 197 "description": "This is the parameter that is sent as request body", 212 198 "name": "PARAMETER-BODY", 213 199 "in": "body", 214 - "type": "string", 215 - "required": true 200 + "required": true, 201 + "schema": { 202 + "type": "string" 203 + } 216 204 }, 217 205 { 218 206 "description": "api-version should be required in standalone clients",