-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathGreetingResource.java
More file actions
79 lines (74 loc) · 3.07 KB
/
GreetingResource.java
File metadata and controls
79 lines (74 loc) · 3.07 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package org.acme;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
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")
@APIResponse(
responseCode = "200",
content = @Content(mediaType = MediaType.TEXT_PLAIN),
headers = {
@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";
}
}