Forum Discussion

sgest's avatar
sgest
Occasional Visitor
5 years ago

Correct way to provide JSON example for POST body

 

I have a sample REST endpoint like the following..

@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("/{designName}/remoteReference")
@ApiOperation(value = "Create an external reference to the service design", response = java.util.Map.class, tags = {"/v1/design", "All Apis", "Working with designs"})
@ApiResponses(value = {@ApiResponse(code = 200, message = "Successful operation", examples = @Example(value = {@ExampleProperty(mediaType = "application/json", value = "{}")})),
@ApiResponse(code = 400, message = "Bad request"),
@ApiResponse(code = 403, message = "Authorization failure")})
@Override
public Response createRemoteReference(@ApiParam(value = "Name of service design", required = true) @PathParam("designName") String designName,
Map<Object, Object> remoteReferenceParams,
@Context HttpServletRequest servletRequest) {

and I wish to provide an example for the 'body' argument appearing in Swagger UI such as:
{

"id": anId",
"displayName": "aDisplayName",
"description" : "aDescription"
}
We're using swagger via the following maven dependency:
<groupId>io.swagger</groupId>
<artifactId>swagger-jersey2-jaxrs</artifactId>
<version>1.6.2</version>

and the annotations are from the following imports:
import io.swagger.annotations.*;
The @ApiResponse annotation renders any sample JSON placed in the value of @Example beautifully; 
but I cannot get the POST body to render at all.

I would like to know how to annotate the Java REST endpoint such that the POST body element
can display the example JSON.

Here is a picture of the current rendering.

Thanks in advance,
Stephen
 

 



 

No RepliesBe the first to reply