要求:我有一个POST方法,它将输入JSON作为String并将其传递给另一个微服务。我不想创建这个输入JSON的Object(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){
}
问题:生成的Swagger不会将输入显示为JSON模型,其中显示所有JSON属性。
期望:我想展示我的Swagger这样的东西:
当然,我错过了关键的事情。有什么想法吗?
如果从String
更改为具体对象不合适(虽然这是我建议你做的,因为它更干净),你可以尝试使用@ApiImplicitParams
(看看他们的documentation)
@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){
}
(不确定你是否还需要方法参数中的@Apiparam(name="JSONrequest", required = true)
位)