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 6c50de8a5a6..59fa1f75d57 100644 --- a/modules/openapi-generator/src/main/resources/typescript-fetch/apis.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-fetch/apis.mustache @@ -265,7 +265,7 @@ export class {{classname}} extends runtime.BaseAPI { {{/isEnumRef}} {{^isEnumRef}} {{^withoutRuntimeChecks}} - formParams.append('{{baseName}}', new Blob([JSON.stringify({{{dataType}}}ToJSON(requestParameters['{{paramName}}']))], { type: "application/json", })); + formParams.append('{{baseName}}', new Blob([JSON.stringify({{returnType}}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 0145f4890f4..d1a6d8e4301 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,6 +347,31 @@ 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 new file mode 100644 index 00000000000..46b7c00b01f --- /dev/null +++ b/modules/openapi-generator/src/test/resources/bugs/issue_20195.json @@ -0,0 +1,77 @@ +{ + "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 609de4bb9fb..b2d105cf768 100644 --- a/samples/client/petstore/typescript-fetch/tests/default/package-lock.json +++ b/samples/client/petstore/typescript-fetch/tests/default/package-lock.json @@ -32,21 +32,6 @@ "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",