[Java/Spring] Fix of issue #12494: call to superclass method is done with correct arguments (#12496)

* [Java/Spring] add missing key parameter to put-item method call of super class (#12494)

* [Java/Spring] add test for missing key parameter to put-item method call of super class (#12494)
This commit is contained in:
WeihmannTNG 2022-06-01 02:28:20 +02:00 committed by GitHub
parent 129fd0ad5c
commit 88e2490087
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 66 additions and 1 deletions

View File

@ -181,7 +181,7 @@ public class {{classname}}{{#parent}} extends {{{parent}}}{{/parent}}{{^parent}}
{{#isMap}} {{#isMap}}
public {{classname}} put{{nameInCamelCase}}Item(String key, {{{items.datatypeWithEnum}}} {{name}}Item) { public {{classname}} put{{nameInCamelCase}}Item(String key, {{{items.datatypeWithEnum}}} {{name}}Item) {
super.put{{nameInCamelCase}}Item({{name}}Item); super.put{{nameInCamelCase}}Item(key, {{name}}Item);
return this; return this;
} }
{{/isMap}} {{/isMap}}

View File

@ -1380,4 +1380,27 @@ public class SpringCodegenTest {
.assertParameterAnnotations() .assertParameterAnnotations()
.containsWithNameAndAttributes("RequestParam", ImmutableMap.of("defaultValue", "\"\"")); .containsWithNameAndAttributes("RequestParam", ImmutableMap.of("defaultValue", "\"\""));
} }
@Test
public void testPutItemsMethodContainsKeyInSuperClassMethodCall_issue12494() throws IOException {
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
output.deleteOnExit();
OpenAPI openAPI = new OpenAPIParser()
.readLocation("src/test/resources/bugs/issue_12494.yaml", null, new ParseOptions()).getOpenAPI();
SpringCodegen codegen = new SpringCodegen();
codegen.setOutputDir(output.getAbsolutePath());
ClientOptInput input = new ClientOptInput()
.openAPI(openAPI)
.config(codegen);
DefaultGenerator generator = new DefaultGenerator();
Map<String, File> files = generator.opts(input).generate().stream()
.collect(Collectors.toMap(File::getName, Function.identity()));
JavaFileAssert.assertThat(files.get("ChildClass.java"))
.assertMethod("putSomeMapItem")
.bodyContainsLines("super.putSomeMapItem(key, someMapItem);");
}
} }

View File

@ -0,0 +1,42 @@
openapi: '3.0.3'
info:
version: 1.0.0
title: Example Api
paths:
/dummy:
get:
summary: dummy
operationId: dummy
responses:
'200':
description: OK
components:
schemas:
ChildClass:
type: object
allOf:
- $ref: "#/components/schemas/ParentClass"
- type: object
properties:
objectType:
type: string
default: "ChildClass"
ParentClass:
type: object
discriminator:
propertyName: objectType
properties:
objectType:
type: string
default: "ParentClass"
someMap:
$ref: "#/components/schemas/MapClass"
MapClass:
type: object
additionalProperties:
type: string