Motor-ODM icon indicating copy to clipboard operation
Motor-ODM copied to clipboard

Schema Validation

Open codello opened this issue 4 years ago • 0 comments

Pydantic supports the generation of JSON Schema. This can be used to automatically support the validation of collections. The implementation should support the following:

  • Enabling/disabling validation via a validate flag in the model’s Mongo class.
  • Customization of the generated schema (this may be done directly via Pydantic)
  • Converting the schema to a MongoDB compatible format (stripping unsupported Keys, embedding referenced models etc.)
  • Using a custom validator instead of the automatically generated schema.
  • The implementation should be compatible with polymorphic and abstract documents:
    • Abstract documents in their function as blueprints can not be validated themselves. They can however enable validation options for any subclass by default.
    • Polymorphic models can be validated. Validation has to be enabled or disabled at the root level and is implemented as an $or combination of all sub-schemas. Submodels can use custom validation rules that will be used instead of the automatically generated schemas.
    • Using a strict validation mode may be interesting. Such a mode may enforce validation not via the $or operator but by using a more complex boolean predicate based on the model’s _type (Something like _type in … and _type=abc => $schema).

codello avatar Apr 06 '20 11:04 codello