dataclasses-jsonschema
dataclasses-jsonschema copied to clipboard
Allow to use fields for arbitrary schema extensions.
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}})