How to use @ExampleProperty.

3,267 views
Skip to first unread message

sdav

unread,
Aug 23, 2016, 3:37:50 PM8/23/16
to Swagger
Hi ,

I have checked the examples on github about @example property (https://github.com/swagger-api/swagger-core/blob/master/modules/swagger-jaxrs/src/test/java/io/swagger/resources/ClassWithExamplePost.java). I tried to implement the same on my api but i always get the error indicating that " @example is disallowed at this location " or "can not be resolved in to type".


@POST
@Produces({MediaType.APPLICATION_JSON})
@Consumes({MediaType.APPLICATION_JSON})
@ApiOperation(value="Creates new Data control")
@ApiImplicitParams({
@ApiImplicitParam(
paramType = "body",
name = "myPody",
dataType = "[Ljava.lang.String;",
examples = @Example(value = {
@ExampleProperty(mediaType="application/json", value="[\"a\",\"b\"]")}))
})

@ApiResponses(value = {
@ApiResponse(code = 403, message = "Invalid credentials"),
@ApiResponse(code = 404, message = "Invalid Request") })  
public JsonObject create(@ApiParam(hidden=true)JsonObject request) {
log.info("create new data control");
JsonObject response = null;
try{..................................
...............................}
}

No matter where i use i get the same error. so can you please tell me what is the correct way of using the @example property?

Ron Ratovsky

unread,
Aug 23, 2016, 9:16:47 PM8/23/16
to swagger-sw...@googlegroups.com

Which version of swagger-core do you use? And assuming it’s not the latest, can you try updating first?

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Kushang Parikh

unread,
Dec 19, 2017, 9:00:59 AM12/19/17
to Swagger
Hey,

I am using  io.swagger.core of version 1.5.16 and it works for me.

@ApiImplicitParams({
      @ApiImplicitParam(name = "graph", value = "list of the graph record IDs for each network which are going to be merged in a single network", paramType = "body", dataType = "jsonNode") ,
@ApiImplicitParam(name = "name", value = "graph name", paramType = "body",examples = @Example(value = {@ExampleProperty(mediaType = "application/json" ,value = "{}")}))})
Reply all
Reply to author
Forward
0 new messages