forked from loafle/openapi-generator-original
[kotlin-spring] Fix inheritance compile error because of missing use-site target on annotation (#3596) (#15488)
This commit is contained in:
parent
f5f382c87a
commit
f0d439fbce
@ -1,4 +1,4 @@
|
||||
{{#swagger2AnnotationLibrary}}
|
||||
@Schema({{#example}}example = "{{{.}}}", {{/example}}{{#required}}requiredMode = Schema.RequiredMode.REQUIRED, {{/required}}{{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}description = "{{{description}}}"){{/swagger2AnnotationLibrary}}{{#swagger1AnnotationLibrary}}
|
||||
@ApiModelProperty({{#example}}example = "{{{.}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}{{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}value = "{{{description}}}"){{/swagger1AnnotationLibrary}}
|
||||
@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}}
|
||||
{{>modelMutable}} {{{name}}}: {{#isEnum}}{{classname}}.{{nameInCamelCase}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}? {{^discriminator}}= {{{defaultValue}}}{{^defaultValue}}null{{/defaultValue}}{{/discriminator}}
|
||||
|
@ -1,4 +1,4 @@
|
||||
{{#swagger2AnnotationLibrary}}
|
||||
@Schema({{#example}}example = "{{{.}}}", {{/example}}{{#required}}requiredMode = Schema.RequiredMode.REQUIRED, {{/required}}{{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}description = "{{{description}}}"){{/swagger2AnnotationLibrary}}{{#swagger1AnnotationLibrary}}
|
||||
@ApiModelProperty({{#example}}example = "{{{.}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}{{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}value = "{{{description}}}"){{/swagger1AnnotationLibrary}}
|
||||
@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}}
|
||||
{{>modelMutable}} {{{name}}}: {{#isEnum}}{{classname}}.{{nameInCamelCase}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}
|
||||
|
@ -14,6 +14,8 @@ import org.openapitools.codegen.TestUtils;
|
||||
import org.openapitools.codegen.kotlin.KotlinTestUtils;
|
||||
import org.openapitools.codegen.languages.KotlinSpringServerCodegen;
|
||||
import org.openapitools.codegen.languages.features.CXFServerFeatures;
|
||||
import org.openapitools.codegen.languages.features.DocumentationProviderFeatures.AnnotationLibrary;
|
||||
import org.openapitools.codegen.languages.features.DocumentationProviderFeatures.DocumentationProvider;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@ -26,6 +28,8 @@ import java.util.List;
|
||||
|
||||
import static org.openapitools.codegen.TestUtils.assertFileContains;
|
||||
import static org.openapitools.codegen.TestUtils.assertFileNotContains;
|
||||
import static org.openapitools.codegen.languages.features.DocumentationProviderFeatures.ANNOTATION_LIBRARY;
|
||||
import static org.openapitools.codegen.languages.features.DocumentationProviderFeatures.DOCUMENTATION_PROVIDER;
|
||||
|
||||
public class KotlinSpringServerCodegenTest {
|
||||
|
||||
@ -480,4 +484,70 @@ public class KotlinSpringServerCodegenTest {
|
||||
+ "- uses Markdown (CommonMark) for rich text representation\"\"\""
|
||||
);
|
||||
}
|
||||
|
||||
@Test(description = "use get Annotation use-site target on kotlin interface attributes")
|
||||
public void useTargetOnInterfaceAnnotations() throws IOException {
|
||||
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
|
||||
output.deleteOnExit();
|
||||
String outputPath = output.getAbsolutePath().replace('\\', '/');
|
||||
|
||||
KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen();
|
||||
codegen.setOutputDir(output.getAbsolutePath());
|
||||
|
||||
new DefaultGenerator().opts(new ClientOptInput()
|
||||
.openAPI(TestUtils.parseSpec("src/test/resources/3_0/kotlin/issue3596-use-correct-get-annotation-target.yaml"))
|
||||
.config(codegen))
|
||||
.generate();
|
||||
|
||||
assertFileNotContains(
|
||||
Paths.get(outputPath + "/src/main/kotlin/org/openapitools/model/Animal.kt"),
|
||||
"@Schema(example = \"null\", description = \"\")"
|
||||
);
|
||||
assertFileContains(
|
||||
Paths.get(outputPath + "/src/main/kotlin/org/openapitools/model/Animal.kt"),
|
||||
"@get:Schema(example = \"null\", description = \"\")"
|
||||
);
|
||||
assertFileNotContains(
|
||||
Paths.get(outputPath + "/src/main/kotlin/org/openapitools/model/Animal.kt"),
|
||||
"@Schema(example = \"null\", requiredMode = Schema.RequiredMode.REQUIRED, description = \"\")"
|
||||
);
|
||||
assertFileContains(
|
||||
Paths.get(outputPath + "/src/main/kotlin/org/openapitools/model/Animal.kt"),
|
||||
"@get:Schema(example = \"null\", requiredMode = Schema.RequiredMode.REQUIRED, description = \"\")"
|
||||
);
|
||||
}
|
||||
|
||||
@Test(description = "use get Annotation use-site target on kotlin interface attributes (swagger1)")
|
||||
public void useTargetOnInterfaceAnnotationsWithSwagger1() 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(ANNOTATION_LIBRARY, AnnotationLibrary.SWAGGER1.toCliOptValue());
|
||||
codegen.additionalProperties().put(DOCUMENTATION_PROVIDER, DocumentationProvider.SPRINGFOX.toCliOptValue());
|
||||
|
||||
new DefaultGenerator().opts(new ClientOptInput()
|
||||
.openAPI(TestUtils.parseSpec("src/test/resources/3_0/kotlin/issue3596-use-correct-get-annotation-target.yaml"))
|
||||
.config(codegen))
|
||||
.generate();
|
||||
|
||||
assertFileNotContains(
|
||||
Paths.get(outputPath + "/src/main/kotlin/org/openapitools/model/Animal.kt"),
|
||||
"@ApiModelProperty(example = \"null\", value = \"\")"
|
||||
);
|
||||
assertFileContains(
|
||||
Paths.get(outputPath + "/src/main/kotlin/org/openapitools/model/Animal.kt"),
|
||||
"@get:ApiModelProperty(example = \"null\", value = \"\")"
|
||||
);
|
||||
assertFileNotContains(
|
||||
Paths.get(outputPath + "/src/main/kotlin/org/openapitools/model/Animal.kt"),
|
||||
"@ApiModelProperty(example = \"null\", required = true, value = \"\")"
|
||||
);
|
||||
assertFileContains(
|
||||
Paths.get(outputPath + "/src/main/kotlin/org/openapitools/model/Animal.kt"),
|
||||
"@get:ApiModelProperty(example = \"null\", required = true, value = \"\")"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,31 @@
|
||||
openapi: 3.0.1
|
||||
info:
|
||||
title: example
|
||||
version: 1.0.0
|
||||
paths:
|
||||
/test:
|
||||
get:
|
||||
responses:
|
||||
200:
|
||||
description: successful operation
|
||||
components:
|
||||
schemas:
|
||||
Animal:
|
||||
type: object
|
||||
properties:
|
||||
weight:
|
||||
type: number
|
||||
hasLegs:
|
||||
type: boolean
|
||||
discriminator:
|
||||
propertyName: animalType
|
||||
required:
|
||||
- animalType
|
||||
- hasLegs
|
||||
Pet:
|
||||
allOf:
|
||||
- $ref: "#/components/schemas/Animal"
|
||||
- type: object
|
||||
properties:
|
||||
name:
|
||||
type: string
|
Loading…
x
Reference in New Issue
Block a user