Skip to content

Commit 0efc754

Browse files
js2meStynStijnLammens
authored
Release 5.1.6 (Bugfix) (#178)
* also json stringify string input (#177) Co-authored-by: stijn.lammens <[email protected]> * bump: up version to 5.1.6 * chore: refresh generated apis Co-authored-by: Stijn Lammens <[email protected]> Co-authored-by: stijn.lammens <[email protected]>
1 parent 683311a commit 0efc754

Some content is hidden

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

58 files changed

+115
-57
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# next release
22

3+
# 5.1.6
4+
5+
Fixes:
6+
- The contentFormatter for ContentType:Json does not correctly format strings (issue #176, thanks @Styn)
7+
38
# 5.1.5
49

510
Fixes:

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "swagger-typescript-api",
3-
"version": "5.1.5",
3+
"version": "5.1.6",
44
"description": "Create typescript api module from swagger schema",
55
"scripts": {
66
"cli:json": "node index.js -r -d -p ./swagger-test-cli.json -n swagger-test-cli.ts --extract-request-params --enum-names-as-values",

templates/default/http-client.eta

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export class HttpClient<SecurityDataType = unknown> {
105105
}
106106

107107
private contentFormatters: Record<ContentType, (input: any) => any> = {
108-
[ContentType.Json]: (input:any) => input !== null && typeof input === "object" ? JSON.stringify(input) : input,
108+
[ContentType.Json]: (input:any) => input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
109109
[ContentType.FormData]: (input: any) =>
110110
Object.keys(input || {}).reduce((data, key) => {
111111
data.append(key, input[key]);

templates/modular/http-client.eta

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export class HttpClient<SecurityDataType = unknown> {
105105
}
106106

107107
private contentFormatters: Record<ContentType, (input: any) => any> = {
108-
[ContentType.Json]: (input:any) => input !== null && typeof input === "object" ? JSON.stringify(input) : input,
108+
[ContentType.Json]: (input:any) => input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
109109
[ContentType.FormData]: (input: any) =>
110110
Object.keys(input || {}).reduce((data, key) => {
111111
data.append(key, input[key]);

tests/generated/v2.0/adafruit.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,8 @@ export class HttpClient<SecurityDataType = unknown> {
256256
}
257257

258258
private contentFormatters: Record<ContentType, (input: any) => any> = {
259-
[ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input),
259+
[ContentType.Json]: (input: any) =>
260+
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
260261
[ContentType.FormData]: (input: any) =>
261262
Object.keys(input || {}).reduce((data, key) => {
262263
data.append(key, input[key]);

tests/generated/v2.0/another-example.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,8 @@ export class HttpClient<SecurityDataType = unknown> {
232232
}
233233

234234
private contentFormatters: Record<ContentType, (input: any) => any> = {
235-
[ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input),
235+
[ContentType.Json]: (input: any) =>
236+
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
236237
[ContentType.FormData]: (input: any) =>
237238
Object.keys(input || {}).reduce((data, key) => {
238239
data.append(key, input[key]);

tests/generated/v2.0/another-schema.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ export class HttpClient<SecurityDataType = unknown> {
124124
}
125125

126126
private contentFormatters: Record<ContentType, (input: any) => any> = {
127-
[ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input),
127+
[ContentType.Json]: (input: any) =>
128+
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
128129
[ContentType.FormData]: (input: any) =>
129130
Object.keys(input || {}).reduce((data, key) => {
130131
data.append(key, input[key]);

tests/generated/v2.0/api-with-examples.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ export class HttpClient<SecurityDataType = unknown> {
101101
}
102102

103103
private contentFormatters: Record<ContentType, (input: any) => any> = {
104-
[ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input),
104+
[ContentType.Json]: (input: any) =>
105+
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
105106
[ContentType.FormData]: (input: any) =>
106107
Object.keys(input || {}).reduce((data, key) => {
107108
data.append(key, input[key]);

tests/generated/v2.0/authentiq.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ export class HttpClient<SecurityDataType = unknown> {
153153
}
154154

155155
private contentFormatters: Record<ContentType, (input: any) => any> = {
156-
[ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input),
156+
[ContentType.Json]: (input: any) =>
157+
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
157158
[ContentType.FormData]: (input: any) =>
158159
Object.keys(input || {}).reduce((data, key) => {
159160
data.append(key, input[key]);

tests/generated/v2.0/example1.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ export class HttpClient<SecurityDataType = unknown> {
128128
}
129129

130130
private contentFormatters: Record<ContentType, (input: any) => any> = {
131-
[ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input),
131+
[ContentType.Json]: (input: any) =>
132+
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
132133
[ContentType.FormData]: (input: any) =>
133134
Object.keys(input || {}).reduce((data, key) => {
134135
data.append(key, input[key]);

tests/generated/v2.0/file-formdata-example.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ export class HttpClient<SecurityDataType = unknown> {
101101
}
102102

103103
private contentFormatters: Record<ContentType, (input: any) => any> = {
104-
[ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input),
104+
[ContentType.Json]: (input: any) =>
105+
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
105106
[ContentType.FormData]: (input: any) =>
106107
Object.keys(input || {}).reduce((data, key) => {
107108
data.append(key, input[key]);

tests/generated/v2.0/furkot-example.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ export class HttpClient<SecurityDataType = unknown> {
164164
}
165165

166166
private contentFormatters: Record<ContentType, (input: any) => any> = {
167-
[ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input),
167+
[ContentType.Json]: (input: any) =>
168+
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
168169
[ContentType.FormData]: (input: any) =>
169170
Object.keys(input || {}).reduce((data, key) => {
170171
data.append(key, input[key]);

tests/generated/v2.0/giphy.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,8 @@ export class HttpClient<SecurityDataType = unknown> {
383383
}
384384

385385
private contentFormatters: Record<ContentType, (input: any) => any> = {
386-
[ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input),
386+
[ContentType.Json]: (input: any) =>
387+
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
387388
[ContentType.FormData]: (input: any) =>
388389
Object.keys(input || {}).reduce((data, key) => {
389390
data.append(key, input[key]);

tests/generated/v2.0/github-swagger.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1526,7 +1526,8 @@ export class HttpClient<SecurityDataType = unknown> {
15261526
}
15271527

15281528
private contentFormatters: Record<ContentType, (input: any) => any> = {
1529-
[ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input),
1529+
[ContentType.Json]: (input: any) =>
1530+
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
15301531
[ContentType.FormData]: (input: any) =>
15311532
Object.keys(input || {}).reduce((data, key) => {
15321533
data.append(key, input[key]);

tests/generated/v2.0/path-args.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ export class HttpClient<SecurityDataType = unknown> {
101101
}
102102

103103
private contentFormatters: Record<ContentType, (input: any) => any> = {
104-
[ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input),
104+
[ContentType.Json]: (input: any) =>
105+
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
105106
[ContentType.FormData]: (input: any) =>
106107
Object.keys(input || {}).reduce((data, key) => {
107108
data.append(key, input[key]);

tests/generated/v2.0/petstore-expanded.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ export class HttpClient<SecurityDataType = unknown> {
138138
}
139139

140140
private contentFormatters: Record<ContentType, (input: any) => any> = {
141-
[ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input),
141+
[ContentType.Json]: (input: any) =>
142+
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
142143
[ContentType.FormData]: (input: any) =>
143144
Object.keys(input || {}).reduce((data, key) => {
144145
data.append(key, input[key]);

tests/generated/v2.0/petstore-minimal.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ export class HttpClient<SecurityDataType = unknown> {
109109
}
110110

111111
private contentFormatters: Record<ContentType, (input: any) => any> = {
112-
[ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input),
112+
[ContentType.Json]: (input: any) =>
113+
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
113114
[ContentType.FormData]: (input: any) =>
114115
Object.keys(input || {}).reduce((data, key) => {
115116
data.append(key, input[key]);

tests/generated/v2.0/petstore-simple.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ export class HttpClient<SecurityDataType = unknown> {
124124
}
125125

126126
private contentFormatters: Record<ContentType, (input: any) => any> = {
127-
[ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input),
127+
[ContentType.Json]: (input: any) =>
128+
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
128129
[ContentType.FormData]: (input: any) =>
129130
Object.keys(input || {}).reduce((data, key) => {
130131
data.append(key, input[key]);

tests/generated/v2.0/petstore-swagger-io.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ export class HttpClient<SecurityDataType = unknown> {
169169
}
170170

171171
private contentFormatters: Record<ContentType, (input: any) => any> = {
172-
[ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input),
172+
[ContentType.Json]: (input: any) =>
173+
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
173174
[ContentType.FormData]: (input: any) =>
174175
Object.keys(input || {}).reduce((data, key) => {
175176
data.append(key, input[key]);

tests/generated/v2.0/petstore-with-external-docs.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ export class HttpClient<SecurityDataType = unknown> {
114114
}
115115

116116
private contentFormatters: Record<ContentType, (input: any) => any> = {
117-
[ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input),
117+
[ContentType.Json]: (input: any) =>
118+
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
118119
[ContentType.FormData]: (input: any) =>
119120
Object.keys(input || {}).reduce((data, key) => {
120121
data.append(key, input[key]);

tests/generated/v2.0/petstore.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ export class HttpClient<SecurityDataType = unknown> {
116116
}
117117

118118
private contentFormatters: Record<ContentType, (input: any) => any> = {
119-
[ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input),
119+
[ContentType.Json]: (input: any) =>
120+
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
120121
[ContentType.FormData]: (input: any) =>
121122
Object.keys(input || {}).reduce((data, key) => {
122123
data.append(key, input[key]);

tests/generated/v2.0/query-path-param.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ export class HttpClient<SecurityDataType = unknown> {
101101
}
102102

103103
private contentFormatters: Record<ContentType, (input: any) => any> = {
104-
[ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input),
104+
[ContentType.Json]: (input: any) =>
105+
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
105106
[ContentType.FormData]: (input: any) =>
106107
Object.keys(input || {}).reduce((data, key) => {
107108
data.append(key, input[key]);

tests/generated/v2.0/uber.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,8 @@ export class HttpClient<SecurityDataType = unknown> {
196196
}
197197

198198
private contentFormatters: Record<ContentType, (input: any) => any> = {
199-
[ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input),
199+
[ContentType.Json]: (input: any) =>
200+
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
200201
[ContentType.FormData]: (input: any) =>
201202
Object.keys(input || {}).reduce((data, key) => {
202203
data.append(key, input[key]);

tests/generated/v3.0/additional-properties.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ export class HttpClient<SecurityDataType = unknown> {
108108
}
109109

110110
private contentFormatters: Record<ContentType, (input: any) => any> = {
111-
[ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input),
111+
[ContentType.Json]: (input: any) =>
112+
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
112113
[ContentType.FormData]: (input: any) =>
113114
Object.keys(input || {}).reduce((data, key) => {
114115
data.append(key, input[key]);

tests/generated/v3.0/additional-properties2.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ export class HttpClient<SecurityDataType = unknown> {
105105
}
106106

107107
private contentFormatters: Record<ContentType, (input: any) => any> = {
108-
[ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input),
108+
[ContentType.Json]: (input: any) =>
109+
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
109110
[ContentType.FormData]: (input: any) =>
110111
Object.keys(input || {}).reduce((data, key) => {
111112
data.append(key, input[key]);

tests/generated/v3.0/allof-example.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ export class HttpClient<SecurityDataType = unknown> {
109109
}
110110

111111
private contentFormatters: Record<ContentType, (input: any) => any> = {
112-
[ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input),
112+
[ContentType.Json]: (input: any) =>
113+
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
113114
[ContentType.FormData]: (input: any) =>
114115
Object.keys(input || {}).reduce((data, key) => {
115116
data.append(key, input[key]);

tests/generated/v3.0/anyof-example.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ export class HttpClient<SecurityDataType = unknown> {
111111
}
112112

113113
private contentFormatters: Record<ContentType, (input: any) => any> = {
114-
[ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input),
114+
[ContentType.Json]: (input: any) =>
115+
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
115116
[ContentType.FormData]: (input: any) =>
116117
Object.keys(input || {}).reduce((data, key) => {
117118
data.append(key, input[key]);

tests/generated/v3.0/api-with-examples.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ export class HttpClient<SecurityDataType = unknown> {
101101
}
102102

103103
private contentFormatters: Record<ContentType, (input: any) => any> = {
104-
[ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input),
104+
[ContentType.Json]: (input: any) =>
105+
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
105106
[ContentType.FormData]: (input: any) =>
106107
Object.keys(input || {}).reduce((data, key) => {
107108
data.append(key, input[key]);

tests/generated/v3.0/callback-example.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ export class HttpClient<SecurityDataType = unknown> {
101101
}
102102

103103
private contentFormatters: Record<ContentType, (input: any) => any> = {
104-
[ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input),
104+
[ContentType.Json]: (input: any) =>
105+
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
105106
[ContentType.FormData]: (input: any) =>
106107
Object.keys(input || {}).reduce((data, key) => {
107108
data.append(key, input[key]);

tests/generated/v3.0/components-responses.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ export class HttpClient<SecurityDataType = unknown> {
101101
}
102102

103103
private contentFormatters: Record<ContentType, (input: any) => any> = {
104-
[ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input),
104+
[ContentType.Json]: (input: any) =>
105+
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
105106
[ContentType.FormData]: (input: any) =>
106107
Object.keys(input || {}).reduce((data, key) => {
107108
data.append(key, input[key]);

tests/generated/v3.0/explode-param-3.0.1.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ export class HttpClient<SecurityDataType = unknown> {
117117
}
118118

119119
private contentFormatters: Record<ContentType, (input: any) => any> = {
120-
[ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input),
120+
[ContentType.Json]: (input: any) =>
121+
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
121122
[ContentType.FormData]: (input: any) =>
122123
Object.keys(input || {}).reduce((data, key) => {
123124
data.append(key, input[key]);

tests/generated/v3.0/full-swagger-scheme.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9045,7 +9045,8 @@ export class HttpClient<SecurityDataType = unknown> {
90459045
}
90469046

90479047
private contentFormatters: Record<ContentType, (input: any) => any> = {
9048-
[ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input),
9048+
[ContentType.Json]: (input: any) =>
9049+
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
90499050
[ContentType.FormData]: (input: any) =>
90509051
Object.keys(input || {}).reduce((data, key) => {
90519052
data.append(key, input[key]);

tests/generated/v3.0/link-example.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ export class HttpClient<SecurityDataType = unknown> {
118118
}
119119

120120
private contentFormatters: Record<ContentType, (input: any) => any> = {
121-
[ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input),
121+
[ContentType.Json]: (input: any) =>
122+
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
122123
[ContentType.FormData]: (input: any) =>
123124
Object.keys(input || {}).reduce((data, key) => {
124125
data.append(key, input[key]);

tests/generated/v3.0/no-definitions-schema.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ export class HttpClient<SecurityDataType = unknown> {
114114
}
115115

116116
private contentFormatters: Record<ContentType, (input: any) => any> = {
117-
[ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input),
117+
[ContentType.Json]: (input: any) =>
118+
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
118119
[ContentType.FormData]: (input: any) =>
119120
Object.keys(input || {}).reduce((data, key) => {
120121
data.append(key, input[key]);

tests/generated/v3.0/nullable-refs.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ export class HttpClient<SecurityDataType = unknown> {
115115
}
116116

117117
private contentFormatters: Record<ContentType, (input: any) => any> = {
118-
[ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input),
118+
[ContentType.Json]: (input: any) =>
119+
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
119120
[ContentType.FormData]: (input: any) =>
120121
Object.keys(input || {}).reduce((data, key) => {
121122
data.append(key, input[key]);

tests/generated/v3.0/oneof-example.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ export class HttpClient<SecurityDataType = unknown> {
111111
}
112112

113113
private contentFormatters: Record<ContentType, (input: any) => any> = {
114-
[ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input),
114+
[ContentType.Json]: (input: any) =>
115+
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
115116
[ContentType.FormData]: (input: any) =>
116117
Object.keys(input || {}).reduce((data, key) => {
117118
data.append(key, input[key]);

0 commit comments

Comments
 (0)