Inheritance support
維護者通常 2 天內回覆
還沒有人認領這個 Issue。
評估
- 難度
- 5/5
- 預估耗時
- 一週以上
- 新手友好度
- 20/100
研究方向
在 playground 中使用 spring 2021.5,並在本機使用 2023.1.2,重現 issue 中的最小 OpenAPI 範例。將產生的 ParentSchema 和 ChildSchema 輸出與預期的獨立類別階層進行比較,然後判斷是否有意支援繼承,以及應記錄或變更哪種行為。
由索引模型根據 Issue 內容生成。
描述
Quite impressed with the toolset you created here.
I was curious about inheritance support so I tried it out with a minimal example:
openapi: 3.0.2
info:
title: edit me
version: 1.0.0
paths:
/nothing:
description: dummy
get:
responses:
'200':
description: empty
content:
'application/json':
schema:
$ref: '#/components/schemas/ChildSchema'
components:
schemas:
ParentSchema:
type: object
properties:
parentAttr:
type: string
ChildSchema:
allOf:
- $ref: '#/components/schemas/ParentSchema'
- type: object
properties:
childAttr:
type: string
This yields a ChildSchema.java consisting of everything from the parent and child model:
public class ChildSchema {
@JsonProperty("parentAttr")
private String parentAttr;
@JsonProperty("childAttr")
private String childAttr;
public String getParentAttr() {
return parentAttr;
}
public void setParentAttr(String parentAttr) {
this.parentAttr = parentAttr;
}
public String getChildAttr() {
return childAttr;
}
public void setChildAttr(String childAttr) {
this.childAttr = childAttr;
}
}
Now specifying a discriminator results in inheritance in the generated code (at least for the openapi-generator project):
openapi: 3.0.2
info:
title: edit me
version: 1.0.0
paths:
/nothing:
description: dummy
get:
responses:
'200':
description: empty
content:
'application/json':
schema:
$ref: '#/components/schemas/ChildSchema'
components:
schemas:
ParentSchema:
type: object
discriminator:
propertyName: className
properties:
parentAttr:
type: string
ChildSchema:
allOf:
- $ref: '#/components/schemas/ParentSchema'
- type: object
properties:
childAttr:
type: string
For this a special propertyName of className is used. If I run that in your playground with spring 2021.5 it complains about the property name which is not wrong strictly speaking:
The discriminator 'className' is not a property of this schema (code: 134)
If I run this locally with 2023.1.2 then this does not error but does not generate two classes with one inheriting from each other:
public class ChildSchema {
@JsonProperty("parentAttr")
private String parentAttr;
@JsonProperty("childAttr")
private String childAttr;
public String getParentAttr() {
return parentAttr;
}
public void setParentAttr(String parentAttr) {
this.parentAttr = parentAttr;
}
public String getChildAttr() {
return childAttr;
}
public void setChildAttr(String childAttr) {
this.childAttr = childAttr;
}
}
Expected result would have been:
public class ParentSchema {
@JsonProperty("parentAttr")
private String parentAttr;
public String getParentAttr() {
return parentAttr;
}
public void setParentAttr(String parentAttr) {
this.parentAttr = parentAttr;
}
}
public class ChildSchema extends ParentSchema {
@JsonProperty("childAttr")
private String childAttr;
public String getChildAttr() {
return childAttr;
}
public void setChildAttr(String childAttr) {
this.childAttr = childAttr;
}
}
Now this expectation could of course be wrong. My question now would be if this inheritance use case is supported and/or if I would have to do something differently to get the desired result. Thanks.
- 主要語言
- Kotlin
- 星號
- 56
- 分支
- 11
- 平均合併
- 4 天 10 小時
- 30 天內合併 PR
- 8
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 沒有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
openapi-processor/openapi-processor-spring 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 76/100
openapi-processor/openapi-processor-spring#524 ·
維護者通常 2 天內回覆
-
難度 5/5 一週以上 新手友好度 35/100
openapi-processor/openapi-processor-spring#334 · 2 則留言 ·
維護者通常 2 天內回覆
-
enhancement
難度 3/5 1-2 天 新手友好度 42/100
openapi-processor/openapi-processor-spring#150 · 3 則留言 ·
維護者通常 2 天內回覆
-
undecided
難度 5/5 一週以上 新手友好度 25/100
openapi-processor/openapi-processor-spring#101 · 1 則留言 ·
維護者通常 2 天內回覆
-
enhancement undecided
難度 3/5 1-2 天 新手友好度 35/100
openapi-processor/openapi-processor-spring#51 ·
維護者通常 2 天內回覆
查看 openapi-processor/openapi-processor-spring 的全部 Issue
相似的 Issue
-
help wanted needs investigation priority: low
難度 2/5 1-3 小時 新手友好度 62/100
-
bug
難度 2/5 1-3 小時 新手友好度 62/100
LeanBitLab/LeanType#883 ·
維護者通常 1 天內回覆
-
Heavy legs 1.12–1.17: compiler corpus goldens not regenerated for #4770可能已有人在做 關聯的 PR 仍在進行中或已合併。 未關閉
難度 2/5 1-3 小時 新手友好度 74/100
intellij-elixir/intellij-elixir#4782 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 74/100
komikku-app/komikku#1983 ·
維護者通常 1 天內回覆
-
bug
難度 2/5 1-3 小時 新手友好度 62/100
Seb3thehacker/gearslip#121 ·