diff --git a/CHANGELOG.md b/CHANGELOG.md index 040a97cbd..665621bf9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # next release +# 5.1.6 + +Fixes: +- The contentFormatter for ContentType:Json does not correctly format strings (issue #176, thanks @Styn) + # 5.1.5 Fixes: diff --git a/package-lock.json b/package-lock.json index 7883f970a..f3e7b1608 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "swagger-typescript-api", - "version": "5.1.5", + "version": "5.1.6", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index b08d7d4e3..3b13c6d85 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "swagger-typescript-api", - "version": "5.1.5", + "version": "5.1.6", "description": "Create typescript api module from swagger schema", "scripts": { "cli:json": "node index.js -r -d -p ./swagger-test-cli.json -n swagger-test-cli.ts --extract-request-params --enum-names-as-values", diff --git a/templates/default/http-client.eta b/templates/default/http-client.eta index 62b313d66..71b5b0f10 100644 --- a/templates/default/http-client.eta +++ b/templates/default/http-client.eta @@ -105,7 +105,7 @@ export class HttpClient { } private contentFormatters: Record any> = { - [ContentType.Json]: (input:any) => input !== null && typeof input === "object" ? JSON.stringify(input) : input, + [ContentType.Json]: (input:any) => input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input, [ContentType.FormData]: (input: any) => Object.keys(input || {}).reduce((data, key) => { data.append(key, input[key]); diff --git a/templates/modular/http-client.eta b/templates/modular/http-client.eta index 3d2a644ce..ae92e1cb3 100644 --- a/templates/modular/http-client.eta +++ b/templates/modular/http-client.eta @@ -105,7 +105,7 @@ export class HttpClient { } private contentFormatters: Record any> = { - [ContentType.Json]: (input:any) => input !== null && typeof input === "object" ? JSON.stringify(input) : input, + [ContentType.Json]: (input:any) => input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input, [ContentType.FormData]: (input: any) => Object.keys(input || {}).reduce((data, key) => { data.append(key, input[key]); diff --git a/tests/generated/v2.0/adafruit.ts b/tests/generated/v2.0/adafruit.ts index 95a3bcd6d..9ba7ce8e1 100644 --- a/tests/generated/v2.0/adafruit.ts +++ b/tests/generated/v2.0/adafruit.ts @@ -256,7 +256,8 @@ export class HttpClient { } private contentFormatters: Record any> = { - [ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input), + [ContentType.Json]: (input: any) => + input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input, [ContentType.FormData]: (input: any) => Object.keys(input || {}).reduce((data, key) => { data.append(key, input[key]); diff --git a/tests/generated/v2.0/another-example.ts b/tests/generated/v2.0/another-example.ts index 1f24f5808..3180bd429 100644 --- a/tests/generated/v2.0/another-example.ts +++ b/tests/generated/v2.0/another-example.ts @@ -232,7 +232,8 @@ export class HttpClient { } private contentFormatters: Record any> = { - [ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input), + [ContentType.Json]: (input: any) => + input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input, [ContentType.FormData]: (input: any) => Object.keys(input || {}).reduce((data, key) => { data.append(key, input[key]); diff --git a/tests/generated/v2.0/another-schema.ts b/tests/generated/v2.0/another-schema.ts index cff355718..ae5e04fde 100644 --- a/tests/generated/v2.0/another-schema.ts +++ b/tests/generated/v2.0/another-schema.ts @@ -124,7 +124,8 @@ export class HttpClient { } private contentFormatters: Record any> = { - [ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input), + [ContentType.Json]: (input: any) => + input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input, [ContentType.FormData]: (input: any) => Object.keys(input || {}).reduce((data, key) => { data.append(key, input[key]); diff --git a/tests/generated/v2.0/api-with-examples.ts b/tests/generated/v2.0/api-with-examples.ts index 3c6a9178d..1b2df2934 100644 --- a/tests/generated/v2.0/api-with-examples.ts +++ b/tests/generated/v2.0/api-with-examples.ts @@ -101,7 +101,8 @@ export class HttpClient { } private contentFormatters: Record any> = { - [ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input), + [ContentType.Json]: (input: any) => + input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input, [ContentType.FormData]: (input: any) => Object.keys(input || {}).reduce((data, key) => { data.append(key, input[key]); diff --git a/tests/generated/v2.0/authentiq.ts b/tests/generated/v2.0/authentiq.ts index b367d057c..478784815 100644 --- a/tests/generated/v2.0/authentiq.ts +++ b/tests/generated/v2.0/authentiq.ts @@ -153,7 +153,8 @@ export class HttpClient { } private contentFormatters: Record any> = { - [ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input), + [ContentType.Json]: (input: any) => + input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input, [ContentType.FormData]: (input: any) => Object.keys(input || {}).reduce((data, key) => { data.append(key, input[key]); diff --git a/tests/generated/v2.0/example1.ts b/tests/generated/v2.0/example1.ts index f97ff857f..065e1dc88 100644 --- a/tests/generated/v2.0/example1.ts +++ b/tests/generated/v2.0/example1.ts @@ -128,7 +128,8 @@ export class HttpClient { } private contentFormatters: Record any> = { - [ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input), + [ContentType.Json]: (input: any) => + input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input, [ContentType.FormData]: (input: any) => Object.keys(input || {}).reduce((data, key) => { data.append(key, input[key]); diff --git a/tests/generated/v2.0/file-formdata-example.ts b/tests/generated/v2.0/file-formdata-example.ts index 23f219cd4..5247c1319 100644 --- a/tests/generated/v2.0/file-formdata-example.ts +++ b/tests/generated/v2.0/file-formdata-example.ts @@ -101,7 +101,8 @@ export class HttpClient { } private contentFormatters: Record any> = { - [ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input), + [ContentType.Json]: (input: any) => + input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input, [ContentType.FormData]: (input: any) => Object.keys(input || {}).reduce((data, key) => { data.append(key, input[key]); diff --git a/tests/generated/v2.0/furkot-example.ts b/tests/generated/v2.0/furkot-example.ts index 91647915c..b276d514d 100644 --- a/tests/generated/v2.0/furkot-example.ts +++ b/tests/generated/v2.0/furkot-example.ts @@ -164,7 +164,8 @@ export class HttpClient { } private contentFormatters: Record any> = { - [ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input), + [ContentType.Json]: (input: any) => + input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input, [ContentType.FormData]: (input: any) => Object.keys(input || {}).reduce((data, key) => { data.append(key, input[key]); diff --git a/tests/generated/v2.0/giphy.ts b/tests/generated/v2.0/giphy.ts index 27463ecff..d7f93da2e 100644 --- a/tests/generated/v2.0/giphy.ts +++ b/tests/generated/v2.0/giphy.ts @@ -383,7 +383,8 @@ export class HttpClient { } private contentFormatters: Record any> = { - [ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input), + [ContentType.Json]: (input: any) => + input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input, [ContentType.FormData]: (input: any) => Object.keys(input || {}).reduce((data, key) => { data.append(key, input[key]); diff --git a/tests/generated/v2.0/github-swagger.ts b/tests/generated/v2.0/github-swagger.ts index f0e13caf0..2eaafba4c 100644 --- a/tests/generated/v2.0/github-swagger.ts +++ b/tests/generated/v2.0/github-swagger.ts @@ -1526,7 +1526,8 @@ export class HttpClient { } private contentFormatters: Record any> = { - [ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input), + [ContentType.Json]: (input: any) => + input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input, [ContentType.FormData]: (input: any) => Object.keys(input || {}).reduce((data, key) => { data.append(key, input[key]); diff --git a/tests/generated/v2.0/path-args.ts b/tests/generated/v2.0/path-args.ts index c59697c47..3feeb8eaa 100644 --- a/tests/generated/v2.0/path-args.ts +++ b/tests/generated/v2.0/path-args.ts @@ -101,7 +101,8 @@ export class HttpClient { } private contentFormatters: Record any> = { - [ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input), + [ContentType.Json]: (input: any) => + input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input, [ContentType.FormData]: (input: any) => Object.keys(input || {}).reduce((data, key) => { data.append(key, input[key]); diff --git a/tests/generated/v2.0/petstore-expanded.ts b/tests/generated/v2.0/petstore-expanded.ts index ec19955a7..042eaf517 100644 --- a/tests/generated/v2.0/petstore-expanded.ts +++ b/tests/generated/v2.0/petstore-expanded.ts @@ -138,7 +138,8 @@ export class HttpClient { } private contentFormatters: Record any> = { - [ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input), + [ContentType.Json]: (input: any) => + input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input, [ContentType.FormData]: (input: any) => Object.keys(input || {}).reduce((data, key) => { data.append(key, input[key]); diff --git a/tests/generated/v2.0/petstore-minimal.ts b/tests/generated/v2.0/petstore-minimal.ts index 861e6d29c..1285988fa 100644 --- a/tests/generated/v2.0/petstore-minimal.ts +++ b/tests/generated/v2.0/petstore-minimal.ts @@ -109,7 +109,8 @@ export class HttpClient { } private contentFormatters: Record any> = { - [ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input), + [ContentType.Json]: (input: any) => + input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input, [ContentType.FormData]: (input: any) => Object.keys(input || {}).reduce((data, key) => { data.append(key, input[key]); diff --git a/tests/generated/v2.0/petstore-simple.ts b/tests/generated/v2.0/petstore-simple.ts index 7bd003917..3d7fe8c06 100644 --- a/tests/generated/v2.0/petstore-simple.ts +++ b/tests/generated/v2.0/petstore-simple.ts @@ -124,7 +124,8 @@ export class HttpClient { } private contentFormatters: Record any> = { - [ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input), + [ContentType.Json]: (input: any) => + input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input, [ContentType.FormData]: (input: any) => Object.keys(input || {}).reduce((data, key) => { data.append(key, input[key]); diff --git a/tests/generated/v2.0/petstore-swagger-io.ts b/tests/generated/v2.0/petstore-swagger-io.ts index 01cc18510..34f6e3cf3 100644 --- a/tests/generated/v2.0/petstore-swagger-io.ts +++ b/tests/generated/v2.0/petstore-swagger-io.ts @@ -169,7 +169,8 @@ export class HttpClient { } private contentFormatters: Record any> = { - [ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input), + [ContentType.Json]: (input: any) => + input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input, [ContentType.FormData]: (input: any) => Object.keys(input || {}).reduce((data, key) => { data.append(key, input[key]); diff --git a/tests/generated/v2.0/petstore-with-external-docs.ts b/tests/generated/v2.0/petstore-with-external-docs.ts index a2d9af2c2..ba06b108e 100644 --- a/tests/generated/v2.0/petstore-with-external-docs.ts +++ b/tests/generated/v2.0/petstore-with-external-docs.ts @@ -114,7 +114,8 @@ export class HttpClient { } private contentFormatters: Record any> = { - [ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input), + [ContentType.Json]: (input: any) => + input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input, [ContentType.FormData]: (input: any) => Object.keys(input || {}).reduce((data, key) => { data.append(key, input[key]); diff --git a/tests/generated/v2.0/petstore.ts b/tests/generated/v2.0/petstore.ts index 448c6d1f4..256dd9f52 100644 --- a/tests/generated/v2.0/petstore.ts +++ b/tests/generated/v2.0/petstore.ts @@ -116,7 +116,8 @@ export class HttpClient { } private contentFormatters: Record any> = { - [ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input), + [ContentType.Json]: (input: any) => + input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input, [ContentType.FormData]: (input: any) => Object.keys(input || {}).reduce((data, key) => { data.append(key, input[key]); diff --git a/tests/generated/v2.0/query-path-param.ts b/tests/generated/v2.0/query-path-param.ts index 09ddfe3e8..3baab13b8 100644 --- a/tests/generated/v2.0/query-path-param.ts +++ b/tests/generated/v2.0/query-path-param.ts @@ -101,7 +101,8 @@ export class HttpClient { } private contentFormatters: Record any> = { - [ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input), + [ContentType.Json]: (input: any) => + input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input, [ContentType.FormData]: (input: any) => Object.keys(input || {}).reduce((data, key) => { data.append(key, input[key]); diff --git a/tests/generated/v2.0/uber.ts b/tests/generated/v2.0/uber.ts index c62eaa9ea..39023be28 100644 --- a/tests/generated/v2.0/uber.ts +++ b/tests/generated/v2.0/uber.ts @@ -196,7 +196,8 @@ export class HttpClient { } private contentFormatters: Record any> = { - [ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input), + [ContentType.Json]: (input: any) => + input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input, [ContentType.FormData]: (input: any) => Object.keys(input || {}).reduce((data, key) => { data.append(key, input[key]); diff --git a/tests/generated/v3.0/additional-properties.ts b/tests/generated/v3.0/additional-properties.ts index ad8140b38..2735c7387 100644 --- a/tests/generated/v3.0/additional-properties.ts +++ b/tests/generated/v3.0/additional-properties.ts @@ -108,7 +108,8 @@ export class HttpClient { } private contentFormatters: Record any> = { - [ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input), + [ContentType.Json]: (input: any) => + input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input, [ContentType.FormData]: (input: any) => Object.keys(input || {}).reduce((data, key) => { data.append(key, input[key]); diff --git a/tests/generated/v3.0/additional-properties2.ts b/tests/generated/v3.0/additional-properties2.ts index 321f98005..d83146b99 100644 --- a/tests/generated/v3.0/additional-properties2.ts +++ b/tests/generated/v3.0/additional-properties2.ts @@ -105,7 +105,8 @@ export class HttpClient { } private contentFormatters: Record any> = { - [ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input), + [ContentType.Json]: (input: any) => + input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input, [ContentType.FormData]: (input: any) => Object.keys(input || {}).reduce((data, key) => { data.append(key, input[key]); diff --git a/tests/generated/v3.0/allof-example.ts b/tests/generated/v3.0/allof-example.ts index e74af7b74..0eb1d07fd 100644 --- a/tests/generated/v3.0/allof-example.ts +++ b/tests/generated/v3.0/allof-example.ts @@ -109,7 +109,8 @@ export class HttpClient { } private contentFormatters: Record any> = { - [ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input), + [ContentType.Json]: (input: any) => + input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input, [ContentType.FormData]: (input: any) => Object.keys(input || {}).reduce((data, key) => { data.append(key, input[key]); diff --git a/tests/generated/v3.0/anyof-example.ts b/tests/generated/v3.0/anyof-example.ts index 240c7f9f2..47b46ab57 100644 --- a/tests/generated/v3.0/anyof-example.ts +++ b/tests/generated/v3.0/anyof-example.ts @@ -111,7 +111,8 @@ export class HttpClient { } private contentFormatters: Record any> = { - [ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input), + [ContentType.Json]: (input: any) => + input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input, [ContentType.FormData]: (input: any) => Object.keys(input || {}).reduce((data, key) => { data.append(key, input[key]); diff --git a/tests/generated/v3.0/api-with-examples.ts b/tests/generated/v3.0/api-with-examples.ts index 9a4b5ffa0..4a90fe903 100644 --- a/tests/generated/v3.0/api-with-examples.ts +++ b/tests/generated/v3.0/api-with-examples.ts @@ -101,7 +101,8 @@ export class HttpClient { } private contentFormatters: Record any> = { - [ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input), + [ContentType.Json]: (input: any) => + input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input, [ContentType.FormData]: (input: any) => Object.keys(input || {}).reduce((data, key) => { data.append(key, input[key]); diff --git a/tests/generated/v3.0/callback-example.ts b/tests/generated/v3.0/callback-example.ts index 783461330..ff2a0b99d 100644 --- a/tests/generated/v3.0/callback-example.ts +++ b/tests/generated/v3.0/callback-example.ts @@ -101,7 +101,8 @@ export class HttpClient { } private contentFormatters: Record any> = { - [ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input), + [ContentType.Json]: (input: any) => + input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input, [ContentType.FormData]: (input: any) => Object.keys(input || {}).reduce((data, key) => { data.append(key, input[key]); diff --git a/tests/generated/v3.0/components-responses.ts b/tests/generated/v3.0/components-responses.ts index 7b3f176ca..bf0340f8c 100644 --- a/tests/generated/v3.0/components-responses.ts +++ b/tests/generated/v3.0/components-responses.ts @@ -101,7 +101,8 @@ export class HttpClient { } private contentFormatters: Record any> = { - [ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input), + [ContentType.Json]: (input: any) => + input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input, [ContentType.FormData]: (input: any) => Object.keys(input || {}).reduce((data, key) => { data.append(key, input[key]); diff --git a/tests/generated/v3.0/explode-param-3.0.1.ts b/tests/generated/v3.0/explode-param-3.0.1.ts index e24b5dd1a..4501ea63d 100644 --- a/tests/generated/v3.0/explode-param-3.0.1.ts +++ b/tests/generated/v3.0/explode-param-3.0.1.ts @@ -117,7 +117,8 @@ export class HttpClient { } private contentFormatters: Record any> = { - [ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input), + [ContentType.Json]: (input: any) => + input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input, [ContentType.FormData]: (input: any) => Object.keys(input || {}).reduce((data, key) => { data.append(key, input[key]); diff --git a/tests/generated/v3.0/full-swagger-scheme.ts b/tests/generated/v3.0/full-swagger-scheme.ts index cbca83058..cc9a089d3 100644 --- a/tests/generated/v3.0/full-swagger-scheme.ts +++ b/tests/generated/v3.0/full-swagger-scheme.ts @@ -9045,7 +9045,8 @@ export class HttpClient { } private contentFormatters: Record any> = { - [ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input), + [ContentType.Json]: (input: any) => + input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input, [ContentType.FormData]: (input: any) => Object.keys(input || {}).reduce((data, key) => { data.append(key, input[key]); diff --git a/tests/generated/v3.0/link-example.ts b/tests/generated/v3.0/link-example.ts index dcf1384a5..5ead52b4b 100644 --- a/tests/generated/v3.0/link-example.ts +++ b/tests/generated/v3.0/link-example.ts @@ -118,7 +118,8 @@ export class HttpClient { } private contentFormatters: Record any> = { - [ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input), + [ContentType.Json]: (input: any) => + input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input, [ContentType.FormData]: (input: any) => Object.keys(input || {}).reduce((data, key) => { data.append(key, input[key]); diff --git a/tests/generated/v3.0/no-definitions-schema.ts b/tests/generated/v3.0/no-definitions-schema.ts index e0514067e..0a1f1f4ef 100644 --- a/tests/generated/v3.0/no-definitions-schema.ts +++ b/tests/generated/v3.0/no-definitions-schema.ts @@ -114,7 +114,8 @@ export class HttpClient { } private contentFormatters: Record any> = { - [ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input), + [ContentType.Json]: (input: any) => + input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input, [ContentType.FormData]: (input: any) => Object.keys(input || {}).reduce((data, key) => { data.append(key, input[key]); diff --git a/tests/generated/v3.0/nullable-refs.ts b/tests/generated/v3.0/nullable-refs.ts index 41f49d315..54b0f899f 100644 --- a/tests/generated/v3.0/nullable-refs.ts +++ b/tests/generated/v3.0/nullable-refs.ts @@ -115,7 +115,8 @@ export class HttpClient { } private contentFormatters: Record any> = { - [ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input), + [ContentType.Json]: (input: any) => + input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input, [ContentType.FormData]: (input: any) => Object.keys(input || {}).reduce((data, key) => { data.append(key, input[key]); diff --git a/tests/generated/v3.0/oneof-example.ts b/tests/generated/v3.0/oneof-example.ts index cbc13a6f7..3a6592f66 100644 --- a/tests/generated/v3.0/oneof-example.ts +++ b/tests/generated/v3.0/oneof-example.ts @@ -111,7 +111,8 @@ export class HttpClient { } private contentFormatters: Record any> = { - [ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input), + [ContentType.Json]: (input: any) => + input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input, [ContentType.FormData]: (input: any) => Object.keys(input || {}).reduce((data, key) => { data.append(key, input[key]); diff --git a/tests/generated/v3.0/personal-api-example.ts b/tests/generated/v3.0/personal-api-example.ts index 23a12d361..1f4123586 100644 --- a/tests/generated/v3.0/personal-api-example.ts +++ b/tests/generated/v3.0/personal-api-example.ts @@ -302,7 +302,8 @@ export class HttpClient { } private contentFormatters: Record any> = { - [ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input), + [ContentType.Json]: (input: any) => + input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input, [ContentType.FormData]: (input: any) => Object.keys(input || {}).reduce((data, key) => { data.append(key, input[key]); diff --git a/tests/generated/v3.0/petstore-expanded.ts b/tests/generated/v3.0/petstore-expanded.ts index 14e85e113..0208d69ff 100644 --- a/tests/generated/v3.0/petstore-expanded.ts +++ b/tests/generated/v3.0/petstore-expanded.ts @@ -114,7 +114,8 @@ export class HttpClient { } private contentFormatters: Record any> = { - [ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input), + [ContentType.Json]: (input: any) => + input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input, [ContentType.FormData]: (input: any) => Object.keys(input || {}).reduce((data, key) => { data.append(key, input[key]); diff --git a/tests/generated/v3.0/petstore.ts b/tests/generated/v3.0/petstore.ts index 6da484cb7..777c14b86 100644 --- a/tests/generated/v3.0/petstore.ts +++ b/tests/generated/v3.0/petstore.ts @@ -118,7 +118,8 @@ export class HttpClient { } private contentFormatters: Record any> = { - [ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input), + [ContentType.Json]: (input: any) => + input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input, [ContentType.FormData]: (input: any) => Object.keys(input || {}).reduce((data, key) => { data.append(key, input[key]); diff --git a/tests/generated/v3.0/recursive-schema.ts b/tests/generated/v3.0/recursive-schema.ts index 2a74589da..425839024 100644 --- a/tests/generated/v3.0/recursive-schema.ts +++ b/tests/generated/v3.0/recursive-schema.ts @@ -115,7 +115,8 @@ export class HttpClient { } private contentFormatters: Record any> = { - [ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input), + [ContentType.Json]: (input: any) => + input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input, [ContentType.FormData]: (input: any) => Object.keys(input || {}).reduce((data, key) => { data.append(key, input[key]); diff --git a/tests/generated/v3.0/responses.ts b/tests/generated/v3.0/responses.ts index fdfc59073..c2e43a9b0 100644 --- a/tests/generated/v3.0/responses.ts +++ b/tests/generated/v3.0/responses.ts @@ -101,7 +101,8 @@ export class HttpClient { } private contentFormatters: Record any> = { - [ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input), + [ContentType.Json]: (input: any) => + input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input, [ContentType.FormData]: (input: any) => Object.keys(input || {}).reduce((data, key) => { data.append(key, input[key]); diff --git a/tests/generated/v3.0/swaggerhub-template.ts b/tests/generated/v3.0/swaggerhub-template.ts index 012f4ad70..ed8ad0046 100644 --- a/tests/generated/v3.0/swaggerhub-template.ts +++ b/tests/generated/v3.0/swaggerhub-template.ts @@ -101,7 +101,8 @@ export class HttpClient { } private contentFormatters: Record any> = { - [ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input), + [ContentType.Json]: (input: any) => + input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input, [ContentType.FormData]: (input: any) => Object.keys(input || {}).reduce((data, key) => { data.append(key, input[key]); diff --git a/tests/generated/v3.0/tsoa-odd-types-3.0.2.ts b/tests/generated/v3.0/tsoa-odd-types-3.0.2.ts index 877eaffe9..02984ac1a 100644 --- a/tests/generated/v3.0/tsoa-odd-types-3.0.2.ts +++ b/tests/generated/v3.0/tsoa-odd-types-3.0.2.ts @@ -222,7 +222,8 @@ export class HttpClient { } private contentFormatters: Record any> = { - [ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input), + [ContentType.Json]: (input: any) => + input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input, [ContentType.FormData]: (input: any) => Object.keys(input || {}).reduce((data, key) => { data.append(key, input[key]); diff --git a/tests/generated/v3.0/up-banking.ts b/tests/generated/v3.0/up-banking.ts index 1bbacf7b1..04394a306 100644 --- a/tests/generated/v3.0/up-banking.ts +++ b/tests/generated/v3.0/up-banking.ts @@ -629,7 +629,8 @@ export class HttpClient { } private contentFormatters: Record any> = { - [ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input), + [ContentType.Json]: (input: any) => + input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input, [ContentType.FormData]: (input: any) => Object.keys(input || {}).reduce((data, key) => { data.append(key, input[key]); diff --git a/tests/generated/v3.0/uspto.ts b/tests/generated/v3.0/uspto.ts index 8b4e36f9e..ce4e1b1aa 100644 --- a/tests/generated/v3.0/uspto.ts +++ b/tests/generated/v3.0/uspto.ts @@ -118,7 +118,8 @@ export class HttpClient { } private contentFormatters: Record any> = { - [ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input), + [ContentType.Json]: (input: any) => + input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input, [ContentType.FormData]: (input: any) => Object.keys(input || {}).reduce((data, key) => { data.append(key, input[key]); diff --git a/tests/generated/v3.0/wrong-enum-subtypes.ts b/tests/generated/v3.0/wrong-enum-subtypes.ts index 999cb7881..1081078ee 100644 --- a/tests/generated/v3.0/wrong-enum-subtypes.ts +++ b/tests/generated/v3.0/wrong-enum-subtypes.ts @@ -103,7 +103,8 @@ export class HttpClient { } private contentFormatters: Record any> = { - [ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input), + [ContentType.Json]: (input: any) => + input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input, [ContentType.FormData]: (input: any) => Object.keys(input || {}).reduce((data, key) => { data.append(key, input[key]); diff --git a/tests/generated/v3.0/wrong-schema-names.ts b/tests/generated/v3.0/wrong-schema-names.ts index ea9a0596f..27ebad78f 100644 --- a/tests/generated/v3.0/wrong-schema-names.ts +++ b/tests/generated/v3.0/wrong-schema-names.ts @@ -125,7 +125,8 @@ export class HttpClient { } private contentFormatters: Record any> = { - [ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input), + [ContentType.Json]: (input: any) => + input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input, [ContentType.FormData]: (input: any) => Object.keys(input || {}).reduce((data, key) => { data.append(key, input[key]); diff --git a/tests/spec/defaultAsSuccess/schema.ts b/tests/spec/defaultAsSuccess/schema.ts index 233935bce..d616a8783 100644 --- a/tests/spec/defaultAsSuccess/schema.ts +++ b/tests/spec/defaultAsSuccess/schema.ts @@ -153,7 +153,8 @@ export class HttpClient { } private contentFormatters: Record any> = { - [ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input), + [ContentType.Json]: (input: any) => + input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input, [ContentType.FormData]: (input: any) => Object.keys(input || {}).reduce((data, key) => { data.append(key, input[key]); diff --git a/tests/spec/defaultResponse/schema.ts b/tests/spec/defaultResponse/schema.ts index a852dc274..7a54e15bb 100644 --- a/tests/spec/defaultResponse/schema.ts +++ b/tests/spec/defaultResponse/schema.ts @@ -101,7 +101,8 @@ export class HttpClient { } private contentFormatters: Record any> = { - [ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input), + [ContentType.Json]: (input: any) => + input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input, [ContentType.FormData]: (input: any) => Object.keys(input || {}).reduce((data, key) => { data.append(key, input[key]); diff --git a/tests/spec/enumNamesAsValues/schema.ts b/tests/spec/enumNamesAsValues/schema.ts index 35a5194a5..8ae614afb 100644 --- a/tests/spec/enumNamesAsValues/schema.ts +++ b/tests/spec/enumNamesAsValues/schema.ts @@ -299,7 +299,8 @@ export class HttpClient { } private contentFormatters: Record any> = { - [ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input), + [ContentType.Json]: (input: any) => + input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input, [ContentType.FormData]: (input: any) => Object.keys(input || {}).reduce((data, key) => { data.append(key, input[key]); diff --git a/tests/spec/extractRequestParams/schema.ts b/tests/spec/extractRequestParams/schema.ts index 02836a6a5..4a8e426de 100644 --- a/tests/spec/extractRequestParams/schema.ts +++ b/tests/spec/extractRequestParams/schema.ts @@ -182,7 +182,8 @@ export class HttpClient { } private contentFormatters: Record any> = { - [ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input), + [ContentType.Json]: (input: any) => + input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input, [ContentType.FormData]: (input: any) => Object.keys(input || {}).reduce((data, key) => { data.append(key, input[key]); diff --git a/tests/spec/js/schema.js b/tests/spec/js/schema.js index ae0635417..47d30f61d 100644 --- a/tests/spec/js/schema.js +++ b/tests/spec/js/schema.js @@ -31,7 +31,8 @@ export class HttpClient { this.securityData = data; }; this.contentFormatters = { - [ContentType.Json]: (input) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input), + [ContentType.Json]: (input) => + input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input, [ContentType.FormData]: (input) => Object.keys(input || {}).reduce((data, key) => { data.append(key, input[key]); diff --git a/tests/spec/modular/http-client.ts b/tests/spec/modular/http-client.ts index d4fc3a77a..baec9e247 100644 --- a/tests/spec/modular/http-client.ts +++ b/tests/spec/modular/http-client.ts @@ -101,7 +101,8 @@ export class HttpClient { } private contentFormatters: Record any> = { - [ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input), + [ContentType.Json]: (input: any) => + input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input, [ContentType.FormData]: (input: any) => Object.keys(input || {}).reduce((data, key) => { data.append(key, input[key]); diff --git a/tests/spec/moduleNameIndex/schema.ts b/tests/spec/moduleNameIndex/schema.ts index 5a5bf2375..1ed776c89 100644 --- a/tests/spec/moduleNameIndex/schema.ts +++ b/tests/spec/moduleNameIndex/schema.ts @@ -229,7 +229,8 @@ export class HttpClient { } private contentFormatters: Record any> = { - [ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input), + [ContentType.Json]: (input: any) => + input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input, [ContentType.FormData]: (input: any) => Object.keys(input || {}).reduce((data, key) => { data.append(key, input[key]); diff --git a/tests/spec/responses/schema.ts b/tests/spec/responses/schema.ts index 3e8759a85..eb32938df 100644 --- a/tests/spec/responses/schema.ts +++ b/tests/spec/responses/schema.ts @@ -164,7 +164,8 @@ export class HttpClient { } private contentFormatters: Record any> = { - [ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input), + [ContentType.Json]: (input: any) => + input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input, [ContentType.FormData]: (input: any) => Object.keys(input || {}).reduce((data, key) => { data.append(key, input[key]); diff --git a/tests/spec/singleHttpClient/schema.ts b/tests/spec/singleHttpClient/schema.ts index adc811833..5554edeb3 100644 --- a/tests/spec/singleHttpClient/schema.ts +++ b/tests/spec/singleHttpClient/schema.ts @@ -101,7 +101,8 @@ export class HttpClient { } private contentFormatters: Record any> = { - [ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input), + [ContentType.Json]: (input: any) => + input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input, [ContentType.FormData]: (input: any) => Object.keys(input || {}).reduce((data, key) => { data.append(key, input[key]); diff --git a/tests/spec/unionEnums/schema.ts b/tests/spec/unionEnums/schema.ts index a4257b34f..96d892404 100644 --- a/tests/spec/unionEnums/schema.ts +++ b/tests/spec/unionEnums/schema.ts @@ -111,7 +111,8 @@ export class HttpClient { } private contentFormatters: Record any> = { - [ContentType.Json]: (input: any) => (input !== null && typeof input === "object" ? JSON.stringify(input) : input), + [ContentType.Json]: (input: any) => + input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input, [ContentType.FormData]: (input: any) => Object.keys(input || {}).reduce((data, key) => { data.append(key, input[key]);