From 2e5e0d415351a057e6435608d3b43f3fea179433 Mon Sep 17 00:00:00 2001 From: "tim.quinn@oracle.com" Date: Fri, 14 Feb 2020 11:28:41 -0600 Subject: [PATCH 1/3] Add OpenAPI annotations to accurately reflect the input and responses on updateGreeting --- .../examples/quickstart/mp/GreetResource.java | 17 ++++++++++++++++- .../examples/quickstart/mp/GreetResource.java | 19 ++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/examples/quickstarts/helidon-quickstart-mp/src/main/java/io/helidon/examples/quickstart/mp/GreetResource.java b/examples/quickstarts/helidon-quickstart-mp/src/main/java/io/helidon/examples/quickstart/mp/GreetResource.java index 47e680bde42..f83a7e35774 100644 --- a/examples/quickstarts/helidon-quickstart-mp/src/main/java/io/helidon/examples/quickstart/mp/GreetResource.java +++ b/examples/quickstarts/helidon-quickstart-mp/src/main/java/io/helidon/examples/quickstart/mp/GreetResource.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2019 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,6 +32,13 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import org.eclipse.microprofile.openapi.annotations.enums.SchemaType; +import org.eclipse.microprofile.openapi.annotations.media.Content; +import org.eclipse.microprofile.openapi.annotations.media.Schema; +import org.eclipse.microprofile.openapi.annotations.parameters.RequestBody; +import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; +import org.eclipse.microprofile.openapi.annotations.responses.APIResponses; + /** * A simple JAX-RS resource to greet you. Examples: * @@ -105,6 +112,14 @@ public JsonObject getMessage(@PathParam("name") String name) { @PUT @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) + @RequestBody(name = "greeting", + required = true, + content = @Content(mediaType = "application/json", + schema = @Schema(type = SchemaType.STRING, example = "{\"greeting\" : \"Hola\"}"))) + @APIResponses({ + @APIResponse(name = "normal", responseCode = "204", description = "Greeting updated"), + @APIResponse(name = "missing 'greeting'", responseCode = "400", + description = "JSON did not contain setting for 'greeting'")}) public Response updateGreeting(JsonObject jsonObject) { if (!jsonObject.containsKey("greeting")) { diff --git a/examples/quickstarts/helidon-standalone-quickstart-mp/src/main/java/io/helidon/examples/quickstart/mp/GreetResource.java b/examples/quickstarts/helidon-standalone-quickstart-mp/src/main/java/io/helidon/examples/quickstart/mp/GreetResource.java index 47e680bde42..7cede1715f5 100644 --- a/examples/quickstarts/helidon-standalone-quickstart-mp/src/main/java/io/helidon/examples/quickstart/mp/GreetResource.java +++ b/examples/quickstarts/helidon-standalone-quickstart-mp/src/main/java/io/helidon/examples/quickstart/mp/GreetResource.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2019 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,6 +32,13 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import org.eclipse.microprofile.openapi.annotations.enums.SchemaType; +import org.eclipse.microprofile.openapi.annotations.media.Content; +import org.eclipse.microprofile.openapi.annotations.media.Schema; +import org.eclipse.microprofile.openapi.annotations.parameters.RequestBody; +import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; +import org.eclipse.microprofile.openapi.annotations.responses.APIResponses; + /** * A simple JAX-RS resource to greet you. Examples: * @@ -105,6 +112,16 @@ public JsonObject getMessage(@PathParam("name") String name) { @PUT @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) + @RequestBody(name = "greeting", + required = true, + content = @Content(mediaType = "application/json", + schema = @Schema(type = SchemaType.STRING, example = "{\"greeting\" : \"Hola\"}"))) + @APIResponses({ + @APIResponse(name = "normal", responseCode = "204", description = + "Greeting " + + "updated"), + @APIResponse(name = "missing 'greeting'", responseCode = "400", + description = "JSON did not contain setting for 'greeting'")}) public Response updateGreeting(JsonObject jsonObject) { if (!jsonObject.containsKey("greeting")) { From 37e80b5dbbd6ebcfd35baaf62bb093b73adb23ba Mon Sep 17 00:00:00 2001 From: "tim.quinn@oracle.com" Date: Fri, 14 Feb 2020 11:37:33 -0600 Subject: [PATCH 2/3] Fix checkstyle error --- .../java/io/helidon/examples/quickstart/mp/GreetResource.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/examples/quickstarts/helidon-standalone-quickstart-mp/src/main/java/io/helidon/examples/quickstart/mp/GreetResource.java b/examples/quickstarts/helidon-standalone-quickstart-mp/src/main/java/io/helidon/examples/quickstart/mp/GreetResource.java index 7cede1715f5..f83a7e35774 100644 --- a/examples/quickstarts/helidon-standalone-quickstart-mp/src/main/java/io/helidon/examples/quickstart/mp/GreetResource.java +++ b/examples/quickstarts/helidon-standalone-quickstart-mp/src/main/java/io/helidon/examples/quickstart/mp/GreetResource.java @@ -117,9 +117,7 @@ public JsonObject getMessage(@PathParam("name") String name) { content = @Content(mediaType = "application/json", schema = @Schema(type = SchemaType.STRING, example = "{\"greeting\" : \"Hola\"}"))) @APIResponses({ - @APIResponse(name = "normal", responseCode = "204", description = - "Greeting " + - "updated"), + @APIResponse(name = "normal", responseCode = "204", description = "Greeting updated"), @APIResponse(name = "missing 'greeting'", responseCode = "400", description = "JSON did not contain setting for 'greeting'")}) public Response updateGreeting(JsonObject jsonObject) { From 2fa3dff7b5ac0c045e041af696646dae7c968f2f Mon Sep 17 00:00:00 2001 From: "tim.quinn@oracle.com" Date: Tue, 18 Feb 2020 10:58:49 -0600 Subject: [PATCH 3/3] Remove 'all rights reserved' from updated copyright --- .../java/io/helidon/examples/quickstart/mp/GreetResource.java | 2 +- .../java/io/helidon/examples/quickstart/mp/GreetResource.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/quickstarts/helidon-quickstart-mp/src/main/java/io/helidon/examples/quickstart/mp/GreetResource.java b/examples/quickstarts/helidon-quickstart-mp/src/main/java/io/helidon/examples/quickstart/mp/GreetResource.java index f83a7e35774..3c7e1c9535f 100644 --- a/examples/quickstarts/helidon-quickstart-mp/src/main/java/io/helidon/examples/quickstart/mp/GreetResource.java +++ b/examples/quickstarts/helidon-quickstart-mp/src/main/java/io/helidon/examples/quickstart/mp/GreetResource.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2020 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/examples/quickstarts/helidon-standalone-quickstart-mp/src/main/java/io/helidon/examples/quickstart/mp/GreetResource.java b/examples/quickstarts/helidon-standalone-quickstart-mp/src/main/java/io/helidon/examples/quickstart/mp/GreetResource.java index f83a7e35774..3c7e1c9535f 100644 --- a/examples/quickstarts/helidon-standalone-quickstart-mp/src/main/java/io/helidon/examples/quickstart/mp/GreetResource.java +++ b/examples/quickstarts/helidon-standalone-quickstart-mp/src/main/java/io/helidon/examples/quickstart/mp/GreetResource.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2020 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License.