Pydantic Field¶
FastDepends
is able to use pydantic.Field
as a default parameter to validate incoming argument
1 2 3 4 5 6 |
|
Pydantic Documentation
To get more information and usage examples, please visit official pydantic documentation
All available fields are:
default
: (a positional argument) the default value of the field. Since theField
replaces the field's default, this first argument can be used to set the default. Use ellipsis (...
) to indicate the field is required.default_factory
: a zero-argument callable that will be called when a default value is needed for this field. Among other purposes, this can be used to set dynamic default values. It is forbidden to set bothdefault
anddefault_factory
.alias
: the public name of the fieldconst
: this argument must be the same as the field's default value if present.gt
: for numeric values (int
,float
,Decimal
), adds a validation of "greater than" and an annotation ofexclusiveMinimum
to the JSON Schemage
: for numeric values, this adds a validation of "greater than or equal" and an annotation ofminimum
to the JSON Schemalt
: for numeric values, this adds a validation of "less than" and an annotation ofexclusiveMaximum
to the JSON Schemale
: for numeric values, this adds a validation of "less than or equal" and an annotation ofmaximum
to the JSON Schemamultiple_of
: for numeric values, this adds a validation of "a multiple of" and an annotation ofmultipleOf
to the JSON Schemamax_digits
: forDecimal
values, this adds a validation to have a maximum number of digits within the decimal. It does not include a zero before the decimal point or trailing decimal zeroes.decimal_places
: forDecimal
values, this adds a validation to have at most a number of decimal places allowed. It does not include trailing decimal zeroes.min_items
: for list values, this adds a corresponding validation and an annotation ofminItems
to the JSON Schemamax_items
: for list values, this adds a corresponding validation and an annotation ofmaxItems
to the JSON Schemaunique_items
: for list values, this adds a corresponding validation and an annotation ofuniqueItems
to the JSON Schemamin_length
: for string values, this adds a corresponding validation and an annotation ofminLength
to the JSON Schemamax_length
: for string values, this adds a corresponding validation and an annotation ofmaxLength
to the JSON Schemaallow_mutation
: a boolean which defaults toTrue
. When False, the field raises aTypeError
if the field is assigned on an instance. The model config must setvalidate_assignment
toTrue
for this check to be performed.regex
: for string values, this adds a Regular Expression validation generated from the passed string and an annotation ofpattern
to the JSON Schema