我正在为我的应用程序使用SpringBoot + Swagger(OpenApi3)+ Java。我使用Swagger文档将API导入API网关。
我有几个Java模型,都具有以下字段:List<MyOwnObject> objectList
。
通过大张旗鼓进行转换后,我将使用相同的字段定义对模型进行转换:
model1:
type: object
properties:
... // other properties here
objectList:
type: array
items:
$ref: #/components/schemas/MyOwnObject
model2:
type: object
properties:
... // other properties here
objectList:
type: array
items:
$ref: #/components/schemas/MyOwnObject
现在,由于"feature" in API Gateway,我需要将这些数组定义提取到一个在两个模型中引用的数组定义中,但是我无法找到一种方法来重构我的POJO来完成它。
我需要类似以下的输出:
model1:
type: object
properties:
... // other properties here
objectList:
$ref: #/components/schemas/commonArray
model2:
type: object
properties:
... // other properties here
objectList:
$ref: #/components/schemas/commonArray
commonArray:
type: array
items:
$ref: #/components/schemas/MyOwnObject
我尝试了什么
ArrayList<MyOwnObject>
开始的新POJO。在生成期间,Swagger将新对象替换为相同的array
模式,使输出等于原始对象。@Schema
和@ArraySchema
Swagger注释,没有运气。你们对如何解决此问题有任何想法吗?甚至有可能实现吗?
谢谢!