Swagger UI 示例数据

问题描述:

有没有办法大摇大摆地显示示例数据;模型,输入和输出、查询参数、标题等?我在注释文档中找不到与此相关的任何内容;https://github.com/swagger-api/swagger-core/wiki/Annotations-1.5.X

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

如果您查看 wiki 中提到的某些注释的文档,您将看到它们的可选参数中有一个称为 exampleexamples.您可以使用此参数添加一个或多个示例(如果允许).

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).

例如,对于查询参数,您可以使用 @ApiParam 注释:

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
) {
...
}