Add vendorExtensions.x-class-extra-annotation to oneOf interfaces (#22020)

This commit is contained in:
jpfinne 2025-09-25 09:40:12 +02:00 committed by GitHub
parent 258d971f42
commit 89edad5b8a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 74 additions and 1 deletions

View File

@ -1,4 +1,7 @@
{{>additionalOneOfTypeAnnotations}}{{>generatedAnnotation}}{{>typeInfoAnnotation}}{{>xmlAnnotation}}
{{#vendorExtensions.x-class-extra-annotation}}
{{{vendorExtensions.x-class-extra-annotation}}}
{{/vendorExtensions.x-class-extra-annotation}}
public {{>sealed}}interface {{classname}} {{#vendorExtensions.x-implements}}{{#-first}}extends {{{.}}}{{/-first}}{{^-first}}, {{{.}}}{{/-first}}{{/vendorExtensions.x-implements}}{{>permits}}{
{{#discriminator}}
public {{propertyType}} {{propertyGetter}}();

View File

@ -13,7 +13,8 @@
@JsonSubTypes.Type(value = {{classname}}.class){{^-last}}, {{/-last}}
{{/interfaceModels}}
})
{{/useDeductionForOneOfInterfaces}}
{{/useDeductionForOneOfInterfaces}}{{#vendorExtensions.x-class-extra-annotation}}{{{vendorExtensions.x-class-extra-annotation}}}
{{/vendorExtensions.x-class-extra-annotation}}
{{/discriminator}}
{{>generatedAnnotation}}

View File

@ -3982,4 +3982,21 @@ public class JavaClientCodegenTest {
}
assertTrue(speciesSeen);
}
@Test
public void testOneOfClassWithAnnotation() throws IOException {
final Map<String, File> files = generateFromContract("src/test/resources/3_0/java/oneOf-with-annotations.yaml", RESTCLIENT);
JavaFileAssert.assertThat(files.get("Fruit.java"))
.isNormalClass()
.assertTypeAnnotations().containsWithName("SuppressWarnings");
}
@Test
public void testOneOfInterfaceWithAnnotation() throws IOException {
final Map<String, File> files = generateFromContract("src/test/resources/3_0/java/oneOf-with-annotations.yaml", RESTCLIENT,
Map.of(USE_ONE_OF_INTERFACES, "true"));
JavaFileAssert.assertThat(files.get("Fruit.java"))
.isInterface()
.assertTypeAnnotations().containsWithName("SuppressWarnings");
}
}

View File

@ -5730,4 +5730,12 @@ public class SpringCodegenTest {
javaFileAssert
.hasImports("java.util.concurrent.atomic.AtomicInteger");
}
@Test
public void testOneOfInterfaceWithAnnotation() throws IOException {
final Map<String, File> files = generateFromContract("src/test/resources/3_0/java/oneOf-with-annotations.yaml", SPRING_BOOT);
JavaFileAssert.assertThat(files.get("Fruit.java"))
.isInterface()
.assertTypeAnnotations().containsWithName("SuppressWarnings");
}
}

View File

@ -0,0 +1,44 @@
openapi: 3.0.1
info:
title: fruity
version: 0.0.1
paths:
/:
get:
responses:
'200':
description: desc
content:
application/json:
schema:
$ref: '#/components/schemas/fruit'
components:
schemas:
fruit:
title: fruit
x-class-extra-annotation: '@SuppressWarnings("unchecked")'
properties:
color:
type: string
oneOf:
- $ref: '#/components/schemas/apple'
- $ref: '#/components/schemas/banana'
- $ref: '#/components/schemas/orange'
apple:
title: apple
type: object
properties:
kind:
type: string
banana:
title: banana
type: object
properties:
count:
type: number
orange:
title: orange
type: object
properties:
sweet:
type: boolean