From 65cb95bef048b5110fda362feee52e76795fa26d Mon Sep 17 00:00:00 2001 From: Adrian Hjertstedt Date: Thu, 10 Jul 2025 17:41:29 +0100 Subject: [PATCH] Revert "[typescript-fetch] to fix incorrect parsing with additional properties (#20923)" (#21542) This reverts commit 0becb3feb7c346585f7cc85501e75f58aa63e95c. Co-authored-by: Adrian Hjertstedt --- .../resources/typescript-fetch/apis.mustache | 2 +- .../TypeScriptFetchClientCodegenTest.java | 25 ------ .../src/test/resources/bugs/issue_20195.json | 77 ------------------- .../tests/default/package-lock.json | 15 ++++ 4 files changed, 16 insertions(+), 103 deletions(-) delete mode 100644 modules/openapi-generator/src/test/resources/bugs/issue_20195.json diff --git a/modules/openapi-generator/src/main/resources/typescript-fetch/apis.mustache b/modules/openapi-generator/src/main/resources/typescript-fetch/apis.mustache index cb90d4dd104..fb50520f925 100644 --- a/modules/openapi-generator/src/main/resources/typescript-fetch/apis.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-fetch/apis.mustache @@ -266,7 +266,7 @@ export class {{classname}} extends runtime.BaseAPI { {{/isEnumRef}} {{^isEnumRef}} {{^withoutRuntimeChecks}} - formParams.append('{{baseName}}', new Blob([JSON.stringify({{returnType}}ToJSON(requestParameters['{{paramName}}']))], { type: "application/json", })); + formParams.append('{{baseName}}', new Blob([JSON.stringify({{{dataType}}}ToJSON(requestParameters['{{paramName}}']))], { type: "application/json", })); {{/withoutRuntimeChecks}}{{#withoutRuntimeChecks}} formParams.append('{{baseName}}', new Blob([JSON.stringify(requestParameters['{{paramName}}'])], { type: "application/json", })); {{/withoutRuntimeChecks}} diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/fetch/TypeScriptFetchClientCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/fetch/TypeScriptFetchClientCodegenTest.java index d1a6d8e4301..0145f4890f4 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/fetch/TypeScriptFetchClientCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/fetch/TypeScriptFetchClientCodegenTest.java @@ -347,31 +347,6 @@ public class TypeScriptFetchClientCodegenTest { TestUtils.assertFileExists(Paths.get(output + "/apis/petControllerApi.ts")); } - @Test(description = "Issue #20195") - public void givenObjectHasAdditionalPropertiesWhenGenerateThenIndexSignatureNotUsedToGenerateMethodName() throws IOException { - File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); - output.deleteOnExit(); - - TypeScriptFetchClientCodegen clientCodegen = new TypeScriptFetchClientCodegen(); - clientCodegen.setWithoutRuntimeChecks(false); - clientCodegen.setOutputDir(output.getAbsolutePath()); - - Map properties = new HashMap<>(); - properties.put(TypeScriptFetchClientCodegen.WITH_INTERFACES, true); - properties.put(CodegenConstants.ENUM_PROPERTY_NAMING, "original"); - clientCodegen.additionalProperties().putAll(properties); - - DefaultGenerator defaultGenerator = new DefaultGenerator(); - defaultGenerator.opts( - new ClientOptInput().openAPI(TestUtils.parseSpec("src/test/resources/bugs/issue_20195.json")) - .config(clientCodegen) - ).generate(); - - String outputPath = output.getAbsolutePath(); - Path exampleApiPath = Paths.get(outputPath + "/apis/ExampleApi.ts"); - TestUtils.assertFileContains(exampleApiPath, "new Blob([JSON.stringify(ResponseOfStringToJSON"); - } - private static File generate(Map properties) throws IOException { File output = Files.createTempDirectory("test").toFile(); output.deleteOnExit(); diff --git a/modules/openapi-generator/src/test/resources/bugs/issue_20195.json b/modules/openapi-generator/src/test/resources/bugs/issue_20195.json deleted file mode 100644 index 46b7c00b01f..00000000000 --- a/modules/openapi-generator/src/test/resources/bugs/issue_20195.json +++ /dev/null @@ -1,77 +0,0 @@ -{ - "openapi": "3.0.1", - "info": { - "title": "Sample API", - "description": "This is sample api", - "version": "v1" - }, - "paths": { - "/example_api_101": { - "post": { - "tags": [ - "Example" - ], - "summary": "Process Auth", - "parameters": [ - { - "name": "Id", - "in": "query", - "schema": { - "type": "integer", - "format": "int32" - } - } - ], - "requestBody": { - "content": { - "multipart/form-data": { - "schema": { - "type": "object", - "properties": { - "paRes": { - "type": "object", - "additionalProperties": { - "type": "string" - }, - "description": "Form sent for Authentication" - } - } - }, - "encoding": { - "paRes": { - "style": "form" - } - } - } - } - }, - "responses": { - "200": { - "description": "OK", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/ResponseOfString" - } - } - } - } - } - } - } - }, - "components": { - "schemas": { - "ResponseOfString": { - "type": "object", - "properties": { - "message": { - "type": "string", - "nullable": true - } - }, - "additionalProperties": false - } - } - } -} \ No newline at end of file diff --git a/samples/client/petstore/typescript-fetch/tests/default/package-lock.json b/samples/client/petstore/typescript-fetch/tests/default/package-lock.json index b2d105cf768..609de4bb9fb 100644 --- a/samples/client/petstore/typescript-fetch/tests/default/package-lock.json +++ b/samples/client/petstore/typescript-fetch/tests/default/package-lock.json @@ -32,6 +32,21 @@ "webpack": "^1.13.0" } }, + "../../builds/with-npm-version": { + "name": "@openapitools/typescript-fetch-petstore", + "version": "1.0.0", + "devDependencies": { + "typescript": "^4.0 || ^5.0" + } + }, + "node_modules/@openapitools/typescript-fetch-petstore": { + "resolved": "../../builds/with-npm-version", + "link": true + }, + "node_modules/@swagger/typescript-fetch-petstore": { + "resolved": "../../builds/with-npm-version", + "link": true + }, "node_modules/@types/chai": { "version": "4.3.16", "resolved": "https://registry.npmjs.org/@types/chai/-/chai-4.3.16.tgz",