marcosschroh / dataclasses-avroschema

Generate avro schemas from python classes. Code generation from avro schemas. Serialize/Deserialize python instances with avro schemas
https://marcosschroh.github.io/dataclasses-avroschema/
MIT License
213 stars 64 forks source link

Add validation as metadata on the schema #681

Open woile opened 1 month ago

woile commented 1 month ago

Is your feature request related to a problem? Please describe. The problem is how to share validation information as part of the schema.

What do I mean by validation? mix_length or max_length on a string, or a regex pattern.

Describe the solution you'd like dataclasses-avroschema es now able to add some metadata, my proposed solution is to also add the Field info from pydantic as part of the schema's metadata.

For example this schema, should include as part of the field's metadata also the min_length and pattern, etc:

from pydantic import BaseModel, Field

class Foo(BaseModel):
    short: str = Field(min_length=3)
    long: str = Field(max_length=10)
    regex: str = Field(pattern=r'^\d*$')