Skip to content

Instantly share code, notes, and snippets.

@mdjimy
Last active February 17, 2023 23:13
Show Gist options
  • Save mdjimy/2a08b1f9f0eb26485f2794c50df7dd35 to your computer and use it in GitHub Desktop.
Save mdjimy/2a08b1f9f0eb26485f2794c50df7dd35 to your computer and use it in GitHub Desktop.
Regression test for ResolvedSchema containing SystemType Enum with enumsAsRef enabled
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>swagger-bug</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-core-jakarta</artifactId>
<version>2.2.8</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.3.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
</plugin>
</plugins>
</build>
</project>
import io.swagger.v3.core.converter.ModelConverters;
import io.swagger.v3.core.converter.ResolvedSchema;
import io.swagger.v3.core.jackson.ModelResolver;
import io.swagger.v3.oas.models.media.Schema;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.time.DayOfWeek;
import java.util.Arrays;
class SystemTypeEnumAsRefTest {
@Test
void testRefSchemaForSystemTypeEnumIsResolved() {
ModelResolver.enumsAsRef = true;
ResolvedSchema schema = ModelConverters.getInstance().readAllAsResolvedSchema(DayOfWeek.class);
Assertions.assertTrue(schema.referencedSchemas.containsKey("DayOfWeek"));
Schema<?> enumSchema = schema.referencedSchemas.get("DayOfWeek");
Assertions.assertEquals(enumSchema.getType(), "string");
Assertions.assertEquals(
enumSchema.getEnum(),
Arrays.asList(
"MONDAY",
"TUESDAY",
"WEDNESDAY",
"THURSDAY",
"FRIDAY",
"SATURDAY",
"SUNDAY"
)
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment