Skip to content
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

OneOf, ContainsOnly for dataclass #510

Open
sylvain-ri opened this issue Nov 22, 2023 · 0 comments
Open

OneOf, ContainsOnly for dataclass #510

sylvain-ri opened this issue Nov 22, 2023 · 0 comments

Comments

@sylvain-ri
Copy link
Contributor

sylvain-ri commented Nov 22, 2023

I love the Python dataclasses and enjoyed using them with APIFlask so far, through marshmallow_dataclass.

But using the OneOf from apiflask.validators with sublasses (non-native types) raises Errors for me. How should I use it ?

Something like:

from marshmallow_dataclass import dataclass
from apiflask.validators import OneOf

@dataclass
class SubClassA:
    attribute: float

@dataclass
class SubClassB:
    something: str

@dataclass
class InputClass:
    attribute_1_with_choice: Union[SubClassA, SubClassB]  # this fails.
    attribute_2_with_choice: OneOf((SubClassA, SubClassB))  # this fails as well

Or would it be possible to use the standard typing.Union for APIFlask to understand the OneOf ?

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

No branches or pull requests

1 participant