Open
Description
Similar to the id
field, I have a created_on
field the database will auto create for me. Now, what is the best way to not allow the field in POST, PUT but have it in GETs?
- Require the use of Create and Update Schema. Nothing would need to change, but all that schema creation smells of boilerplate.
- Modify the _utils.py schema_factory to allow for additional fields to exclude. However, at that point you might as well add
id
to that list and make it generic. - Modify the _utils.py schema_factory to look for
allow_mutation
and exclude it along withid
.
for f in schema_cls.__fields__.values()
if f.name != pk_field_name and f.field_info.allow_mutation
Now my field could look something like
# Not in OpenAPI post or put
update_on: datetime.datetime = Field(
allow_mutation=False, description="Last update from sync system"
)
Is there a better way to remove fields from Create and Update schemas easily?