Java OpenApi 生成器使用对象作为查询参数 [英] Java OpenApi generator use object as query parameter
本文介绍了Java OpenApi 生成器使用对象作为查询参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下控制器:
public interface GetScoreController {
@GetMapping(value = "/score", produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(parameters = {@Parameter(in = ParameterIn.QUERY, name = "request")})
Score getScore(ScoreRequest request);
}
并且我希望 OpenApi 在生成 Swagger 文档时将 ScoreRequest
中的所有属性显示为查询参数,因为这是请求是 POJO 时的结果:
And I'd like OpenApi to show all the attributes in ScoreRequest
as query params when generating the Swagger documentation since this is the result when the request is a POJO:
我不知道实际上 OpenApi 是否允许这样做,但是如果我有太多请求参数,将它们收集到一个唯一的 POJO 中会更有用.
I don't know if actually, OpenApi allows this, but if I have too many request params it is more useful to collect them in a unique POJO.
推荐答案
添加 @ParameterObject 方法签名的注解.
Add @ParameterObject annotation to method signature.
Score getScore(@ParameterObject ScoreRequest request);
}
这篇关于Java OpenApi 生成器使用对象作为查询参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文