vitalik / django-ninja

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

[BUG] `models.URLField` serialized & validated as `str` #1157

Open mpeyfuss opened 6 months ago

mpeyfuss commented 6 months ago

Describe the bug When using a URLField in a Django model and then using a ModelSchema for serialization/validation on a POST request, the url is just validated as a str. Most other fields are covered in Ninja, but this one seems to be missing.

Versions (please complete the following information):

pmdevita commented 5 months ago

It could be easy enough to just the annotation to the TYPES list in fields but the tricky bit is mimicking Django validator behavior. Django's default behavior is debatable too though, as it will accept FTP URLs and IPs which many people might not want.

Maybe the more complete solution is to be able to declare a Pydantic type annotation on a custom Django Field, then it could get reused automatically everywhere. It would also provide a path for third-party libraries that implement their own fields to improve their out-of-box support with Ninja.