forked from loafle/openapi-generator-original
[Kotlin] fix 20228 - spring-kotlin insert override modifier to interface if it is needed (#20246)
This commit is contained in:
parent
8035da8639
commit
f603f04bc4
@ -2,4 +2,4 @@
|
||||
@get:Schema({{#example}}example = "{{{.}}}", {{/example}}{{#required}}requiredMode = Schema.RequiredMode.REQUIRED, {{/required}}{{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}description = "{{{description}}}"){{/swagger2AnnotationLibrary}}{{#swagger1AnnotationLibrary}}
|
||||
@get:ApiModelProperty({{#example}}example = "{{{.}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}{{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}value = "{{{description}}}"){{/swagger1AnnotationLibrary}}{{#vendorExtensions.x-field-extra-annotation}}
|
||||
{{{.}}}{{/vendorExtensions.x-field-extra-annotation}}
|
||||
{{>modelMutable}} {{{name}}}: {{#isEnum}}{{classname}}.{{nameInPascalCase}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}? {{^discriminator}}= {{{defaultValue}}}{{^defaultValue}}null{{/defaultValue}}{{/discriminator}}
|
||||
{{#isInherited}}override {{/isInherited}}{{>modelMutable}} {{{name}}}: {{#isEnum}}{{classname}}.{{nameInPascalCase}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}? {{^discriminator}}= {{{defaultValue}}}{{^defaultValue}}null{{/defaultValue}}{{/discriminator}}
|
||||
|
@ -2,4 +2,4 @@
|
||||
@get:Schema({{#example}}example = "{{{.}}}", {{/example}}{{#required}}requiredMode = Schema.RequiredMode.REQUIRED, {{/required}}{{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}description = "{{{description}}}"){{/swagger2AnnotationLibrary}}{{#swagger1AnnotationLibrary}}
|
||||
@get:ApiModelProperty({{#example}}example = "{{{.}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}{{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}value = "{{{description}}}"){{/swagger1AnnotationLibrary}}{{#vendorExtensions.x-field-extra-annotation}}
|
||||
{{{.}}}{{/vendorExtensions.x-field-extra-annotation}}
|
||||
{{>modelMutable}} {{{name}}}: {{#isEnum}}{{classname}}.{{nameInPascalCase}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}
|
||||
{{#isInherited}}override {{/isInherited}}{{>modelMutable}} {{{name}}}: {{#isEnum}}{{classname}}.{{nameInPascalCase}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}
|
||||
|
@ -851,6 +851,36 @@ public class KotlinSpringServerCodegenTest {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void overridePropertyFunction() throws IOException {
|
||||
|
||||
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
|
||||
output.deleteOnExit();
|
||||
String outputPath = output.getAbsolutePath().replace('\\', '/');
|
||||
|
||||
KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen();
|
||||
codegen.setOutputDir(output.getAbsolutePath());
|
||||
codegen.additionalProperties().put(CodegenConstants.SERIALIZABLE_MODEL, true);
|
||||
|
||||
ClientOptInput input = new ClientOptInput()
|
||||
.openAPI(TestUtils.parseSpec("src/test/resources/bugs/issue_20228.yaml"))
|
||||
.config(codegen);
|
||||
DefaultGenerator generator = new DefaultGenerator();
|
||||
|
||||
generator.setGeneratorPropertyDefault(CodegenConstants.MODELS, "true");
|
||||
generator.setGeneratorPropertyDefault(CodegenConstants.MODEL_TESTS, "false");
|
||||
generator.setGeneratorPropertyDefault(CodegenConstants.MODEL_DOCS, "false");
|
||||
generator.setGeneratorPropertyDefault(CodegenConstants.APIS, "false");
|
||||
generator.setGeneratorPropertyDefault(CodegenConstants.SUPPORTING_FILES, "false");
|
||||
|
||||
generator.opts(input).generate();
|
||||
|
||||
assertFileContains(
|
||||
Paths.get(outputPath + "/src/main/kotlin/org/openapitools/model/Pony.kt"),
|
||||
"override val nameOpt", "override val nameReq"
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generateSerializableModel() throws Exception {
|
||||
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
|
||||
|
@ -0,0 +1,42 @@
|
||||
openapi: 3.0.3
|
||||
paths:
|
||||
/api/kotlin-test:
|
||||
post:
|
||||
description: Example get
|
||||
responses:
|
||||
'200':
|
||||
description: The request sent by the client was successful.
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/Unicorn'
|
||||
components:
|
||||
schemas:
|
||||
Animal:
|
||||
type: "object"
|
||||
properties:
|
||||
nameOpt:
|
||||
type: "string"
|
||||
nameReq:
|
||||
type: "string"
|
||||
discriminator:
|
||||
propertyName: animalType
|
||||
mapping:
|
||||
pegasi: "#/components/schemas/Pony"
|
||||
Pony:
|
||||
allOf:
|
||||
- $ref: "#/components/schemas/Animal"
|
||||
- type: "object"
|
||||
discriminator:
|
||||
propertyName: ponyType
|
||||
mapping:
|
||||
pegasi: "#/components/schemas/Pegasi"
|
||||
unicorn: "#/components/schemas/Unicorn"
|
||||
Pegasi:
|
||||
allOf:
|
||||
- $ref: "#/components/schemas/Pony"
|
||||
- type: "object"
|
||||
Unicorn:
|
||||
allOf:
|
||||
- $ref: "#/components/schemas/Pony"
|
||||
- type: "object"
|
Loading…
x
Reference in New Issue
Block a user