Skip to content

Commit 24a77b8

Browse files
Merge pull request #36514 from phillip-kruger/content-type-tests
Tests to check content type between Services and OpenAPI
2 parents 58bc0c4 + 3dad6f5 commit 24a77b8

File tree

65 files changed

+7564
-7
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+7564
-7
lines changed

bom/application/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
<smallrye-config.version>3.4.1</smallrye-config.version>
5555
<smallrye-health.version>4.0.4</smallrye-health.version>
5656
<smallrye-metrics.version>4.0.0</smallrye-metrics.version>
57-
<smallrye-open-api.version>3.6.2</smallrye-open-api.version>
57+
<smallrye-open-api.version>3.7.0</smallrye-open-api.version>
5858
<smallrye-graphql.version>2.5.1</smallrye-graphql.version>
5959
<smallrye-opentracing.version>3.0.3</smallrye-opentracing.version>
6060
<smallrye-fault-tolerance.version>6.2.6</smallrye-fault-tolerance.version>

extensions/smallrye-openapi/deployment/src/main/java/io/quarkus/smallrye/openapi/deployment/SmallRyeOpenApiProcessor.java

+4
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@ public class SmallRyeOpenApiProcessor {
162162
private static final String VERT_X = "Vert.x";
163163

164164
static {
165+
System.setProperty(io.smallrye.openapi.api.constants.OpenApiConstants.DEFAULT_PRODUCES_STREAMING,
166+
"application/octet-stream");
167+
System.setProperty(io.smallrye.openapi.api.constants.OpenApiConstants.DEFAULT_CONSUMES_STREAMING,
168+
"application/octet-stream");
165169
System.setProperty(io.smallrye.openapi.api.constants.OpenApiConstants.DEFAULT_PRODUCES, "application/json");
166170
System.setProperty(io.smallrye.openapi.api.constants.OpenApiConstants.DEFAULT_CONSUMES, "application/json");
167171
System.setProperty(io.smallrye.openapi.api.constants.OpenApiConstants.DEFAULT_PRODUCES_PRIMITIVES, "text/plain");

extensions/smallrye-openapi/deployment/src/test/java/io/quarkus/smallrye/openapi/test/jaxrs/DefaultContentTypeTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ public void testOpenApiPathAccessResource() {
3434
Matchers.containsString("#/components/schemas/Greeting"));
3535

3636
}
37-
}
37+
}

integration-tests/main/src/main/java/io/quarkus/it/rest/TestResource.java

