Use default value for ref property by github-abcde · Pull Request #1202 · openapi-generators/openapi-python-client · GitHub
Skip to content

Use default value for ref property#1202

Open
github-abcde wants to merge 4 commits intoopenapi-generators:mainfrom
github-abcde:use_default_value_for_ref_property
Open

Use default value for ref property#1202
github-abcde wants to merge 4 commits intoopenapi-generators:mainfrom
github-abcde:use_default_value_for_ref_property

Conversation

@github-abcde
Copy link
Copy Markdown

When the OpenAPI spec contains an optional enum property with a default value, the default value is ignored and is always set to UNSET in 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 :-)

@github-abcde github-abcde force-pushed the use_default_value_for_ref_property branch from 6fa4204 to 5d34403 Compare March 13, 2025 13:27
Copy link
Copy Markdown
Collaborator

@dbanty dbanty left a 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
Copy link
Copy Markdown
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants