Java / OpenAPI-无法为对象数组生成Model类

问题描述

说明 我正在尝试公开内部API供客户使用。为了这;我正在根据API响应生成Swagger api-docs,并使用它生成YAML文件

然后转到YAML文件,我正在使用'openapi-generator-maven-plugin'创建模型文件,该文件将指向内部代码供外部用户查看响应。

openapi-generator版本 弹簧靴:2.3.2。发布 爪哇:1.8 好的http:4.8.1 gson:2.8.6 openapitools的:4.3.1 发现代码错误:3.0.2

OpenAPI声明文件内容或URL 我有回应:

{
  "offset": 0,"limit": 200,"total": 136,"status": {
    "code": 200,"message": "Success"
  },"count": 136,"reponseLastModified": "2020-09-02T20:56:57.951+0000","adjustments": [
    {
      "name1": "value1","name2": value2,"name3": value3,"name4": "value4"
    },{
      "name1": "value1","name4": "value4"
    }
  ]
}

对于上述情况,我生成了Swagger JSON并转换为YAML代码删除了某些部分):

responses:
          200:
            description: OK
            content:
              application/json:
                schema:
                  $ref: '#/components/schemas/AdjustmentResponse'
     AdjustmentResponse:
      type: object
      properties:
        offset:
          type: integer
          description: 'The number of items to offset the start of the list from.'
          format: int32
          example: 5
        limit:
          type: integer
          description: 'The number of items you want the list to be limited to.'
          format: int32
          example: 10
        total:
          type: integer
          description: 'The total number of items that are in the entire collection.'
          format: int32
          example: 50
        count:
          type: integer
          format: int32
        reponseLastModified:
          type: string
        adjustments:
          type: array
          items:
            $ref: '#/components/schemas/Adjustment'
    Adjustment:
      type: object
      properties:
        name1:
          type: string
          description: 'ABCD'
        name2:
          type: integer
          description: 'ABCD'
          example: 39
        name3:
          type: string
          description: 'ABCD'
        name4:
          type: integer
          description: 'ABCD'
          example: 39

发电详情 如上所述

复制步骤 当我生成模型时,它将生成模型,但不会根据我生成的Swagger生成响应API。

将YAML文件更改为以下内容生成响应,但是由于在AdjustmentResponse DTO中它显示为:列表调整,因此不会生成模型文件“调整”。

....
adjustments:
          items:
            $ref: '#/components/schemas/Adjustment'
    Adjustment:
      type: array
.....

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)