File tree Expand file tree Collapse file tree 19 files changed +767
-10
lines changed
templates/base/http-clients
axiosSingleHttpClient/__snapshots__
extractRequestBody/__snapshots__
extractResponseBody/__snapshots__
moduleNameFirstTag/__snapshots__
moduleNameIndex/__snapshots__ Expand file tree Collapse file tree 19 files changed +767
-10
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " swagger-typescript-api " : patch
3
+ ---
4
+
5
+ Fix: PUT requests with application/x-www-form-urlencoded content type
6
+
7
+ This fixes an issue where PUT requests with ` application/x-www-form-urlencoded ` content type were incorrectly sent as ` multipart/form-data ` .
8
+ A new ` createUrlEncoded ` method has been added to the ` HttpClient ` to handle this content type correctly.
Original file line number Diff line number Diff line change @@ -561,7 +561,17 @@ export class SchemaRoutes {
561
561
} ) ;
562
562
}
563
563
564
- if ( routeParams . formData . length ) {
564
+ if (
565
+ contentKind === CONTENT_KIND . URL_ENCODED &&
566
+ routeParams . formData . length
567
+ ) {
568
+ schema = this . convertRouteParamsIntoObject ( routeParams . formData ) ;
569
+ content = this . schemaParserFabric . getInlineParseContent (
570
+ schema ,
571
+ typeName ,
572
+ [ operationId ] ,
573
+ ) ;
574
+ } else if ( routeParams . formData . length ) {
565
575
contentKind = CONTENT_KIND . FORM_DATA ;
566
576
schema = this . convertRouteParamsIntoObject ( routeParams . formData ) ;
567
577
content = this . schemaParserFabric . getInlineParseContent (
Original file line number Diff line number Diff line change @@ -99,6 +99,22 @@ export class HttpClient<SecurityDataType = unknown> {
99
99
}, new FormData());
100
100
}
101
101
102
+ protected createUrlEncoded(input: Record<string , unknown >): URLSearchParams {
103
+ if (input instanceof URLSearchParams) {
104
+ return input;
105
+ }
106
+ return Object.keys(input || {}).reduce((searchParams, key) => {
107
+ const property = input[key];
108
+ const propertyContent: any[] = (property instanceof Array) ? property : [property]
109
+
110
+ for (const formItem of propertyContent) {
111
+ searchParams.append(key, this.stringifyFormItem(formItem));
112
+ }
113
+
114
+ return searchParams;
115
+ }, new URLSearchParams());
116
+ }
117
+
102
118
public request = async <T = any, _E = any >({
103
119
secure,
104
120
path,
@@ -120,6 +136,10 @@ export class HttpClient<SecurityDataType = unknown> {
120
136
body = this.createFormData(body as Record<string , unknown >);
121
137
}
122
138
139
+ if (type === ContentType.UrlEncoded && body && body !== null && typeof body === "object") {
140
+ body = this.createUrlEncoded(body as Record<string , unknown >);
141
+ }
142
+
123
143
if (type === ContentType.Text && body && body !== null && typeof body !== "string") {
124
144
body = JSON.stringify(body);
125
145
}
Original file line number Diff line number Diff line change @@ -6376,7 +6376,7 @@ export class Api<
6376
6376
method: "POST",
6377
6377
body: data,
6378
6378
secure: true,
6379
- type: ContentType.FormData ,
6379
+ type: ContentType.UrlEncoded ,
6380
6380
...params,
6381
6381
}),
6382
6382
@@ -69452,7 +69452,7 @@ export class Api<
69452
69452
method: "POST",
69453
69453
body: data,
69454
69454
secure: true,
69455
- type: ContentType.FormData ,
69455
+ type: ContentType.UrlEncoded ,
69456
69456
...params,
69457
69457
}),
69458
69458
Original file line number Diff line number Diff line change @@ -3968,7 +3968,7 @@ export class Api<
3968
3968
method: "POST",
3969
3969
body: data,
3970
3970
secure: true,
3971
- type: ContentType.FormData ,
3971
+ type: ContentType.UrlEncoded ,
3972
3972
...params,
3973
3973
}),
3974
3974
@@ -43623,7 +43623,7 @@ export class Api<
43623
43623
method: "POST",
43624
43624
body: data,
43625
43625
secure: true,
43626
- type: ContentType.FormData ,
43626
+ type: ContentType.UrlEncoded ,
43627
43627
...params,
43628
43628
}),
43629
43629
Original file line number Diff line number Diff line change @@ -2037,6 +2037,23 @@ export class HttpClient<SecurityDataType = unknown> {
2037
2037
}, new FormData());
2038
2038
}
2039
2039
2040
+ protected createUrlEncoded(input: Record<string, unknown>): URLSearchParams {
2041
+ if (input instanceof URLSearchParams) {
2042
+ return input;
2043
+ }
2044
+ return Object.keys(input || {}).reduce((searchParams, key) => {
2045
+ const property = input[key];
2046
+ const propertyContent: any[] =
2047
+ property instanceof Array ? property : [property];
2048
+
2049
+ for (const formItem of propertyContent) {
2050
+ searchParams.append(key, this.stringifyFormItem(formItem));
2051
+ }
2052
+
2053
+ return searchParams;
2054
+ }, new URLSearchParams());
2055
+ }
2056
+
2040
2057
public request = async <T = any, _E = any>({
2041
2058
secure,
2042
2059
path,
@@ -2063,6 +2080,15 @@ export class HttpClient<SecurityDataType = unknown> {
2063
2080
body = this.createFormData(body as Record<string, unknown>);
2064
2081
}
2065
2082
2083
+ if (
2084
+ type === ContentType.UrlEncoded &&
2085
+ body &&
2086
+ body !== null &&
2087
+ typeof body === "object"
2088
+ ) {
2089
+ body = this.createUrlEncoded(body as Record<string, unknown>);
2090
+ }
2091
+
2066
2092
if (
2067
2093
type === ContentType.Text &&
2068
2094
body &&
Original file line number Diff line number Diff line change @@ -2037,6 +2037,23 @@ export class HttpClient<SecurityDataType = unknown> {
2037
2037
}, new FormData());
2038
2038
}
2039
2039
2040
+ protected createUrlEncoded(input: Record<string, unknown>): URLSearchParams {
2041
+ if (input instanceof URLSearchParams) {
2042
+ return input;
2043
+ }
2044
+ return Object.keys(input || {}).reduce((searchParams, key) => {
2045
+ const property = input[key];
2046
+ const propertyContent: any[] =
2047
+ property instanceof Array ? property : [property];
2048
+
2049
+ for (const formItem of propertyContent) {
2050
+ searchParams.append(key, this.stringifyFormItem(formItem));
2051
+ }
2052
+
2053
+ return searchParams;
2054
+ }, new URLSearchParams());
2055
+ }
2056
+
2040
2057
public request = async <T = any, _E = any>({
2041
2058
secure,
2042
2059
path,
@@ -2063,6 +2080,15 @@ export class HttpClient<SecurityDataType = unknown> {
2063
2080
body = this.createFormData(body as Record<string, unknown>);
2064
2081
}
2065
2082
2083
+ if (
2084
+ type === ContentType.UrlEncoded &&
2085
+ body &&
2086
+ body !== null &&
2087
+ typeof body === "object"
2088
+ ) {
2089
+ body = this.createUrlEncoded(body as Record<string, unknown>);
2090
+ }
2091
+
2066
2092
if (
2067
2093
type === ContentType.Text &&
2068
2094
body &&
Original file line number Diff line number Diff line change @@ -636,7 +636,7 @@ export class Api<
636
636
method: "POST",
637
637
body: data,
638
638
secure: true,
639
- type: ContentType.FormData ,
639
+ type: ContentType.UrlEncoded ,
640
640
...params,
641
641
}),
642
642
Original file line number Diff line number Diff line change @@ -637,7 +637,7 @@ export class Api<
637
637
method: "POST",
638
638
body: data,
639
639
secure: true,
640
- type: ContentType.FormData ,
640
+ type: ContentType.UrlEncoded ,
641
641
...params,
642
642
}),
643
643
Original file line number Diff line number Diff line change @@ -642,7 +642,7 @@ export class Api<
642
642
method: "POST",
643
643
body: data,
644
644
secure: true,
645
- type: ContentType.FormData ,
645
+ type: ContentType.UrlEncoded ,
646
646
...params,
647
647
}),
648
648
You can’t perform that action at this time.
0 commit comments