-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathBadRequestProblem.java
More file actions
65 lines (54 loc) · 2.14 KB
/
BadRequestProblem.java
File metadata and controls
65 lines (54 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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 {
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,
;
}
}