Sum*_*Sum 7 java annotations swagger-ui spring-boot
要求:我有一个 POST 方法,它将输入的 JSON 作为字符串并将其传递给另一个微服务。我不想创建此输入 JSON 的对象(Bean)。
方法:
@ApiOperation(notes = "example" value = "/example", consumes = ".." , method= "..")
@RequestMapping(name = "xxx" value ="/hello" ..)
@ApiResponses(..)
public @ResponseBody String getXXX (@Apiparam(name="JSONrequest", required = true) @RequestBody String JSONrequest){
}
Run Code Online (Sandbox Code Playgroud)
问题:生成的 Swagger 没有将输入显示为显示所有 JSON 属性的 JSON 模型。
期望:我想显示我的 Swagger 像这样的东西:
绝对我错过了关键的事情。有什么想法吗?
如果从String具体对象更改为不行(尽管我建议您这样做,因为它更干净),您可以尝试使用@ApiImplicitParams(查看他们的文档)
@ApiOperation(notes = "example" value = "/example", consumes = ".." , method= "..")
@ApiImplicitParams({
@ApiImplicitParam(name = "Object", value = "Object to be created", required = true, dataType = "your.package.BodyClass", paramType = "body")
})
@RequestMapping(name = "xxx" value ="/hello" ..)
@ApiResponses(..)
public @ResponseBody String getXXX (@Apiparam(name="JSONrequest", required = true) @RequestBody String JSONrequest){
}
Run Code Online (Sandbox Code Playgroud)
(不确定您是否仍然需要@Apiparam(name="JSONrequest", required = true)方法参数中的位)