diff --git a/templates/node/src/client.ts.twig b/templates/node/src/client.ts.twig index 5ed9b8b31e..8ed155e5ec 100644 --- a/templates/node/src/client.ts.twig +++ b/templates/node/src/client.ts.twig @@ -85,6 +85,15 @@ function fillDefaults( result[key] = fillDefaults(result[key], child, models); } } + // The spread drops the non-enumerable JSON toString that Client.call attaches. + if (Object.prototype.hasOwnProperty.call(value, 'toString')) { + Object.defineProperty(result, 'toString', { + value: () => JSONbig.stringify(result), + writable: true, + enumerable: false, + configurable: true, + }); + } return result; } diff --git a/templates/react-native/src/client.ts.twig b/templates/react-native/src/client.ts.twig index 65ec4b2e4e..5d7021fa25 100644 --- a/templates/react-native/src/client.ts.twig +++ b/templates/react-native/src/client.ts.twig @@ -86,6 +86,15 @@ function fillDefaults( result[key] = fillDefaults(result[key], child, models); } } + // The spread drops the non-enumerable JSON toString that Client.call attaches. + if (Object.prototype.hasOwnProperty.call(value, 'toString')) { + Object.defineProperty(result, 'toString', { + value: () => JSONbig.stringify(result), + writable: true, + enumerable: false, + configurable: true, + }); + } return result; } diff --git a/templates/web/src/client.ts.twig b/templates/web/src/client.ts.twig index 554eb54c36..4deb9bf64f 100644 --- a/templates/web/src/client.ts.twig +++ b/templates/web/src/client.ts.twig @@ -86,6 +86,15 @@ function fillDefaults( result[key] = fillDefaults(result[key], child, models); } } + // The spread drops the non-enumerable JSON toString that Client.call attaches. + if (Object.prototype.hasOwnProperty.call(value, 'toString')) { + Object.defineProperty(result, 'toString', { + value: () => JSONbig.stringify(result), + writable: true, + enumerable: false, + configurable: true, + }); + } return result; } diff --git a/tests/e2e/Base.php b/tests/e2e/Base.php index b9dcd38539..4a356102ca 100644 --- a/tests/e2e/Base.php +++ b/tests/e2e/Base.php @@ -96,6 +96,10 @@ abstract class Base extends TestCase 'preset: name=server, count=25, enabled=true', ]; + protected const JS_MODEL_TO_STRING_RESPONSES = [ + 'preset toString: {"name":"guest","count":25,"enabled":false,"tier":"free"}', + ]; + protected const PYTHON_MODEL_DEFAULT_RESPONSES = [ 'preset tier: PresetTier.FREE', ]; diff --git a/tests/e2e/Node18Test.php b/tests/e2e/Node18Test.php index ae3b286702..6f491dc346 100644 --- a/tests/e2e/Node18Test.php +++ b/tests/e2e/Node18Test.php @@ -58,6 +58,7 @@ final class Node18Test extends Base ...Base::MODEL_RESPONSES, ...Base::OPTIONAL_PARAM_RESPONSES, ...Base::MODEL_DEFAULT_RESPONSES, + ...Base::JS_MODEL_TO_STRING_RESPONSES, ...Base::EXCEPTION_RESPONSES, ...Base::OAUTH_RESPONSES, ...Base::QUERY_HELPER_RESPONSES, diff --git a/tests/e2e/Node20Test.php b/tests/e2e/Node20Test.php index 19f12194c4..4bc796c382 100644 --- a/tests/e2e/Node20Test.php +++ b/tests/e2e/Node20Test.php @@ -58,6 +58,7 @@ final class Node20Test extends Base ...Base::MODEL_RESPONSES, ...Base::OPTIONAL_PARAM_RESPONSES, ...Base::MODEL_DEFAULT_RESPONSES, + ...Base::JS_MODEL_TO_STRING_RESPONSES, ...Base::EXCEPTION_RESPONSES, ...Base::OAUTH_RESPONSES, ...Base::QUERY_HELPER_RESPONSES, diff --git a/tests/e2e/Node26Test.php b/tests/e2e/Node26Test.php index c6a14b9d9b..c7bb895da7 100644 --- a/tests/e2e/Node26Test.php +++ b/tests/e2e/Node26Test.php @@ -58,6 +58,7 @@ final class Node26Test extends Base ...Base::MODEL_RESPONSES, ...Base::OPTIONAL_PARAM_RESPONSES, ...Base::MODEL_DEFAULT_RESPONSES, + ...Base::JS_MODEL_TO_STRING_RESPONSES, ...Base::EXCEPTION_RESPONSES, ...Base::OAUTH_RESPONSES, ...Base::QUERY_HELPER_RESPONSES, diff --git a/tests/e2e/ReactNativeTest.php b/tests/e2e/ReactNativeTest.php index b6c9b4adb7..5faf16cd79 100644 --- a/tests/e2e/ReactNativeTest.php +++ b/tests/e2e/ReactNativeTest.php @@ -63,6 +63,7 @@ final class ReactNativeTest extends Base ...Base::MODEL_RESPONSES, ...Base::OPTIONAL_PARAM_RESPONSES, ...Base::MODEL_DEFAULT_RESPONSES, + ...Base::JS_MODEL_TO_STRING_RESPONSES, ...Base::EXCEPTION_RESPONSES, ...Base::REALTIME_RESPONSES, ...Base::QUERY_HELPER_RESPONSES, diff --git a/tests/e2e/WebChromiumTest.php b/tests/e2e/WebChromiumTest.php index ccf0683f3f..4233789dd7 100644 --- a/tests/e2e/WebChromiumTest.php +++ b/tests/e2e/WebChromiumTest.php @@ -59,6 +59,7 @@ final class WebChromiumTest extends Base ...Base::OPTIONAL_PARAM_RESPONSES, ...Base::UNION_RESPONSES, ...Base::MODEL_DEFAULT_RESPONSES, + ...Base::JS_MODEL_TO_STRING_RESPONSES, ...Base::EXCEPTION_RESPONSES, ...Base::REALTIME_RESPONSES, ...Base::QUERY_HELPER_RESPONSES, diff --git a/tests/e2e/WebNodeTest.php b/tests/e2e/WebNodeTest.php index aaa4ba98a2..1e5eb87618 100644 --- a/tests/e2e/WebNodeTest.php +++ b/tests/e2e/WebNodeTest.php @@ -51,6 +51,7 @@ final class WebNodeTest extends Base ...Base::OPTIONAL_PARAM_RESPONSES, ...Base::UNION_RESPONSES, ...Base::MODEL_DEFAULT_RESPONSES, + ...Base::JS_MODEL_TO_STRING_RESPONSES, ...Base::EXCEPTION_RESPONSES, ...Base::QUERY_HELPER_RESPONSES, ...Base::PERMISSION_HELPER_RESPONSES, diff --git a/tests/e2e/languages/node/test.js b/tests/e2e/languages/node/test.js index d01e0ecea0..c228753edf 100644 --- a/tests/e2e/languages/node/test.js +++ b/tests/e2e/languages/node/test.js @@ -284,6 +284,7 @@ async function start() { for (const item of presets.presets) { console.log(`preset: name=${item.name}, count=${item.count}, enabled=${item.enabled}`); } + console.log(`preset toString: ${preset.toString()}`); try { response = await general.error400(); diff --git a/tests/e2e/languages/react-native/browser.js b/tests/e2e/languages/react-native/browser.js index 19dd4c4461..72a6e5647d 100644 --- a/tests/e2e/languages/react-native/browser.js +++ b/tests/e2e/languages/react-native/browser.js @@ -231,6 +231,7 @@ import { for (const item of presets.presets) { console.log(`preset: name=${item.name}, count=${item.count}, enabled=${item.enabled}`); } + console.log(`preset toString: ${preset.toString()}`); // Exception responses try { diff --git a/tests/e2e/languages/web/index.html b/tests/e2e/languages/web/index.html index 734f322050..05e2f11a22 100644 --- a/tests/e2e/languages/web/index.html +++ b/tests/e2e/languages/web/index.html @@ -337,6 +337,7 @@ for (const item of presets.presets) { console.log(`preset: name=${item.name}, count=${item.count}, enabled=${item.enabled}`); } + console.log(`preset toString: ${preset.toString()}`); try { response = await general.error400(); diff --git a/tests/e2e/languages/web/node.js b/tests/e2e/languages/web/node.js index f5d9adf050..09252ae641 100644 --- a/tests/e2e/languages/web/node.js +++ b/tests/e2e/languages/web/node.js @@ -200,6 +200,7 @@ async function start() { for (const item of presets.presets) { console.log(`preset: name=${item.name}, count=${item.count}, enabled=${item.enabled}`); } + console.log(`preset toString: ${preset.toString()}`); try { response = await general.error400();