Java 招摇过市:提取公共生成的实现

Java 招摇过市:提取公共生成的实现,java,swagger,openapi,Java,Swagger,Openapi,我的应用程序使用SpringBoot+Swagger(OpenApi3)+Java。我使用Swagger文档将API导入API网关 我有两个Java模型都有以下字段:List objectList 当通过swagger转换时,我会使用相同的字段定义转换我的模型: model1: type: object properties: ... // other properties here objectList: type: array items:

我的应用程序使用SpringBoot+Swagger(OpenApi3)+Java。我使用Swagger文档将API导入API网关

我有两个Java模型都有以下字段:
List objectList

当通过swagger转换时,我会使用相同的字段定义转换我的模型:

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
现在,由于一个问题,我需要将这些数组定义提取到一个单独的数组定义中,并在两个模型中引用,但我无法找到一种方法来重新建模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
我试过什么

  • 我创建了一个新的POJO,其中包含list变量。这是可行的,但考虑到我们正在添加一个额外的变量,这会影响当前的生产API模式,我们不希望修改该模式
  • 我创建了一个新的POJO,它从
    ArrayList
    扩展而来。在生成过程中,Swagger为相同的
    数组
    模式替换新对象,使输出与原始对象相同
  • 我很幸运地使用了
    @Schema
    @ArraySchema
    招摇过市的注释
你们知道怎么解决这个问题吗?甚至有可能完成吗

谢谢