Skip to content

Commit 89edad5

Browse files
authored
Add vendorExtensions.x-class-extra-annotation to oneOf interfaces (OpenAPITools#22020)
1 parent 258d971 commit 89edad5

File tree

5 files changed

+74
-1
lines changed

5 files changed

+74
-1
lines changed

modules/openapi-generator/src/main/resources/Java/oneof_interface.mustache

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
{{>additionalOneOfTypeAnnotations}}{{>generatedAnnotation}}{{>typeInfoAnnotation}}{{>xmlAnnotation}}
2+
{{#vendorExtensions.x-class-extra-annotation}}
3+
{{{vendorExtensions.x-class-extra-annotation}}}
4+
{{/vendorExtensions.x-class-extra-annotation}}
25
public {{>sealed}}interface {{classname}} {{#vendorExtensions.x-implements}}{{#-first}}extends {{{.}}}{{/-first}}{{^-first}}, {{{.}}}{{/-first}}{{/vendorExtensions.x-implements}}{{>permits}}{
36
{{#discriminator}}
47
public {{propertyType}} {{propertyGetter}}();

modules/openapi-generator/src/main/resources/JavaSpring/oneof_interface.mustache

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
@JsonSubTypes.Type(value = {{classname}}.class){{^-last}}, {{/-last}}
1414
{{/interfaceModels}}
1515
})
16-
{{/useDeductionForOneOfInterfaces}}
16+
{{/useDeductionForOneOfInterfaces}}{{#vendorExtensions.x-class-extra-annotation}}{{{vendorExtensions.x-class-extra-annotation}}}
17+
{{/vendorExtensions.x-class-extra-annotation}}
1718
{{/discriminator}}
1819
{{>generatedAnnotation}}
1920

modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaClientCodegenTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3982,4 +3982,21 @@ public void oneOfWithInnerModelTest() {
39823982
}
39833983
assertTrue(speciesSeen);
39843984
}
3985+
3986+
@Test
3987+
public void testOneOfClassWithAnnotation() throws IOException {
3988+
final Map<String, File> files = generateFromContract("src/test/resources/3_0/java/oneOf-with-annotations.yaml", RESTCLIENT);
3989+
JavaFileAssert.assertThat(files.get("Fruit.java"))
3990+
.isNormalClass()
3991+
.assertTypeAnnotations().containsWithName("SuppressWarnings");
3992+
}
3993+
3994+
@Test
3995+
public void testOneOfInterfaceWithAnnotation() throws IOException {
3996+
final Map<String, File> files = generateFromContract("src/test/resources/3_0/java/oneOf-with-annotations.yaml", RESTCLIENT,
3997+
Map.of(USE_ONE_OF_INTERFACES, "true"));
3998+
JavaFileAssert.assertThat(files.get("Fruit.java"))
3999+
.isInterface()
4000+
.assertTypeAnnotations().containsWithName("SuppressWarnings");
4001+
}
39854002
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5730,4 +5730,12 @@ public void testHasRestControllerDoesNotHaveController_issue21156() throws IOExc
57305730
javaFileAssert
57315731
.hasImports("java.util.concurrent.atomic.AtomicInteger");
57325732
}
5733+
5734+
@Test
5735+
public void testOneOfInterfaceWithAnnotation() throws IOException {
5736+
final Map<String, File> files = generateFromContract("src/test/resources/3_0/java/oneOf-with-annotations.yaml", SPRING_BOOT);
5737+
JavaFileAssert.assertThat(files.get("Fruit.java"))
5738+
.isInterface()
5739+
.assertTypeAnnotations().containsWithName("SuppressWarnings");
5740+
}
57335741
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
openapi: 3.0.1
2+
info:
3+
title: fruity
4+
version: 0.0.1
5+
paths:
6+
/:
7+
get:
8+
responses:
9+
'200':
10+
description: desc
11+
content:
12+
application/json:
13+
schema:
14+
$ref: '#/components/schemas/fruit'
15+
components:
16+
schemas:
17+
fruit:
18+
title: fruit
19+
x-class-extra-annotation: '@SuppressWarnings("unchecked")'
20+
properties:
21+
color:
22+
type: string
23+
oneOf:
24+
- $ref: '#/components/schemas/apple'
25+
- $ref: '#/components/schemas/banana'
26+
- $ref: '#/components/schemas/orange'
27+
apple:
28+
title: apple
29+
type: object
30+
properties:
31+
kind:
32+
type: string
33+
banana:
34+
title: banana
35+
type: object
36+
properties:
37+
count:
38+
type: number
39+
orange:
40+
title: orange
41+
type: object
42+
properties:
43+
sweet:
44+
type: boolean

0 commit comments

Comments
 (0)