-
-
Notifications
You must be signed in to change notification settings - Fork 263
Use default value for ref property#1202
Use default value for ref property #1202github-abcde wants to merge 4 commits intoopenapi-generators:main from
Conversation
6fa4204 to
5d34403
Compare
@dbanty
dbanty
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the OpenAPI spec, we're supposed to ignore any additional properties defined on a reference—which would include default unless I'm missing something.
The "right" way to do this might be with allOf?
github-abcde
commented
Apr 14, 2025
According to the OpenAPI spec, we're supposed to ignore any additional properties defined on a reference—which would include
defaultunless I'm missing something.The "right" way to do this might be with
allOf?
Sorry for not getting back to you earlier. I needed a bit of time to deeper understand the reference you made, since it seemed quite straightforward (but contradicts what I wanted it to say :))
However (and I'm still not entirely sure I've wrapped my head around this correctly) there is a distinction made between "Reference objects" and "Schema objects that contain a $ref keyword".
After some searching, I found this: https://learn.openapis.org/referencing/overview.html#a-taxonomy-of-references.
Isn't this an example of the 4th row in the table, whereas a direct reading of the spec would be an example of the 2nd row in the table?
The remark that 'this is more-or-less equivalent to using a one-element "allOf"' seems to agree with your suggestion to use allOf.
Another interesting fact is that this schema structure is generated by pydantic (from at least 2.8 up to 2.11.3 which is the latest version at this time of writing). So it seems that it's either a bug in how pydantic generates the schema, or how we interpret it :)
What do you think?
When the OpenAPI spec contains an optional enum property with a default value, the default value is ignored and is always set to
UNSETin the generated client (current behavior).This PR attempts to address this, checking if a default is defined for a referenced property and applying that. If no default is defined on the property itself, the current behavior is applied (fetching the default from the parent if present and falling back to
None(UNSET) if absent).I hope I've provided everything required in this PR, but if not, please let me know :-)