昂首阔步:提取常见的生成实现

时间:2020-09-21 22:12:19

标签: java swagger openapi

我正在为我的应用程序使用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

我尝试了什么

  • 我创建了一个新的POJO,其中包含列表变量。此方法有效,但是考虑到我们要添加一个额外的变量,这会影响当前生产中的API模式,因此我们不希望对其进行修改。
  • 我创建了一个从ArrayList<MyOwnObject>开始的新POJO。在生成期间,Swagger将新对象替换为相同的array模式,使输出等于原始对象。
  • 我玩过@Schema@ArraySchema Swagger注释,没有运气。

你们对如何解决此问题有任何想法吗?甚至有可能实现吗?

谢谢!

0 个答案:

没有答案