The problem or bug i noticed is if i use DateField instead of DatetimeField then the schema for the post request to create a User shows up in the FastAPI swagger docs like so
But if i use a DatetimeField the schema shows up like this
I am aware when creating a pydantic model i can pass the argument of exclude_readonly=True and in the example from the docs that argument is there but this only omits the id of the model in the schema.
I don't understand why even though auto_now_add=True and auto_now=True is specified for the fields it still complains of missing 2 fields. The missing fields error or response shows up like this in the swagger docs.
To Reproduce
Create a basic FastAPI App with a main.py file and a models.py file and run the project with same content as the FastAPI example from the documentation
Expected behavior
Expected behavior is for the proper schema with created_at and modified_at to show up in the schema.
Describe the bug I am working on a very simple FastAPI example as suggested by the official documentation here.
In the example you can see usage of DateTime Fields like
created_at = fields.DatetimeField(auto_now_add=True)
modified_at = fields.DatetimeField(auto_now=True)
The problem or bug i noticed is if i use
DateField
instead ofDatetimeField
then the schema for the post request to create a User shows up in the FastAPI swagger docs like soBut if i use a
DatetimeField
the schema shows up like thisI am aware when creating a pydantic model i can pass the argument of
exclude_readonly=True
and in the example from the docs that argument is there but this only omits the id of the model in the schema.I don't understand why even though
auto_now_add=True
andauto_now=True
is specified for the fields it still complains of missing 2 fields. The missing fields error or response shows up like this in the swagger docs.To Reproduce Create a basic FastAPI App with a
main.py
file and amodels.py
file and run the project with same content as the FastAPI example from the documentationExpected behavior Expected behavior is for the proper schema with
created_at
andmodified_at
to show up in the schema.