Skip to content

Commit

Permalink
Create seperate module for swagger-java17 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
micryc committed Oct 4, 2024
1 parent 0e6ddb8 commit b9c9d5b
Show file tree
Hide file tree
Showing 16 changed files with 959 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import io.swagger.v3.core.resolving.v31.model.AnnotatedArray;
import io.swagger.v3.core.resolving.v31.model.ModelWithDependentSchema;
import io.swagger.v3.core.resolving.v31.model.ModelWithOAS31Stuff;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.models.media.Schema;
import org.testng.annotations.Test;
import javax.validation.constraints.DecimalMax;
Expand Down Expand Up @@ -348,70 +347,4 @@ public void setMyField(Number myField) {
this.myField = myField;
}
}

@Test
public void testOAS31JavaRecord() {
String expectedYaml = "JavaRecordWithOAS31Fields:\n" +
" type: object\n" +
" $comment: Random comment at schema level\n" +
" $id: http://yourdomain.com/schemas/myschema.json\n" +
" description: this is model for testing OAS 3.1 Java Record resolving\n" +
" properties:\n" +
" test:\n" +
" type: string\n" +
" isLatest:\n" +
" type: boolean\n" +
" randomList:\n" +
" type: array\n" +
" contains:\n" +
" type: string\n" +
" items:\n" +
" type: string\n" +
" maxContains: 10\n" +
" minContains: 1\n" +
" prefixItems:\n" +
" - type: string\n" +
" unevaluatedItems:\n" +
" type: number\n" +
" Status:\n" +
" type:\n" +
" - string\n" +
" - number\n";

Map<String, Schema> stringSchemaMap = ModelConverters.getInstance(true).readAll(JavaRecordWithOAS31Fields.class);
SerializationMatchers.assertEqualsToYaml31(stringSchemaMap, expectedYaml);
}

@io.swagger.v3.oas.annotations.media.Schema(
$id = "http://yourdomain.com/schemas/myschema.json",
description = "this is model for testing OAS 3.1 Java Record resolving",
$comment = "Random comment at schema level",
types = "object"
)
private record JavaRecordWithOAS31Fields(
String test,
boolean isLatest,
@ArraySchema(
maxContains = 10,
minContains = 1,
contains = @io.swagger.v3.oas.annotations.media.Schema(
types = "string"
),
unevaluatedItems = @io.swagger.v3.oas.annotations.media.Schema(
types = "number"
),
prefixItems = {
@io.swagger.v3.oas.annotations.media.Schema(
types = "string"
)
}
)
List<String> randomList,
@io.swagger.v3.oas.annotations.media.Schema(types = {
"string",
"number"
})
Object Status
){
}
}
91 changes: 91 additions & 0 deletions modules/swagger-java17-support/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-project</artifactId>
<version>2.2.26-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>swagger-java17-support</artifactId>
<packaging>jar</packaging>
<name>swagger-java17-support</name>
<description>Module for Java 17 specific tests</description>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-jaxrs2</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-annotations</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-models</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-multipart</artifactId>
<version>${jersey2-version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
<version>${jersey2-version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<release>17</release>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<maven.compiler.release>17</maven.compiler.release>
</properties>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package io.swagger.v3.java17.Reader;

import io.swagger.v3.java17.matchers.SerializationMatchers;
import io.swagger.v3.java17.resources.JavaRecordWithPathResource;
import io.swagger.v3.java17.resources.OtherJavaRecordWithPathsResource;
import io.swagger.v3.java17.resources.TestControllerWithRecordResource;
import io.swagger.v3.jaxrs2.Reader;
import io.swagger.v3.oas.integration.SwaggerConfiguration;
import io.swagger.v3.oas.models.OpenAPI;
import org.testng.annotations.Test;

import java.util.HashSet;
import java.util.Set;

public class ReaderTest {

@Test
public void TestJavaRecordRef(){
Reader reader = new Reader(new SwaggerConfiguration().openAPI(new OpenAPI()).openAPI31(true));

OpenAPI openAPI = reader.read(TestControllerWithRecordResource.class);
String yaml = "openapi: 3.1.0\n" +
"paths:\n" +
" /v17:\n" +
" post:\n" +
" operationId: opsRecordID\n" +
" responses:\n" +
" default:\n" +
" description: Successful operation\n" +
" content:\n" +
" application/json:\n" +
" schema:\n" +
" $ref: '#/components/schemas/JavaRecordResource'\n" +
"components:\n" +
" schemas:\n" +
" JavaRecordResource:\n" +
" type: object\n" +
" properties:\n" +
" test:\n" +
" type: string\n" +
" description: Testing of Java Record Processing\n" +
" isLatest:\n" +
" type: boolean\n" +
" id:\n" +
" type: string\n" +
" age:\n" +
" type: integer\n" +
" format: int32";
SerializationMatchers.assertEqualsToYaml31(openAPI, yaml);
}

@Test
public void TestSetOfRecords(){
Set<Class<?>> classes = new HashSet<>();
classes.add(JavaRecordWithPathResource.class);
classes.add(OtherJavaRecordWithPathsResource.class);

Reader reader = new Reader(new OpenAPI());
OpenAPI openAPI = reader.read(classes);
String yaml = "openapi: 3.0.1\n" +
"paths:\n" +
" /sample/1:\n" +
" post:\n" +
" description: description 1\n" +
" operationId: id 1\n" +
" responses:\n" +
" default:\n" +
" description: default response\n" +
" content:\n" +
" '*/*': {}\n" +
" /sample/2:\n" +
" post:\n" +
" description: description 2\n" +
" operationId: id 2\n" +
" responses:\n" +
" default:\n" +
" description: default response\n" +
" content:\n" +
" '*/*': {}\n" +
" /sample2:\n" +
" get:\n" +
" description: description\n" +
" operationId: Operation Id\n" +
" responses:\n" +
" default:\n" +
" description: default response\n" +
" content:\n" +
" '*/*': {}\n" +
" security:\n" +
" - security_key:\n" +
" - write:pets\n" +
" - read:pets\n" +
" /sample2/2:\n" +
" get:\n" +
" description: description 2\n" +
" operationId: Operation Id 2\n" +
" responses:\n" +
" default:\n" +
" description: default response\n" +
" content:\n" +
" '*/*': {}\n" +
" security:\n" +
" - security_key2:\n" +
" - write:pets\n" +
" - read:pets";
SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
}
}
Loading

0 comments on commit b9c9d5b

Please sign in to comment.