Skip to content

Add support of UnionType in OpenAPI schema #322

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

Conversation

EvgenySmekalin
Copy link
Collaborator

Add support for writing union types as X | Y for OpenAPI generator
It was added in Python 3.10 as part of PEP 604

@EvgenySmekalin EvgenySmekalin requested a review from mofr February 7, 2025 21:53
if hasattr(types, 'UnionType') and isinstance(hint_class, types.UnionType):
# Extract the arguments of the union (e.g., `str | int` -> (str, int))
args = get_args(hint_class)
# Convert to the old `typing.Union` style
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To simplify future life, usually it's better to rely on newer style, not vice-versa.

@EvgenySmekalin EvgenySmekalin requested a review from mofr February 10, 2025 11:40
@EvgenySmekalin
Copy link
Collaborator Author

The support of new types will be implemented in future pull request

@EvgenySmekalin EvgenySmekalin merged commit 2c1a042 into WinterFramework:master Feb 11, 2025
16 checks passed
@EvgenySmekalin EvgenySmekalin deleted the add-onpenapi-union-type-support branch February 11, 2025 11:25
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