Skip to content

Commit 9fc4b2a

Browse files
Merge pull request quarkusio#36198 from phillip-kruger/openapi-default-content-type
OpenAPI different default content type for pojo return and primitives
2 parents 1c87e6f + 29f26d3 commit 9fc4b2a

File tree

8 files changed

+74
-4
lines changed

8 files changed

+74
-4
lines changed

bom/application/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
<smallrye-config.version>3.3.4</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.0</smallrye-open-api.version>
57+
<smallrye-open-api.version>3.6.1</smallrye-open-api.version>
5858
<smallrye-graphql.version>2.4.0</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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ public class SmallRyeOpenApiProcessor {
164164
static {
165165
System.setProperty(io.smallrye.openapi.api.constants.OpenApiConstants.DEFAULT_PRODUCES, "application/json");
166166
System.setProperty(io.smallrye.openapi.api.constants.OpenApiConstants.DEFAULT_CONSUMES, "application/json");
167+
System.setProperty(io.smallrye.openapi.api.constants.OpenApiConstants.DEFAULT_PRODUCES_PRIMITIVES, "plain/text");
168+
System.setProperty(io.smallrye.openapi.api.constants.OpenApiConstants.DEFAULT_CONSUMES_PRIMITIVES, "plain/text");
167169
}
168170

169171
@BuildStep

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
@Path("/greeting")
1010
public class DefaultContentTypeResource {
1111

12+
@GET
13+
@Path("/foo")
14+
public String foo() {
15+
return "bar";
16+
}
17+
1218
@GET
1319
@Path("/hello")
1420
public Greeting hello() {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ public void testOpenApiPathAccessResource() {
2828
Matchers.containsString("#/components/schemas/Greeting"))
2929
.body("paths.'/greeting/hello'.get.responses.'200'.content.'application/json'.schema.$ref",
3030
Matchers.containsString("#/components/schemas/Greeting"))
31+
.body("paths.'/greeting/foo'.get.responses.'200'.content.'plain/text'.schema.type",
32+
Matchers.equalTo("string"))
3133
.body("paths.'/greeting/hello'.post.responses.'200'.content.'application/json'.schema.$ref",
3234
Matchers.containsString("#/components/schemas/Greeting"));
3335

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package io.quarkus.smallrye.openapi.test.jaxrs;
2+
3+
import jakarta.ws.rs.GET;
4+
import jakarta.ws.rs.POST;
5+
import jakarta.ws.rs.Path;
6+
import jakarta.ws.rs.Produces;
7+
import jakarta.ws.rs.core.MediaType;
8+
9+
@Path("/greeting")
10+
public class NoDefaultSecurityResource {
11+
12+
@GET
13+
@Path("/hello")
14+
public Greeting hello() {
15+
return new Greeting("Hello there");
16+
}
17+
18+
@POST
19+
@Path("/hello")
20+
public Greeting hello(Greeting greeting) {
21+
return greeting;
22+
}
23+
24+
@GET
25+
@Path("/goodbye")
26+
@Produces(MediaType.APPLICATION_XML)
27+
public Greeting byebye() {
28+
return new Greeting("Good Bye !");
29+
}
30+
31+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package io.quarkus.smallrye.openapi.test.jaxrs;
2+
3+
import org.hamcrest.Matchers;
4+
import org.junit.jupiter.api.Test;
5+
import org.junit.jupiter.api.extension.RegisterExtension;
6+
7+
import io.quarkus.test.QuarkusUnitTest;
8+
import io.restassured.RestAssured;
9+
10+
public class NoDefaultSecurityTest {
11+
private static final String OPEN_API_PATH = "/q/openapi";
12+
13+
@RegisterExtension
14+
static QuarkusUnitTest runner = new QuarkusUnitTest()
15+
.withApplicationRoot((jar) -> jar
16+
.addClasses(NoDefaultSecurityResource.class, Greeting.class));
17+
18+
@Test
19+
public void testOpenApiNoSecurity() {
20+
RestAssured.given().queryParam("format", "JSON")
21+
.when().get(OPEN_API_PATH)
22+
.then()
23+
.body("components.securitySchemes.SecurityScheme.type", Matchers.nullValue());
24+
}
25+
26+
}

extensions/vertx-http/deployment/src/main/java/io/quarkus/vertx/http/deployment/HttpSecurityProcessor.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package io.quarkus.vertx.http.deployment;
22

33
import static io.quarkus.arc.processor.DotNames.APPLICATION_SCOPED;
4-
import static org.jboss.jandex.AnnotationTarget.Kind.CLASS;
54

65
import java.security.Permission;
76
import java.util.HashMap;
@@ -216,7 +215,9 @@ SyntheticBeanBuildItem initBasicAuth(
216215
&& !buildTimeConfig.auth.basic.orElse(false)) {
217216
//if not explicitly enabled we make this a default bean, so it is the fallback if nothing else is defined
218217
configurator.defaultBean();
219-
securityInformationProducer.produce(SecurityInformationBuildItem.BASIC());
218+
if (buildTimeConfig.auth.basic.isPresent() && buildTimeConfig.auth.basic.get()) {
219+
securityInformationProducer.produce(SecurityInformationBuildItem.BASIC());
220+
}
220221
}
221222

222223
return configurator.done();

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +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 = "plain/text";
2526

2627
@TestHTTPResource("q/openapi")
2728
URL uri;
@@ -63,7 +64,8 @@ public void testOpenAPIJSON() throws Exception {
6364
// test RESTEasy extensions
6465

6566
JsonObject schemasObj = obj.getJsonObject("components").getJsonObject("schemas");
66-
String testSchemaType = schemaType("200", DEFAULT_MEDIA_TYPE, testObj.getJsonObject("get").getJsonObject("responses"),
67+
String testSchemaType = schemaType("200", DEFAULT_MEDIA_TYPE_PRIMITAVE,
68+
testObj.getJsonObject("get").getJsonObject("responses"),
6769
schemasObj);
6870
String rxSchemaType = schemaType("200", DEFAULT_MEDIA_TYPE,
6971
injectionObj.getJsonObject("get").getJsonObject("responses"),

0 commit comments

Comments
 (0)