Skip to content

Commit e971917

Browse files
authored
Merge pull request #2893 from hey-api/copilot/fix-body-parameter-ignored
2 parents a3cf648 + ef1dedc commit e971917

File tree

47 files changed

+361
-91
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+361
-91
lines changed

.changeset/fluffy-suits-care.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
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

packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/external/types.gen.ts

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,10 @@ export type GetExternalModelResponses = {
176176
export type GetExternalModelResponse = GetExternalModelResponses[keyof GetExternalModelResponses];
177177

178178
export type PostExternalModelData = {
179-
body?: never;
179+
/**
180+
* Request body using external model
181+
*/
182+
body: ExternalSharedExternalSharedModel;
180183
path?: never;
181184
query?: never;
182185
url: '/external-model';
@@ -217,7 +220,10 @@ export type GetExternalUuidResponses = {
217220
export type GetExternalUuidResponse = GetExternalUuidResponses[keyof GetExternalUuidResponses];
218221

219222
export type PutExternalUuidData = {
220-
body?: never;
223+
/**
224+
* Request body using external UUID
225+
*/
226+
body?: ExternalSharedExternalSharedModelWithUuid;
221227
path?: never;
222228
query?: never;
223229
url: '/external-uuid';
@@ -252,7 +258,10 @@ export type GetExternalNestedResponses = {
252258
export type GetExternalNestedResponse = GetExternalNestedResponses[keyof GetExternalNestedResponses];
253259

254260
export type PostExternalNestedData = {
255-
body?: never;
261+
/**
262+
* Request body using external nested object
263+
*/
264+
body?: ExternalSharedExternalNested;
256265
path?: never;
257266
query?: never;
258267
url: '/external-nested';
@@ -292,7 +301,15 @@ export type GetExternalMixedResponses = {
292301
export type GetExternalMixedResponse = GetExternalMixedResponses[keyof GetExternalMixedResponses];
293302

294303
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+
};
296313
path?: never;
297314
query?: never;
298315
url: '/external-mixed';
@@ -324,7 +341,7 @@ export type GetExternalArrayResponses = {
324341
export type GetExternalArrayResponse = GetExternalArrayResponses[keyof GetExternalArrayResponses];
325342

326343
export type PostExternalArrayData = {
327-
body?: never;
344+
body: Array<ExternalSharedExternalSharedModel>;
328345
path?: never;
329346
query?: never;
330347
url: '/external-array';
@@ -354,7 +371,7 @@ export type GetExternalUnionResponses = {
354371
};
355372

356373
export type PostExternalUnionData = {
357-
body?: never;
374+
body: unknown;
358375
path?: never;
359376
query?: never;
360377
url: '/external-union';

packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@angular/common/default-class/sdk.gen.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,11 @@ export const callWithParameters = <ThrowOnError extends boolean = false>(options
105105
export const callWithWeirdParameterNames = <ThrowOnError extends boolean = false>(options: Options<CallWithWeirdParameterNamesData, ThrowOnError>) => {
106106
return (options.client ?? client).post<unknown, unknown, ThrowOnError>({
107107
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+
}
109113
});
110114
};
111115

packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@angular/common/default-class/types.gen.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,10 @@ export type CallWithParametersData = {
600600
};
601601

602602
export type CallWithWeirdParameterNamesData = {
603-
body?: never;
603+
/**
604+
* This is the parameter that is sent as request body
605+
*/
606+
body: string;
604607
headers: {
605608
/**
606609
* This is the parameter that goes into the request header

packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@angular/common/default/sdk.gen.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,11 @@ export const callWithParameters = <ThrowOnError extends boolean = false>(options
105105
export const callWithWeirdParameterNames = <ThrowOnError extends boolean = false>(options: Options<CallWithWeirdParameterNamesData, ThrowOnError>) => {
106106
return (options.client ?? client).post<unknown, unknown, ThrowOnError>({
107107
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+
}
109113
});
110114
};
111115

packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@angular/common/default/types.gen.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,10 @@ export type CallWithParametersData = {
600600
};
601601

602602
export type CallWithWeirdParameterNamesData = {
603-
body?: never;
603+
/**
604+
* This is the parameter that is sent as request body
605+
*/
606+
body: string;
604607
headers: {
605608
/**
606609
* This is the parameter that goes into the request header

packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/sdk/default/sdk.gen.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,11 @@ export const callWithParameters = <ThrowOnError extends boolean = false>(options
105105
export const callWithWeirdParameterNames = <ThrowOnError extends boolean = false>(options: Options<CallWithWeirdParameterNamesData, ThrowOnError>) => {
106106
return (options.client ?? client).post<unknown, unknown, ThrowOnError>({
107107
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+
}
109113
});
110114
};
111115

packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/sdk/default/types.gen.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,10 @@ export type CallWithParametersData = {
600600
};
601601

602602
export type CallWithWeirdParameterNamesData = {
603-
body?: never;
603+
/**
604+
* This is the parameter that is sent as request body
605+
*/
606+
body: string;
604607
headers: {
605608
/**
606609
* This is the parameter that goes into the request header

packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/sdk/throwOnError/sdk.gen.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,11 @@ export const callWithParameters = <ThrowOnError extends boolean = true>(options:
105105
export const callWithWeirdParameterNames = <ThrowOnError extends boolean = true>(options: Options<CallWithWeirdParameterNamesData, ThrowOnError>) => {
106106
return (options.client ?? client).post<unknown, unknown, ThrowOnError>({
107107
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+
}
109113
});
110114
};
111115

packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/sdk/throwOnError/types.gen.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,10 @@ export type CallWithParametersData = {
600600
};
601601

602602
export type CallWithWeirdParameterNamesData = {
603-
body?: never;
603+
/**
604+
* This is the parameter that is sent as request body
605+
*/
606+
body: string;
604607
headers: {
605608
/**
606609
* This is the parameter that goes into the request header

0 commit comments

Comments
 (0)