forked from IBM/openshift-on-ibm-cloud-workshops
-
Notifications
You must be signed in to change notification settings - Fork 11
/
GetAuthor.java
69 lines (63 loc) · 2.59 KB
/
GetAuthor.java
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
package com.ibm.authors;
import javax.enterprise.context.ApplicationScoped;
import javax.json.JsonObject;
import javax.ws.rs.*;
import javax.ws.rs.core.Response;
import org.eclipse.microprofile.openapi.annotations.OpenAPIDefinition;
import org.eclipse.microprofile.openapi.annotations.Operation;
import org.eclipse.microprofile.openapi.annotations.enums.SchemaType;
import org.eclipse.microprofile.openapi.annotations.info.Contact;
import org.eclipse.microprofile.openapi.annotations.info.Info;
import org.eclipse.microprofile.openapi.annotations.info.License;
import org.eclipse.microprofile.openapi.annotations.responses.APIResponses;
import org.eclipse.microprofile.openapi.annotations.responses.APIResponse;
import javax.ws.rs.QueryParam;
import org.eclipse.microprofile.openapi.annotations.media.Content;
import org.eclipse.microprofile.openapi.annotations.media.Schema;
import org.eclipse.microprofile.openapi.annotations.parameters.Parameter;
import javax.json.Json;
@ApplicationScoped
@Path("/getauthor")
@OpenAPIDefinition(info = @Info(title = "Authors Service", version = "1.0", description = "Authors Service APIs", contact = @Contact(url = "https://github.com/nheidloff/cloud-native-starter", name = "Niklas Heidloff"), license = @License(name = "License", url = "https://github.com/nheidloff/cloud-native-starter/blob/master/LICENSE")))
public class GetAuthor {
@GET
@APIResponses(value = {
@APIResponse(
responseCode = "404",
description = "Author Not Found"
),
@APIResponse(
responseCode = "200",
description = "Author with requested name",
content = @Content(
mediaType = "application/json",
schema = @Schema(implementation = Author.class)
)
),
@APIResponse(
responseCode = "500",
description = "Internal service error"
)
})
@Operation(
summary = "Get specific author",
description = "Get specific author"
)
public Response getAuthor(@Parameter(
description = "The unique name of the author",
required = true,
example = "Niklas Heidloff",
schema = @Schema(type = SchemaType.STRING))
@QueryParam("name") String name) {
Author author = new Author();
author.name = "Niklas Heidloff";
author.twitter = "https://twitter.com/nheidloff";
author.blog = "http://heidloff.net";
return Response.ok(this.createJson(author)).build();
}
private JsonObject createJson(Author author) {
JsonObject output = Json.createObjectBuilder().add("name", author.name).add("twitter", author.twitter)
.add("blog", author.blog).build();
return output;
}
}