Skip to content

OneOf, ContainsOnly for dataclass #510

Open
@sylvain-ri

Description

@sylvain-ri

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 ?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions