Forum Discussion

sgest's avatar
Occasional Visitor
4 years ago

Correct way to provide JSON example for POST body


I have a sample REST endpoint like the following..

@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")})
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:

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,



No RepliesBe the first to reply