forked from loafle/openapi-generator-original
[typescript-fetch] to fix incorrect parsing with additional properties (#20923)
* Fix issue #20195 * Ran export_docs_generators.sh * Generated path separators fixed * Trigger Build
This commit is contained in:
parent
cd2fbd6ff4
commit
0becb3feb7
@ -265,7 +265,7 @@ export class {{classname}} extends runtime.BaseAPI {
|
|||||||
{{/isEnumRef}}
|
{{/isEnumRef}}
|
||||||
{{^isEnumRef}}
|
{{^isEnumRef}}
|
||||||
{{^withoutRuntimeChecks}}
|
{{^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}}
|
{{/withoutRuntimeChecks}}{{#withoutRuntimeChecks}}
|
||||||
formParams.append('{{baseName}}', new Blob([JSON.stringify(requestParameters['{{paramName}}'])], { type: "application/json", }));
|
formParams.append('{{baseName}}', new Blob([JSON.stringify(requestParameters['{{paramName}}'])], { type: "application/json", }));
|
||||||
{{/withoutRuntimeChecks}}
|
{{/withoutRuntimeChecks}}
|
||||||
|
@ -347,6 +347,31 @@ public class TypeScriptFetchClientCodegenTest {
|
|||||||
TestUtils.assertFileExists(Paths.get(output + "/apis/petControllerApi.ts"));
|
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<String, Object> 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<String, Object> properties) throws IOException {
|
private static File generate(Map<String, Object> properties) throws IOException {
|
||||||
File output = Files.createTempDirectory("test").toFile();
|
File output = Files.createTempDirectory("test").toFile();
|
||||||
output.deleteOnExit();
|
output.deleteOnExit();
|
||||||
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -32,21 +32,6 @@
|
|||||||
"webpack": "^1.13.0"
|
"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": {
|
"node_modules/@types/chai": {
|
||||||
"version": "4.3.16",
|
"version": "4.3.16",
|
||||||
"resolved": "https://registry.npmjs.org/@types/chai/-/chai-4.3.16.tgz",
|
"resolved": "https://registry.npmjs.org/@types/chai/-/chai-4.3.16.tgz",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user