Skip to content

Commit 0becb3f

Browse files
authored
[typescript-fetch] to fix incorrect parsing with additional properties (#20923)
* Fix issue #20195 * Ran export_docs_generators.sh * Generated path separators fixed * Trigger Build
1 parent cd2fbd6 commit 0becb3f

File tree

4 files changed

+103
-16
lines changed

4 files changed

+103
-16
lines changed

modules/openapi-generator/src/main/resources/typescript-fetch/apis.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ export class {{classname}} extends runtime.BaseAPI {
265265
{{/isEnumRef}}
266266
{{^isEnumRef}}
267267
{{^withoutRuntimeChecks}}
268-
formParams.append('{{baseName}}', new Blob([JSON.stringify({{{dataType}}}ToJSON(requestParameters['{{paramName}}']))], { type: "application/json", }));
268+
formParams.append('{{baseName}}', new Blob([JSON.stringify({{returnType}}ToJSON(requestParameters['{{paramName}}']))], { type: "application/json", }));
269269
{{/withoutRuntimeChecks}}{{#withoutRuntimeChecks}}
270270
formParams.append('{{baseName}}', new Blob([JSON.stringify(requestParameters['{{paramName}}'])], { type: "application/json", }));
271271
{{/withoutRuntimeChecks}}

modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/fetch/TypeScriptFetchClientCodegenTest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,31 @@ public void testGeneratedFilenamesInCamelCaseWithAdditionalModelPrefix() throws
347347
TestUtils.assertFileExists(Paths.get(output + "/apis/petControllerApi.ts"));
348348
}
349349

350+
@Test(description = "Issue #20195")
351+
public void givenObjectHasAdditionalPropertiesWhenGenerateThenIndexSignatureNotUsedToGenerateMethodName() throws IOException {
352+
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
353+
output.deleteOnExit();
354+
355+
TypeScriptFetchClientCodegen clientCodegen = new TypeScriptFetchClientCodegen();
356+
clientCodegen.setWithoutRuntimeChecks(false);
357+
clientCodegen.setOutputDir(output.getAbsolutePath());
358+
359+
Map<String, Object> properties = new HashMap<>();
360+
properties.put(TypeScriptFetchClientCodegen.WITH_INTERFACES, true);
361+
properties.put(CodegenConstants.ENUM_PROPERTY_NAMING, "original");
362+
clientCodegen.additionalProperties().putAll(properties);
363+
364+
DefaultGenerator defaultGenerator = new DefaultGenerator();
365+
defaultGenerator.opts(
366+
new ClientOptInput().openAPI(TestUtils.parseSpec("src/test/resources/bugs/issue_20195.json"))
367+
.config(clientCodegen)
368+
).generate();
369+
370+
String outputPath = output.getAbsolutePath();
371+
Path exampleApiPath = Paths.get(outputPath + "/apis/ExampleApi.ts");
372+
TestUtils.assertFileContains(exampleApiPath, "new Blob([JSON.stringify(ResponseOfStringToJSON");
373+
}
374+
350375
private static File generate(Map<String, Object> properties) throws IOException {
351376
File output = Files.createTempDirectory("test").toFile();
352377
output.deleteOnExit();
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
{
2+
"openapi": "3.0.1",
3+
"info": {
4+
"title": "Sample API",
5+
"description": "This is sample api",
6+
"version": "v1"
7+
},
8+
"paths": {
9+
"/example_api_101": {
10+
"post": {
11+
"tags": [
12+
"Example"
13+
],
14+
"summary": "Process Auth",
15+
"parameters": [
16+
{
17+
"name": "Id",
18+
"in": "query",
19+
"schema": {
20+
"type": "integer",
21+
"format": "int32"
22+
}
23+
}
24+
],
25+
"requestBody": {
26+
"content": {
27+
"multipart/form-data": {
28+
"schema": {
29+
"type": "object",
30+
"properties": {
31+
"paRes": {
32+
"type": "object",
33+
"additionalProperties": {
34+
"type": "string"
35+
},
36+
"description": "Form sent for Authentication"
37+
}
38+
}
39+
},
40+
"encoding": {
41+
"paRes": {
42+
"style": "form"
43+
}
44+
}
45+
}
46+
}
47+
},
48+
"responses": {
49+
"200": {
50+
"description": "OK",
51+
"content": {
52+
"application/json": {
53+
"schema": {
54+
"$ref": "#/components/schemas/ResponseOfString"
55+
}
56+
}
57+
}
58+
}
59+
}
60+
}
61+
}
62+
},
63+
"components": {
64+
"schemas": {
65+
"ResponseOfString": {
66+
"type": "object",
67+
"properties": {
68+
"message": {
69+
"type": "string",
70+
"nullable": true
71+
}
72+
},
73+
"additionalProperties": false
74+
}
75+
}
76+
}
77+
}

samples/client/petstore/typescript-fetch/tests/default/package-lock.json

Lines changed: 0 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)