From f666b8cacab92c54692d05270a0a4bd813060d4d Mon Sep 17 00:00:00 2001 From: Michael Edgar Date: Wed, 18 Dec 2024 19:43:53 -0500 Subject: [PATCH] Add test case for record with name from implemented interface Signed-off-by: Michael Edgar --- testsuite/data/pom.xml | 1 + .../testdata/QuarkusAnnotationScanIT.java | 49 +++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/testsuite/data/pom.xml b/testsuite/data/pom.xml index 2d91decb3..3233fb23d 100644 --- a/testsuite/data/pom.xml +++ b/testsuite/data/pom.xml @@ -300,6 +300,7 @@ true + org.jboss.logmanager.LogManager ${project.build.testOutputDirectory}/logging.properties ${maven.home} diff --git a/testsuite/data/src/test/java/io/smallrye/openapi/testdata/QuarkusAnnotationScanIT.java b/testsuite/data/src/test/java/io/smallrye/openapi/testdata/QuarkusAnnotationScanIT.java index 96c3d03d2..858ce4f49 100644 --- a/testsuite/data/src/test/java/io/smallrye/openapi/testdata/QuarkusAnnotationScanIT.java +++ b/testsuite/data/src/test/java/io/smallrye/openapi/testdata/QuarkusAnnotationScanIT.java @@ -1,5 +1,8 @@ package io.smallrye.openapi.testdata; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + import java.io.IOException; import java.io.InputStream; import java.net.URL; @@ -7,12 +10,19 @@ import java.nio.file.Paths; import java.util.Collections; import java.util.HashMap; +import java.util.List; import java.util.Map; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; + import org.eclipse.microprofile.config.Config; import org.eclipse.microprofile.config.spi.ConfigSource; import org.eclipse.microprofile.openapi.OASConfig; +import org.eclipse.microprofile.openapi.annotations.Operation; +import org.eclipse.microprofile.openapi.annotations.media.Schema; import org.eclipse.microprofile.openapi.models.OpenAPI; +import org.eclipse.microprofile.openapi.models.media.Schema.SchemaType; import org.jboss.jandex.Index; import org.jboss.jandex.IndexReader; import org.jboss.logging.Logger; @@ -21,9 +31,12 @@ import org.junit.jupiter.params.provider.ValueSource; import org.skyscreamer.jsonassert.JSONAssert; +import com.fasterxml.jackson.annotation.JsonProperty; + import io.smallrye.config.PropertiesConfigSource; import io.smallrye.config.SmallRyeConfigBuilder; import io.smallrye.openapi.api.OpenApiConfig; +import io.smallrye.openapi.api.SmallRyeOpenAPI; import io.smallrye.openapi.runtime.OpenApiProcessor; import io.smallrye.openapi.runtime.io.Format; import io.smallrye.openapi.runtime.io.OpenApiSerializer; @@ -119,6 +132,42 @@ void testKotlinResourceWithUnwrappedFlowSSE() throws Exception { assertJsonEquals("components.schemas.kotlin-flow-unwrapped.json", result); } + interface Named { + @JsonProperty("nombre") + T name(); + } + + @Test + void testRecordInheritsInterfacePropertyName() throws Exception { + @Schema(name = "Widget") + record Widget(String name, int number) implements Named { + } + + @Path("widgets") + class WidgetsResource { + + @GET + @Operation(summary = "Get a widget") + public Widget get() { + return new Widget("foo", 42); + } + } + + Index index = Index.of(Named.class, Widget.class, WidgetsResource.class); + OpenAPI result = SmallRyeOpenAPI.builder() + .withIndex(index) + .enableModelReader(false) + .enableStandardFilter(false) + .enableStandardStaticFiles(false) + .build() + .model(); + + printToConsole(result); + var nameModel = result.getComponents().getSchemas().get("Widget").getProperties().get("nombre"); + assertNotNull(nameModel); + assertEquals(List.of(SchemaType.STRING), nameModel.getType()); + } + @Test void testSyntheticClassesAndInterfacesIgnoredByDefault() throws Exception { try (InputStream source = getClass().getResourceAsStream("/smallrye-open-api-testsuite-data.idx")) {