Skip to content

Commit 718e1e8

Browse files
committed
Add change to template with tests
1 parent d11bc86 commit 718e1e8

4 files changed

Lines changed: 63 additions & 0 deletions

File tree

modules/openapi-generator/src/main/resources/kotlin-spring/api.mustache

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ class {{classname}}Controller({{#serviceInterface}}@Autowired(required = true) v
8787
{{#vendorExtensions.x-operation-extra-annotation}}
8888
{{{.}}}
8989
{{/vendorExtensions.x-operation-extra-annotation}}
90+
{{#isDeprecated}}
91+
@Deprecated
92+
{{/isDeprecated}}
9093
@RequestMapping(
9194
method = [RequestMethod.{{httpMethod}}],
9295
// "{{#lambdaEscapeInNormalString}}{{{path}}}{{/lambdaEscapeInNormalString}}"

modules/openapi-generator/src/main/resources/kotlin-spring/apiInterface.mustache

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ interface {{classname}} {
102102
{{#vendorExtensions.x-operation-extra-annotation}}
103103
{{{.}}}
104104
{{/vendorExtensions.x-operation-extra-annotation}}
105+
{{#isDeprecated}}
106+
@Deprecated
107+
{{/isDeprecated}}
105108
@RequestMapping(
106109
method = [RequestMethod.{{httpMethod}}],
107110
// "{{#lambdaEscapeInNormalString}}{{{path}}}{{/lambdaEscapeInNormalString}}"

modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/spring/KotlinSpringServerCodegenTest.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4663,6 +4663,49 @@ public void testSealedResponseInterfacesVoidResponse() throws IOException {
46634663
Assert.assertTrue(petContent.contains(") : CreatePetResponse {") || petContent.contains(") : CreatePetResponse"),
46644664
"Pet should implement CreatePetResponse");
46654665
}
4666+
4667+
@Test
4668+
public void testDeprecatedAnnotationOnInterface() throws IOException {
4669+
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
4670+
output.deleteOnExit();
4671+
String outputPath = output.getAbsolutePath().replace('\\', '/');
4672+
4673+
KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen();
4674+
codegen.setOutputDir(output.getAbsolutePath());
4675+
codegen.additionalProperties().put(CodegenConstants.API_PACKAGE, "org.openapitools.api");
4676+
codegen.additionalProperties().put(KotlinSpringServerCodegen.INTERFACE_ONLY, true);
4677+
4678+
new DefaultGenerator().opts(new ClientOptInput()
4679+
.openAPI(TestUtils.parseSpec("src/test/resources/3_0/kotlin/support-deprecated-api.yaml"))
4680+
.config(codegen))
4681+
.generate();
4682+
4683+
assertFileContains(
4684+
Paths.get(outputPath + "/src/main/kotlin/org/openapitools/api/PingApi.kt"),
4685+
"@Deprecated"
4686+
);
4687+
}
4688+
4689+
@Test
4690+
public void testDeprecatedAnnotationOnController() throws IOException {
4691+
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
4692+
output.deleteOnExit();
4693+
String outputPath = output.getAbsolutePath().replace('\\', '/');
4694+
4695+
KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen();
4696+
codegen.setOutputDir(output.getAbsolutePath());
4697+
codegen.additionalProperties().put(CodegenConstants.API_PACKAGE, "org.openapitools.api");
4698+
4699+
new DefaultGenerator().opts(new ClientOptInput()
4700+
.openAPI(TestUtils.parseSpec("src/test/resources/3_0/kotlin/support-deprecated-api.yaml"))
4701+
.config(codegen))
4702+
.generate();
4703+
4704+
assertFileContains(
4705+
Paths.get(outputPath + "/src/main/kotlin/org/openapitools/api/PingApiController.kt"),
4706+
"@Deprecated"
4707+
);
4708+
}
46664709
}
46674710

46684711

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
openapi: "3.0.0"
2+
info:
3+
title: Verify @Deprecated annotation
4+
version: "1.0"
5+
6+
paths:
7+
8+
/ping:
9+
get:
10+
deprecated: true
11+
operationId: ping
12+
responses:
13+
200:
14+
description: OK

0 commit comments

Comments
 (0)