forked from loafle/openapi-generator-original
[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:
parent
129fd0ad5c
commit
88e2490087
@ -181,7 +181,7 @@ public class {{classname}}{{#parent}} extends {{{parent}}}{{/parent}}{{^parent}}
|
||||
{{#isMap}}
|
||||
|
||||
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;
|
||||
}
|
||||
{{/isMap}}
|
||||
|
@ -1380,4 +1380,27 @@ public class SpringCodegenTest {
|
||||
.assertParameterAnnotations()
|
||||
.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);");
|
||||
}
|
||||
}
|
||||
|
@ -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
|
Loading…
x
Reference in New Issue
Block a user