vitalik / django-ninja

💨 Fast, Async-ready, Openapi, type hints based framework for building APIs
https://django-ninja.dev
MIT License
7.32k stars 436 forks source link

[Question] Custom Validation for post body Json fields. #1086

Open ethanli722 opened 9 months ago

ethanli722 commented 9 months ago

I'm upgrading from 0.22.2 to 1.1.0 and many tests are failing. Previously I was overriding my Schema's init and preforming my validations in there.

class MySchema(Schema):

  def __init__(self, **data: dict[str, Any]):
          super().__init__(**data)
          self._validate_args()

However in 1.1.0 this no longer works as init is no longer called. Is there an alternative I can do?

soccer99 commented 8 months ago

django-ninja internally is using the Pydantic "Model validators"

https://docs.pydantic.dev/latest/concepts/validators/#model-validators

You might want to look into and try that.