Feature Request: Specify fields that should remain required
Hi there, this is a really useful project! It would be great if we could pass a list of fields that should remain required in the resulting model—essentially, the opposite of the current ability to specify a subset of fields to be optional.
Hey, maybe this is what you are looking for: https://github.com/team23/pydantic-partial/blob/main/pydantic_partial/partial.py#L22
I think adding an required_fields keyword argument to the *_partial_model functions and removing them here would be an even cleaner solution as often you only need a few specific fields for PATCH requests for example, but need them always
Current solution would be to use:
PartialModel = create_partial_model(
Model,
*(
set(model_compat.model_fields.keys())
- {"the", "fields", "you", "want", "to" "keep"}
),
)
Is that working for you?
I wanted the partial model to just add a default value to all fields but keep whether the field is required or not from the full model.
This way all the fields may be omitted, but if they are given and aren't optional already in the full model Pydantic will reject null values.
Is that useful to you? See https://github.com/team23/pydantic-partial/pull/39