Inheritance support
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Anfängerfreundlichkeit
- 20/100
Rechercherichtung
Reproduziere die minimalen OpenAPI-Beispiele aus dem Issue im Playground mit spring 2021.5 und lokal mit 2023.1.2. Vergleiche die generierte Ausgabe von ParentSchema und ChildSchema mit der erwarteten separaten Klassenhierarchie und bestimme anschließend, ob Vererbungsunterstützung vorgesehen ist und welches Verhalten dokumentiert oder geändert werden sollte.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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.
- Vorherrschende Sprache
- Kotlin
- Sterne
- 56
- Forks
- 11
- Ø Merge
- 2 T. 4 Std.
- Gemergte PRs (30 T.)
- 8
Beitragsleitfaden
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus openapi-processor/openapi-processor-spring
-
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 35/100
openapi-processor/openapi-processor-spring#334 · 2 Kommentare ·
-
enhancement
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 42/100
openapi-processor/openapi-processor-spring#150 · 3 Kommentare ·
-
undecided
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 25/100
openapi-processor/openapi-processor-spring#101 · 1 Kommentar ·
-
log unknown options Offenenhancement undecided
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 35/100
Alle Issues in openapi-processor/openapi-processor-spring
Ähnliche Issues
-
Bug Java Platform: Java
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
getsentry/sentry-java#6138 · 1 Kommentar ·
-
Icon Requests Offensupported
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
LawnchairLauncher/lawnicons#4100 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
-
Good First Issue
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
ankidroid/Anki-Android#21942 ·
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
libre-tube/LibreTube#8781 · 1 Kommentar ·