Skip to content
This repository has been archived by the owner on Aug 19, 2023. It is now read-only.

Allow to use fields for arbitrary schema extensions. #120

Open
mic47 opened this issue Nov 30, 2019 · 0 comments
Open

Allow to use fields for arbitrary schema extensions. #120

mic47 opened this issue Nov 30, 2019 · 0 comments

Comments

@mic47
Copy link

mic47 commented Nov 30, 2019

Currently, you can use field metadata for custom descriptions, examples. But to do more custom validation (like constraints for integers), you have to use NewType and registering this type. While NewType is good for things like Email, and Enum-like things, it's cumbersome for numeric things, since you have to create newtype for each restriction (i.e. for restricting by 1 and 0 you need separate types). Instead, metadata from field could be used, as like this:

>>@dataclass
class Box(JsonSchemaMixin):
    """A box."""
    width: int = field(metadata={"description": "Some desctiption", "schema": {"minimum": 1}})
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant