Swagger示例帖子正文 - 如何显示JSON Body-Swagger-annotations

问题描述 投票:0回答:1

要求:我有一个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这样的东西:

enter image description here

当然,我错过了关键的事情。有什么想法吗?

java spring-boot annotations swagger-ui
1个回答
2
投票

如果从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)位)

© www.soinside.com 2019 - 2024. All rights reserved.