如何解决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 举报,一经查实,本站将立刻删除。