使用Java的swagger注释显示API请求/响应结构

使用Java的swagger注释显示API请求/响应结构,java,annotations,swagger,Java,Annotations,Swagger,我对swagger是新手,正在尝试向API文档中添加一个使用swagger.io注释库的API输入/输出json示例。我试过这样的方法: @other annotations here public ResponseObj doSomething(@ApiParam(name = "testname", value = "test value", required = true, example = "{\"userId\":\"1234\"}" @RequestBody RequestOb

我对swagger是新手,正在尝试向API文档中添加一个使用swagger.io注释库的API输入/输出json示例。我试过这样的方法:

@other annotations here
public ResponseObj doSomething(@ApiParam(name = "testname", value = 
"test value", required = true, example = "{\"userId\":\"1234\"}" 
@RequestBody RequestObj req) {
    //some code here
}
在输出文档中,我只看到名称、值和必填字段,而没有看到示例。我甚至试过

examples = @Example(value = { @ExampleProperty(value = "examplepropvaluetest") } 
但你也看不到


有人帮忙吗?TIA以模型(表格)和示例值(json)的形式显示任何请求/响应。 请参见下面的屏幕截图

作为车型

作为示例值(xml/json)


单击模型/示例值在它们之间切换。

我使用spring-restdocs()解决了这个问题。基本上是在运行测试时生成文档。

您使用的是spring fox吗。有了spring,spring-fox swager集成工作得更好。我正在使用spring-fox如果你使用springfox,那么添加@RequestBody就足够了,它将显示在uiI中。我正在使用@RequestBody,如我的问题所示。它只是显示模式(如表中所示),而不是json格式。