django-ninja
django-ninja copied to clipboard
[BUG] In docs page, the payload examples do not use the default_factory attribute
Describe the bug
Given this schema:
class Quote(Schema):
checkIn: date = Field(default_factory=lambda: date.today() + timedelta(days=1))
checkOut: date = Field(default_factory=lambda: date.today() + timedelta(days=4))
I expect the example payloads in the docs to have dates different than today. But they dont.
If I use default values, they do, but they are set once the application loads and get stalled with the pass of time.
class QuoteOptionInputDTO(Schema):
checkIn: date = Field(default=date.today() + timedelta(days=1))
checkOut: date = Field(default=date.today() + timedelta(days=4))
Versions (please complete the following information):
- Python version: 3.11
- Django version: 4.2.7
- Django-Ninja version: 1.1.0
- Pydantic version: 2.4.2
@hugochinchilla when you set default_factory - nothing is actually brought to opneapi examples schema (what you see as today date is actually provided by swagger js)
default_factory only works during validation if you do not provide
what you need is some sort of dynamic examples generation - I'm not really sure how is it possible at pydantic - so I guess you better ask at pydantic forum how to achive json_schema to generate dynamic examples
Thanks for the reply, and apologize for my very late response. I'm closing the issue.