+1
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ public CompletionStage<String> cs() {
150150

151151
@GET
152152
@Path("/rx")
153+
@Produces("text/plain")
153154
public Single<String> rx() {
154155
return Single.just("Hello");
155156
}

integration-tests/main/src/test/java/io/quarkus/it/main/OpenApiTestCase.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
public class OpenApiTestCase {
2323

2424
private static final String DEFAULT_MEDIA_TYPE = "application/json";
25-
private static final String DEFAULT_MEDIA_TYPE_PRIMITAVE = "text/plain";
25+
private static final String DEFAULT_MEDIA_TYPE_PRIMITIVE = "text/plain";
2626

2727
@TestHTTPResource("q/openapi")
2828
URL uri;
@@ -64,10 +64,10 @@ public void testOpenAPIJSON() throws Exception {
6464
// test RESTEasy extensions
6565

6666
JsonObject schemasObj = obj.getJsonObject("components").getJsonObject("schemas");
67-
String testSchemaType = schemaType("200", DEFAULT_MEDIA_TYPE_PRIMITAVE,
67+
String testSchemaType = schemaType("200", DEFAULT_MEDIA_TYPE_PRIMITIVE,
6868
testObj.getJsonObject("get").getJsonObject("responses"),
6969
schemasObj);
70-
String rxSchemaType = schemaType("200", DEFAULT_MEDIA_TYPE,
70+
String rxSchemaType = schemaType("200", DEFAULT_MEDIA_TYPE_PRIMITIVE,
7171
injectionObj.getJsonObject("get").getJsonObject("responses"),
7272
schemasObj);
7373
// make sure String, CompletionStage<String> and Single<String> are detected the same
@@ -76,7 +76,8 @@ public void testOpenAPIJSON() throws Exception {
7676
"Normal and RX/Single have same schema");
7777
JsonObject csObj = paths.getJsonObject("/test/cs");
7878
Assertions.assertEquals(testSchemaType,
79-
schemaType("200", DEFAULT_MEDIA_TYPE, csObj.getJsonObject("get").getJsonObject("responses"), schemasObj),
79+
schemaType("200", DEFAULT_MEDIA_TYPE_PRIMITIVE, csObj.getJsonObject("get").getJsonObject("responses"),
80+
schemasObj),
8081
"Normal and RX/CS have same schema");
8182

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

93-
String uniSchemaType = schemaType("200", DEFAULT_MEDIA_TYPE_PRIMITAVE,
94+
String uniSchemaType = schemaType("200", DEFAULT_MEDIA_TYPE_PRIMITIVE,
9495
uniObj.getJsonObject("get").getJsonObject("responses"),
9596
schemasObj);
9697
// make sure String, CompletionStage<String> and Uni<String> are detected the same

integration-tests/openapi/pom.xml

+171
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>quarkus-integration-tests-parent</artifactId>
7+
<groupId>io.quarkus</groupId>
8+
<version>999-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>quarkus-integration-test-openapi</artifactId>
13+
<name>Quarkus - Integration Tests - OpenAPI</name>
14+
<description>The openapi integration tests module</description>
15+
16+
<dependencies>
17+
<dependency>
18+
<groupId>io.quarkus</groupId>
19+
<artifactId>quarkus-smallrye-openapi</artifactId>
20+
</dependency>
21+
<dependency>
22+
<groupId>io.quarkus</groupId>
23+
<artifactId>quarkus-resteasy-reactive-jackson</artifactId>
24+
</dependency>
25+
<dependency>
26+
<groupId>io.quarkus</groupId>
27+
<artifactId>quarkus-reactive-routes</artifactId>
28+
</dependency>
29+
<dependency>
30+
<groupId>io.quarkus</groupId>
31+
<artifactId>quarkus-spring-web</artifactId>
32+
</dependency>
33+
34+
<!-- test dependencies -->
35+
<dependency>
36+
<groupId>io.quarkus</groupId>
37+
<artifactId>quarkus-junit5</artifactId>
38+
<scope>test</scope>
39+
</dependency>
40+
<dependency>
41+
<groupId>io.quarkus</groupId>
42+
<artifactId>quarkus-junit5-component</artifactId>
43+
<scope>test</scope>
44+
</dependency>
45+
<dependency>
46+
<groupId>io.rest-assured</groupId>
47+
<artifactId>rest-assured</artifactId>
48+
<scope>test</scope>
49+
</dependency>
50+
<dependency>
51+
<groupId>org.assertj</groupId>
52+
<artifactId>assertj-core</artifactId>
53+
<scope>test</scope>
54+
</dependency>
55+
56+
<!-- Minimal test dependencies to *-deployment artifacts for consistent build order -->
57+
<dependency>
58+
<groupId>io.quarkus</groupId>
59+
<artifactId>quarkus-reactive-routes-deployment</artifactId>
60+
<version>${project.version}</version>
61+
<type>pom</type>
62+
<scope>test</scope>
63+
<exclusions>
64+
<exclusion>
65+
<groupId>*</groupId>
66+
<artifactId>*</artifactId>
67+
</exclusion>
68+
</exclusions>
69+
</dependency>
70+
<dependency>
71+
<groupId>io.quarkus</groupId>
72+
<artifactId>quarkus-resteasy-reactive-jackson-deployment</artifactId>
73+
<version>${project.version}</version>
74+
<type>pom</type>
75+
<scope>test</scope>
76+
<exclusions>
77+
<exclusion>
78+
<groupId>*</groupId>
79+
<artifactId>*</artifactId>
80+
</exclusion>
81+
</exclusions>
82+
</dependency>
83+
<dependency>
84+
<groupId>io.quarkus</groupId>
85+
<artifactId>quarkus-smallrye-openapi-deployment</artifactId>
86+
<version>${project.version}</version>
87+
<type>pom</type>
88+
<scope>test</scope>
89+
<exclusions>
90+
<exclusion>
91+
<groupId>*</groupId>
92+
<artifactId>*</artifactId>
93+
</exclusion>
94+
</exclusions>
95+
</dependency>
96+
<dependency>
97+
<groupId>io.quarkus</groupId>
98+
<artifactId>quarkus-spring-web-deployment</artifactId>
99+
<version>${project.version}</version>
100+
<type>pom</type>
101+
<scope>test</scope>
102+
<exclusions>
103+
<exclusion>
104+
<groupId>*</groupId>
105+
<artifactId>*</artifactId>
106+
</exclusion>
107+
</exclusions>
108+
</dependency>
109+
</dependencies>
110+
111+
<build>
112+
<resources>
113+
<resource>
114+
<directory>src/main/resources</directory>
115+
<filtering>true</filtering>
116+
</resource>
117+
</resources>
118+
<plugins>
119+
<plugin>
120+
<groupId>io.quarkus</groupId>
121+
<artifactId>quarkus-maven-plugin</artifactId>
122+
<executions>
123+
<execution>
124+
<goals>
125+
<goal>build</goal>
126+
</goals>
127+
</execution>
128+
</executions>
129+
</plugin>
130+
<plugin>
131+
<groupId>org.apache.maven.plugins</groupId>
132+
<artifactId>maven-surefire-plugin</artifactId>
133+
<configuration>
134+
<runOrder>alphabetical</runOrder>
135+
</configuration>
136+
</plugin>
137+
</plugins>
138+
</build>
139+
140+
<profiles>
141+
142+
<profile>
143+
<id>native-image</id>
144+
<activation>
145+
<property>
146+
<name>native</name>
147+
</property>
148+
</activation>
149+
<!-- add some custom config, the rest comes from parent -->
150+
<properties>
151+
<quarkus.native.add-all-charsets>true</quarkus.native.add-all-charsets>
152+
</properties>
153+
</profile>
154+
155+
<profile>
156+
<id>no-native</id>
157+
<activation>
158+
<property>
159+
<name>!native</name>
160+
</property>
161+
</activation>
162+
<!-- these properties must not be defined in the general properties,
163+
otherwise the native profile in the parent pom is not able to override them -->
164+
<properties>
165+
<quarkus.package.type>uber-jar</quarkus.package.type>
166+
</properties>
167+
</profile>
168+
169+
</profiles>
170+
171+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package io.quarkus.it.openapi;
2+
3+
public class Greeting {
4+
private int id;
5+
private String salutation;
6+
7+
public Greeting() {
8+
9+
}
10+
11+
public Greeting(int id, String salutation) {
12+
this.id = id;
13+
this.salutation = salutation;
14+
}
15+
16+
public int getId() {
17+
return id;
18+
}
19+
20+
public void setId(int id) {
21+
this.id = id;
22+
}
23+
24+
public String getSalutation() {
25+
return salutation;
26+
}
27+
28+
public void setSalutation(String salutation) {
29+
this.salutation = salutation;
30+
}
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
package io.quarkus.it.openapi.jaxrs;
2+
3+
import java.math.BigDecimal;
4+
import java.util.Arrays;
5+
import java.util.List;
6+
import java.util.Optional;
7+
import java.util.concurrent.CompletableFuture;
8+
import java.util.concurrent.CompletionStage;
9+
10+
import jakarta.ws.rs.GET;
11+
import jakarta.ws.rs.POST;
12+
import jakarta.ws.rs.Path;
13+
14+
import org.jboss.resteasy.reactive.RestResponse;
15+
16+
import io.smallrye.mutiny.Uni;
17+
18+
@Path("/jax-rs/defaultContentType")
19+
public class BigDecimalResource {
20+
@GET
21+
@Path("/justBigDecimal")
22+
public BigDecimal justBigDecimal() {
23+
return new BigDecimal("0");
24+
}
25+
26+
@POST
27+
@Path("/justBigDecimal")
28+
public BigDecimal justBigDecimal(BigDecimal body) {
29+
return body;
30+
}
31+
32+
@GET
33+
@Path("/restResponseBigDecimal")
34+
public RestResponse<BigDecimal> restResponseBigDecimal() {
35+
return RestResponse.ok(new BigDecimal("0"));
36+
}
37+
38+
@POST
39+
@Path("/restResponseBigDecimal")
40+
public RestResponse<BigDecimal> restResponseBigDecimal(BigDecimal body) {
41+
return RestResponse.ok(body);
42+
}
43+
44+
@GET
45+
@Path("/optionalBigDecimal")
46+
public Optional<BigDecimal> optionalBigDecimal() {
47+
return Optional.of(new BigDecimal("0"));
48+
}
49+
50+
@POST
51+
@Path("/optionalBigDecimal")
52+
public Optional<BigDecimal> optionalBigDecimal(Optional<BigDecimal> body) {
53+
return body;
54+
}
55+
56+
@GET
57+
@Path("/uniBigDecimal")
58+
public Uni<BigDecimal> uniBigDecimal() {
59+
return Uni.createFrom().item(new BigDecimal("0"));
60+
}
61+
62+
@GET
63+
@Path("/completionStageBigDecimal")
64+
public CompletionStage<BigDecimal> completionStageBigDecimal() {
65+
return CompletableFuture.completedStage(new BigDecimal("0"));
66+
}
67+
68+
@GET
69+
@Path("/completedFutureBigDecimal")
70+
public CompletableFuture<BigDecimal> completedFutureBigDecimal() {
71+
return CompletableFuture.completedFuture(new BigDecimal("0"));
72+
}
73+
74+
@GET
75+
@Path("/listBigDecimal")
76+
public List<BigDecimal> listBigDecimal() {
77+
return Arrays.asList(new BigDecimal[] { new BigDecimal("0") });
78+
}
79+
80+
@POST
81+
@Path("/listBigDecimal")
82+
public List<BigDecimal> listBigDecimal(List<BigDecimal> body) {
83+
return body;
84+
}
85+
86+
@GET
87+
@Path("/arrayBigDecimal")
88+
public BigDecimal[] arrayBigDecimal() {
89+
return new BigDecimal[] { new BigDecimal("0") };
90+
}
91+
92+
@POST
93+
@Path("/arrayBigDecimal")
94+
public BigDecimal[] arrayBigDecimal(BigDecimal[] body) {
95+
return body;
96+
}
97+
98+
}

0 commit comments

Comments
 (0)