diff --git a/CHANGELOG.md b/CHANGELOG.md index 040a97cb..665621bf 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 7883f970..f3e7b160 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 b08d7d4e..3b13c6d8 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 62b313d6..71b5b0f1 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 3d2a644c..ae92e1cb 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 95a3bcd6..9ba7ce8e 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 1f24f580..3180bd42 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 cff35571..ae5e04fd 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 3c6a9178..1b2df293 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 b367d057..47878481 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 f97ff857..065e1dc8 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 23f219cd..5247c131 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 91647915..b276d514 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 27463ecf..d7f93da2 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 f0e13caf..2eaafba4 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 c59697c4..3feeb8ea 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 ec19955a..042eaf51 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 861e6d29..1285988f 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 7bd00391..3d7fe8c0 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 01cc1851..34f6e3cf 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 a2d9af2c..ba06b108 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 448c6d1f..256dd9f5 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 09ddfe3e..3baab13b 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 c62eaa9e..39023be2 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 ad8140b3..2735c738 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 321f9800..d83146b9 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 e74af7b7..0eb1d07f 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 240c7f9f..47b46ab5 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 9a4b5ffa..4a90fe90 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 78346133..ff2a0b99 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 7b3f176c..bf0340f8 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 e24b5dd1..4501ea63 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 cbca8305..cc9a089d 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 dcf1384a..5ead52b4 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 e0514067..0a1f1f4e 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 41f49d31..54b0f899 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 cbc13a6f..3a6592f6 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 23a12d36..1f412358 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 14e85e11..0208d69f 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 6da484cb..777c14b8 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 2a74589d..42583902 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 fdfc5907..c2e43a9b 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 012f4ad7..ed8ad004 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 877eaffe..02984ac1 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 1bbacf7b..04394a30 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 8b4e36f9..ce4e1b1a 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 999cb788..1081078e 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 ea9a0596..27ebad78 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 233935bc..d616a878 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 a852dc27..7a54e15b 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 35a5194a..8ae614af 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 02836a6a..4a8e426d 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 ae063541..47d30f61 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 d4fc3a77..baec9e24 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 5a5bf237..1ed776c8 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 3e8759a8..eb32938d 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 adc81183..5554edeb 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 a4257b34..96d89240 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]);