Skip to content

Commit

Permalink
[3.x]: Add OpenAPI annotations to examples/quickstarts/helidon-quicks…
Browse files Browse the repository at this point in the history
…tart-mp (helidon-io#6818)
  • Loading branch information
Captain1653 authored Aug 29, 2023
1 parent 2366fbc commit afe4e11
Showing 1 changed file with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2022 Oracle and/or its affiliates.
* Copyright (c) 2018, 2023 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.
Expand Down Expand Up @@ -30,6 +30,7 @@
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import org.eclipse.microprofile.openapi.annotations.Operation;
import org.eclipse.microprofile.openapi.annotations.enums.SchemaType;
import org.eclipse.microprofile.openapi.annotations.media.Content;
import org.eclipse.microprofile.openapi.annotations.media.Schema;
Expand Down Expand Up @@ -78,6 +79,11 @@ public GreetResource(GreetingProvider greetingConfig) {
* @return {@link JsonObject}
*/
@GET
@Operation(summary = "Returns a generic greeting",
description = "Greets the user generically")
@APIResponse(description = "Simple JSON containing the greeting",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = GreetingMessage.class)))
@Produces(MediaType.APPLICATION_JSON)
public JsonObject getDefaultMessage() {
return createResponse("World");
Expand All @@ -91,6 +97,10 @@ public JsonObject getDefaultMessage() {
*/
@Path("/{name}")
@GET
@Operation(summary = "Returns a personalized greeting")
@APIResponse(description = "Simple JSON containing the greeting",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = GreetingMessage.class)))
@Produces(MediaType.APPLICATION_JSON)
public JsonObject getMessage(@PathParam("name") String name) {
return createResponse(name);
Expand Down Expand Up @@ -136,4 +146,30 @@ private JsonObject createResponse(String who) {
.add("message", msg)
.build();
}

/**
* POJO defining the greeting message content.
*/
public static class GreetingMessage {

private String message;

/**
* Gets the message value.
*
* @return message value
*/
public String getMessage() {
return message;
}

/**
* Sets the message value.
*
* @param message message value to set
*/
public void setMessage(String message) {
this.message = message;
}
}
}

0 comments on commit afe4e11

Please sign in to comment.