Swagger UI example data

江枫思渺然 提交于 2019-12-12 02:35:59

问题


Is there a way in swagger to show example data for; model, both input & output, query parameters, headers, etc? I have been unable to find anything related to this in the annotations documentation; https://github.com/swagger-api/swagger-core/wiki/Annotations-1.5.X


回答1:


If you look at the documentation for some of the annotations mentioned in the wiki you will see they have among their optional parameters one called example or examples. You can use this parameter to add a single example or more than one (if it's allowed).

For example for a query parameter you can do it like this using the @ApiParam annotation:

@Path("/{username}")
@ApiOperation(value = "Updated user")
public Response updateUser(
  @ApiParam(example = "moondaisy") @QueryParam("username") String username
) {
...
}


来源:https://stackoverflow.com/questions/43544259/swagger-ui-example-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!