Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions examples/quarkus/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
<quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id>
<quarkus.platform.version>3.21.1</quarkus.platform.version>
<quarkus.platform.version>3.34.3</quarkus.platform.version>
<skipITs>true</skipITs>
<surefire-plugin.version>3.5.2</surefire-plugin.version>
</properties>
Expand Down Expand Up @@ -44,7 +44,20 @@
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<artifactId>quarkus-rest-jackson</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-validator</artifactId>
</dependency>
<dependency>
<groupId>io.quarkiverse.resteasy-problem</groupId>
<artifactId>quarkus-resteasy-problem</artifactId>
<version>3.32.0</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
65 changes: 65 additions & 0 deletions examples/quarkus/src/main/java/org/acme/BadRequestProblem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package org.acme;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.quarkiverse.resteasy.problem.HttpProblem;
import jakarta.ws.rs.core.Response;
import org.eclipse.microprofile.openapi.annotations.media.Schema;

import java.util.List;

public class BadRequestProblem extends HttpProblem {
Comment thread
TimvdLippe marked this conversation as resolved.
protected BadRequestProblem(String message, List<BadRequestDetails> errors) {
super(
builder()
.withTitle("Bad hello request")
.withStatus(Response.Status.BAD_REQUEST)
.withDetail(message)
.with("errors", errors));
}

@Schema(name = "errors", description = "All bad request errors")
public List<BadRequestDetails> errors;

@Schema(
name = "BadRequestDetails",
description = "Request details according to API Design Rules")
public static class BadRequestDetails {
@Schema(description = "Where the error occurs")
public BadRequestLocation in;

@Schema(description = "Human-readable message describing the violation")
public String detail;

@Schema(description = "A locator for the offending value")
public String location;

@Schema(
nullable = true,
description =
"A zero-based index position when multiple query parameters have the same name")
@JsonInclude(value = JsonInclude.Include.NON_NULL)
public Integer index;

private BadRequestDetails(
BadRequestLocation in, String detail, String location, Integer index) {
this.in = in;
this.detail = detail;
this.location = location;
this.index = index;
}

public static BadRequestDetails forQuery(
BadRequestLocation in, String detail, Integer index) {
return new BadRequestDetails(in, detail, "query", index);
}
}

public enum BadRequestLocation {
@JsonProperty("body")
Body,
@JsonProperty("query")
Query,
;
}
}
64 changes: 54 additions & 10 deletions examples/quarkus/src/main/java/org/acme/GreetingResource.java
Original file line number Diff line number Diff line change
@@ -1,35 +1,79 @@
package org.acme;

import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
import org.eclipse.microprofile.openapi.annotations.Operation;
import org.eclipse.microprofile.openapi.annotations.headers.Header;
import org.eclipse.microprofile.openapi.annotations.media.Content;
import org.eclipse.microprofile.openapi.annotations.media.Schema;
import org.eclipse.microprofile.openapi.annotations.responses.APIResponse;
import org.eclipse.microprofile.openapi.annotations.tags.Tag;
import org.jboss.resteasy.reactive.RestQuery;
import org.jboss.resteasy.reactive.Separator;

import java.util.List;
import java.util.Map;

@Path("/hello")
@Tag(name = "greeting")
public class GreetingResource {

@GET
@Operation(
description = "Hello world endpoint"
)
@Operation(description = "Hello world endpoint")
@APIResponse(
responseCode = "200",
content = @Content(mediaType = MediaType.TEXT_PLAIN),
headers = {
@Header(
name = OpenApiConstants.API_VERSION_HEADER_NAME,
schema = @Schema(implementation = String.class)
)
}
)
@Header(
name = OpenApiConstants.API_VERSION_HEADER_NAME,
schema = @Schema(implementation = String.class))
})
public String hello() {
return "Hello from Quarkus REST";
}

@POST
@Operation(description = "Test bad request with query parameter")
@APIResponse(
responseCode = "200",
content = @Content(mediaType = MediaType.TEXT_PLAIN),
headers = {
@Header(
name = OpenApiConstants.API_VERSION_HEADER_NAME,
schema = @Schema(implementation = String.class))
})
@APIResponse(
responseCode = "400",
description = "Bad request response",
content =
@Content(
mediaType = "application/problem+json",
schema = @Schema(implementation = BadRequestProblem.class)))
public String withInput(@RestQuery("query") @Separator(",") List<String> queryParam) {
if (queryParam.isEmpty()) {
throw new BadRequestProblem(
"Missing required query parameter",
List.of(
BadRequestProblem.BadRequestDetails.forQuery(
BadRequestProblem.BadRequestLocation.Query,
"Query parameter is invalid",
null)));
}
var queryParams = queryParam.iterator();
for (var index = 0; queryParams.hasNext(); index++) {
var param = queryParams.next();
if (!param.equals("42")) {
throw new BadRequestProblem(
"Missing required query parameter",
List.of(
BadRequestProblem.BadRequestDetails.forQuery(
BadRequestProblem.BadRequestLocation.Query,
"Query parameter is invalid",
index)));
}
}
return "Successful response";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

/testcases/error-type-bad-invalid-input/openapi.json
119:29 error nlgov:problem-invalid-input GET and DELETE endpoints that have parameters, and all other endpoints must be able to return a 400 response paths./invalid-response-vereist.get.responses
157:29 error nlgov:problem-invalid-input GET and DELETE endpoints that have parameters, and all other endpoints must be able to return a 400 response paths./invalid-response-vereist.put.responses
195:29 error nlgov:problem-invalid-input GET and DELETE endpoints that have parameters, and all other endpoints must be able to return a 400 response paths./invalid-response-vereist.post.responses

✖ 3 problems (3 errors, 0 warnings, 0 infos, 0 hints)
Loading
Loading