-
Notifications
You must be signed in to change notification settings - Fork 216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiple colliding allOf
s causing issues in generation
#4325
Comments
iiuc, |
For reference, the openapi-generator golang generator handles this design by correctly combining the composed properties from Base* types. |
right, that's probably the last case that's not implemented properly in the allOf/oneOf/anyOf matrix. We chose to implement allOf with one inline + one referenced schema as inheritance as it was the most common scenario at the time. allOf with a single entry is squashed, allOf with no entry is ignored. We're left with allOf >= 2 inline entries and allOf >= 2 referenced entries, which should effectively be a new type, will the inclusive union of all the properties (trying to avoid using all of here to avoid allOf for clarity) from the member types. As we take this opportunity to implement the last gap in the matrix, we might also clear confusion on the initial conditions for inheritance as described in #4346 |
Thanks for the answer @baywet , makes sense to me now! |
Unfortunately our team has been re-organized yet another time, and I'll be out on vacations for a couple of weeks in a couple of weeks. I'm not able to tell you when I'll be able to work on that. Please be patient with us while we re-assess priorities. |
I had some downtime waiting for specifications to be completed and took the time to look at this one. I think I have a fix with #4381 Please have a look at it. |
Attempted to minimize the issue, and this is the best I have so far. Common section: openapi: 3.0.3
servers:
- url: https://example.com
info:
title: example
version: 0.0.1
paths:
/path:
post:
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/ComponentOne"
responses:
"201":
description: Created
content:
application/json:
schema:
type: string Working example: components:
schemas:
ComponentOne:
type: object
properties:
propOne:
type: string
allOf:
- $ref: "#/components/schemas/ComponentTwo"
- $ref: "#/components/schemas/ComponentThree"
- $ref: "#/components/schemas/ComponentFour"
ComponentTwo:
type: object
properties:
propTwo:
type: string
ComponentThree:
type: object
properties:
propThree:
type: string
ComponentFour:
type: object
properties:
propFour:
type: string produces the expected result: @dataclass
class ComponentOne(AdditionalDataHolder, Parsable):
# Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well.
additional_data: Dict[str, Any] = field(default_factory=dict)
# The propFour property
prop_four: Optional[str] = None
# The propOne property
prop_one: Optional[str] = None
# The propThree property
prop_three: Optional[str] = None
# The propTwo property
prop_two: Optional[str] = None Moving the components:
schemas:
ComponentOne:
type: object
properties:
propOne:
type: string
allOf:
- $ref: "#/components/schemas/ComponentTwo"
ComponentTwo:
type: object
properties:
propTwo:
type: string
allOf:
- $ref: "#/components/schemas/ComponentFour"
- $ref: "#/components/schemas/ComponentThree"
ComponentThree:
type: object
properties:
propThree:
type: string
ComponentFour:
type: object
properties:
propFour:
type: string in this case the generation has the expected @dataclass
class ComponentOne(ComponentTwo):
# The propOne property
prop_one: Optional[str] = None but @dataclass
class ComponentTwo(ComponentFour):
# The propTwo property
prop_two: Optional[str] = None note that |
Thanks for the additional information. Do you still get the behaviour with the patch in progress? |
Tested on top of your branch and I think is even a regression: @dataclass
class ComponentOne(ComponentTwo):
# The propOne property
prop_one: Optional[str] = None and: @dataclass
class ComponentTwo(AdditionalDataHolder, Parsable):
# Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well.
additional_data: Dict[str, Any] = field(default_factory=dict)
# The propTwo property
prop_two: Optional[str] = None Seems like we are losing both the transitive dependencies ( |
I've finally had some time to start working on this again.
More investigations to follow but we're getting really close! |
Confirmed, the nested/transitive nature is the issue here, working on a fix |
I'm analyzing an OpenAPI where they used
allOf
s heavily, here you have a reproducer:The pattern that is causing issues here is:
I acknowledge that this is not supported, but the generator doesn't throw any error or warning.
The final result is to have a
RegisteredModel
data class without thename
field, breaking the "multiple inheritance pattern" correctly generates all of the expected fields.Reproducer command:
The text was updated successfully, but these errors were encountered: