Skip to content

Commit

Permalink
Add test case for record with name from implemented interface
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Edgar <michael@xlate.io>
  • Loading branch information
MikeEdgar committed Dec 20, 2024
1 parent 76e7273 commit 4f949dd
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
1 change: 1 addition & 0 deletions testsuite/data/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@
<configuration>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<systemPropertyVariables>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
<java.util.logging.config.file>${project.build.testOutputDirectory}/logging.properties</java.util.logging.config.file>
<maven.home>${maven.home}</maven.home>
</systemPropertyVariables>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
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;
import java.nio.file.Files;
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;
Expand All @@ -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;
Expand Down Expand Up @@ -119,6 +132,42 @@ void testKotlinResourceWithUnwrappedFlowSSE() throws Exception {
assertJsonEquals("components.schemas.kotlin-flow-unwrapped.json", result);
}

interface Named<T> {
@JsonProperty("nombre")
T name();
}

@Test
void testRecordInheritsInterfacePropertyName() throws Exception {
@Schema(name = "Widget")
record Widget(String name, int number) implements Named<String> {
}

@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")) {
Expand Down

0 comments on commit 4f949dd

Please sign in to comment.