如何在 Springfox 的 Swagger 2 中为 JSONObject 请求主体自定义示例值?

How to customize example values in Springfox's Swagger 2 for a JSONObject request body?

我想为我使用 Springfox 的 Swagger (Spring REST API) 制作的 API 文档自定义示例值。

由于请求正文是通过 JQuery AJAX 字符串化的 JSON,因此 @RequestParam 是一个字符串。 我已经尝试了多个 "solutions",包括 @ApiModel@ApiImplicitParams,但都没有用。 "string" 似乎永远不会改变。

如何更改示例值?我不介意这是否需要手动完成。我只希望该区域显示一个 JSON 对象。

如果使用对象描述请求体,可以使用@ApiModelProperty,示例:

data class RequestBody(
    @ApiModelProperty(example = "John Doe")
    val name: String,
    @ApiModelProperty(example = "Coolstreet 1")
    val address: String
)

替代方法是使用@Example 和@ExampleProperties,但我发现它们更加混乱。在官方参考文档中有一些关于如何使用它们的示例:http://springfox.github.io/springfox/docs/current/#example-application

提供的例子:

@RequestMapping(value = "/2031", method = RequestMethod.POST)
@ResponseBody
@ApiOperation(value = "/2031")
@ApiImplicitParams({
    @ApiImplicitParam(
        name = "contents",
        dataType = "CustomTypeFor2031",
        examples = @io.swagger.annotations.Example(
            value = {
                @ExampleProperty(value = "{'property': 'test'}", mediaType = "application/json")
            })) 
})
public void save(@PathVariable("keyId") String keyId,
                 @PathVariable("id") String id,
                 @RequestBody String contents 
) {
}

public static class CustomTypeFor2031 { 
  private String property;

  public String getProperty() {
    return property;
  }

  public void setProperty(String property) {
    this.property = property;
  }
}