![](/img/trans.png)
[英]OpenAPI Generator / Swagger Codegen: How to add a function after all files have been generated
[英]Nested property inheritance in OpenAPI Generator/Swagger Codegen
我正在嘗試使用第三方公司提供給我的 Swagger 模式生成 Java 模型,但生成失敗或不生成我期望的對象。 我不確定是生成器還是模式是問題所在。
本質上,該模式有一個父 object Pet 具有屬性“屬性”,其中“屬性”具有屬性“大小”。 該模式還有一個子 object Cat,它“繼承”自 Pet(在 'allOf' 語句中引用 Pet),並且它本身具有一個帶有嵌套屬性“whiskerCount”的屬性“attributes”。
Cat:
allOf:
- $ref: '#/definitions/Pet'
- type: object
properties:
attributes:
type: "object"
properties:
weight:
type: "string"
Pet:
type: "object"
properties:
attributes:
type: "object"
properties:
whiskerCount:
type: "integer"
format: "int64"
使用 Swagger 編輯器 (2.0) 時,UI model 顯示為我提供架構的公司試圖實現的結果:
Cat {
attributes {
whiskerCount integer($int64)
weight string
但是,當嘗試生成模型時,結果是:
發電機 | 結果 |
---|---|
Swagger 代碼生成 (2.2.1) | 生成失敗: getAttributes() in Cat cannot override getAttributes() in Pet (返回類型不兼容) |
OpenAPI 生成器(4.3.1、5.0.0、5.1.0) | 生成成功,但生成類“Cat.java”、“CatAllOf.java”、“CatAllOfAttributes.java”、“Pet.java”、“PetAttributes.java”。 Cat#attributes(CatAllOfAttributes 類型)僅包含“whiskerCount”,而 Pet#attributes(PetAttributes 類型)僅包含“size”) |
有沒有辦法實現包含兩個字段whiskerCount和大小的“組合”屬性object(Cat的成員變量)?
嘗試將類型和屬性置於同一級別(allOf)
Cat:
allOf:
- $ref: '#/definitions/Pet'
type: object
properties:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.