Skip to content

Commit

Permalink
Tests to check content type between Services and OpenAPI
Browse files Browse the repository at this point in the history
Signed-off-by: Phillip Kruger <phillip.kruger@gmail.com>
  • Loading branch information
phillip-kruger committed Oct 31, 2023
1 parent 3149ece commit add04db
Show file tree
Hide file tree
Showing 65 changed files with 7,564 additions and 7 deletions.
2 changes: 1 addition & 1 deletion bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<smallrye-config.version>3.4.1</smallrye-config.version>
<smallrye-health.version>4.0.4</smallrye-health.version>
<smallrye-metrics.version>4.0.0</smallrye-metrics.version>
<smallrye-open-api.version>3.6.2</smallrye-open-api.version>
<smallrye-open-api.version>3.7.0</smallrye-open-api.version>
<smallrye-graphql.version>2.5.1</smallrye-graphql.version>
<smallrye-opentracing.version>3.0.3</smallrye-opentracing.version>
<smallrye-fault-tolerance.version>6.2.6</smallrye-fault-tolerance.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ public class SmallRyeOpenApiProcessor {
private static final String VERT_X = "Vert.x";

static {
System.setProperty(io.smallrye.openapi.api.constants.OpenApiConstants.DEFAULT_PRODUCES_STREAMING,
"application/octet-stream");
System.setProperty(io.smallrye.openapi.api.constants.OpenApiConstants.DEFAULT_CONSUMES_STREAMING,
"application/octet-stream");
System.setProperty(io.smallrye.openapi.api.constants.OpenApiConstants.DEFAULT_PRODUCES, "application/json");
System.setProperty(io.smallrye.openapi.api.constants.OpenApiConstants.DEFAULT_CONSUMES, "application/json");
System.setProperty(io.smallrye.openapi.api.constants.OpenApiConstants.DEFAULT_PRODUCES_PRIMITIVES, "text/plain");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ public void testOpenApiPathAccessResource() {
Matchers.containsString("#/components/schemas/Greeting"));

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ public CompletionStage<String> cs() {

@GET
@Path("/rx")
@Produces("text/plain")
public Single<String> rx() {
return Single.just("Hello");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
public class OpenApiTestCase {

private static final String DEFAULT_MEDIA_TYPE = "application/json";
private static final String DEFAULT_MEDIA_TYPE_PRIMITAVE = "text/plain";
private static final String DEFAULT_MEDIA_TYPE_PRIMITIVE = "text/plain";

@TestHTTPResource("q/openapi")
URL uri;
Expand Down Expand Up @@ -64,10 +64,10 @@ public void testOpenAPIJSON() throws Exception {
// test RESTEasy extensions

JsonObject schemasObj = obj.getJsonObject("components").getJsonObject("schemas");
String testSchemaType = schemaType("200", DEFAULT_MEDIA_TYPE_PRIMITAVE,
String testSchemaType = schemaType("200", DEFAULT_MEDIA_TYPE_PRIMITIVE,
testObj.getJsonObject("get").getJsonObject("responses"),
schemasObj);
String rxSchemaType = schemaType("200", DEFAULT_MEDIA_TYPE,
String rxSchemaType = schemaType("200", DEFAULT_MEDIA_TYPE_PRIMITIVE,
injectionObj.getJsonObject("get").getJsonObject("responses"),
schemasObj);
// make sure String, CompletionStage<String> and Single<String> are detected the same
Expand All @@ -76,7 +76,8 @@ public void testOpenAPIJSON() throws Exception {
"Normal and RX/Single have same schema");
JsonObject csObj = paths.getJsonObject("/test/cs");
Assertions.assertEquals(testSchemaType,
schemaType("200", DEFAULT_MEDIA_TYPE, csObj.getJsonObject("get").getJsonObject("responses"), schemasObj),
schemaType("200", DEFAULT_MEDIA_TYPE_PRIMITIVE, csObj.getJsonObject("get").getJsonObject("responses"),
schemasObj),
"Normal and RX/CS have same schema");

JsonObject paramsObj = paths.getJsonObject("/test/params/{path}");
Expand All @@ -90,7 +91,7 @@ public void testOpenAPIJSON() throws Exception {
Assertions.assertEquals(1, keys.size());
Assertions.assertEquals("get", keys.iterator().next());

String uniSchemaType = schemaType("200", DEFAULT_MEDIA_TYPE_PRIMITAVE,
String uniSchemaType = schemaType("200", DEFAULT_MEDIA_TYPE_PRIMITIVE,
uniObj.getJsonObject("get").getJsonObject("responses"),
schemasObj);
// make sure String, CompletionStage<String> and Uni<String> are detected the same
Expand Down
171 changes: 171 additions & 0 deletions integration-tests/openapi/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>quarkus-integration-tests-parent</artifactId>
<groupId>io.quarkus</groupId>
<version>999-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>quarkus-integration-test-openapi</artifactId>
<name>Quarkus - Integration Tests - OpenAPI</name>
<description>The openapi integration tests module</description>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-openapi</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-reactive-jackson</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-reactive-routes</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-spring-web</artifactId>
</dependency>

<!-- test dependencies -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5-component</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>

<!-- Minimal test dependencies to *-deployment artifacts for consistent build order -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-reactive-routes-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-reactive-jackson-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-openapi-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-spring-web-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<runOrder>alphabetical</runOrder>
</configuration>
</plugin>
</plugins>
</build>

<profiles>

<profile>
<id>native-image</id>
<activation>
<property>
<name>native</name>
</property>
</activation>
<!-- add some custom config, the rest comes from parent -->
<properties>
<quarkus.native.add-all-charsets>true</quarkus.native.add-all-charsets>
</properties>
</profile>

<profile>
<id>no-native</id>
<activation>
<property>
<name>!native</name>
</property>
</activation>
<!-- these properties must not be defined in the general properties,
otherwise the native profile in the parent pom is not able to override them -->
<properties>
<quarkus.package.type>uber-jar</quarkus.package.type>
</properties>
</profile>

</profiles>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package io.quarkus.it.openapi;

public class Greeting {
private int id;
private String salutation;

public Greeting() {

}

public Greeting(int id, String salutation) {
this.id = id;
this.salutation = salutation;
}

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

public String getSalutation() {
return salutation;
}

public void setSalutation(String salutation) {
this.salutation = salutation;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package io.quarkus.it.openapi.jaxrs;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;

import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;

import org.jboss.resteasy.reactive.RestResponse;

import io.smallrye.mutiny.Uni;

@Path("/jax-rs/defaultContentType")
public class BigDecimalResource {
@GET
@Path("/justBigDecimal")
public BigDecimal justBigDecimal() {
return new BigDecimal("0");
}

@POST
@Path("/justBigDecimal")
public BigDecimal justBigDecimal(BigDecimal body) {
return body;
}

@GET
@Path("/restResponseBigDecimal")
public RestResponse<BigDecimal> restResponseBigDecimal() {
return RestResponse.ok(new BigDecimal("0"));
}

@POST
@Path("/restResponseBigDecimal")
public RestResponse<BigDecimal> restResponseBigDecimal(BigDecimal body) {
return RestResponse.ok(body);
}

@GET
@Path("/optionalBigDecimal")
public Optional<BigDecimal> optionalBigDecimal() {
return Optional.of(new BigDecimal("0"));
}

@POST
@Path("/optionalBigDecimal")
public Optional<BigDecimal> optionalBigDecimal(Optional<BigDecimal> body) {
return body;
}

@GET
@Path("/uniBigDecimal")
public Uni<BigDecimal> uniBigDecimal() {
return Uni.createFrom().item(new BigDecimal("0"));
}

@GET
@Path("/completionStageBigDecimal")
public CompletionStage<BigDecimal> completionStageBigDecimal() {
return CompletableFuture.completedStage(new BigDecimal("0"));
}

@GET
@Path("/completedFutureBigDecimal")
public CompletableFuture<BigDecimal> completedFutureBigDecimal() {
return CompletableFuture.completedFuture(new BigDecimal("0"));
}

@GET
@Path("/listBigDecimal")
public List<BigDecimal> listBigDecimal() {
return Arrays.asList(new BigDecimal[] { new BigDecimal("0") });
}

@POST
@Path("/listBigDecimal")
public List<BigDecimal> listBigDecimal(List<BigDecimal> body) {
return body;
}

@GET
@Path("/arrayBigDecimal")
public BigDecimal[] arrayBigDecimal() {
return new BigDecimal[] { new BigDecimal("0") };
}

@POST
@Path("/arrayBigDecimal")
public BigDecimal[] arrayBigDecimal(BigDecimal[] body) {
return body;
}

}
Loading

0 comments on commit add04db

Please sign in to comment.