validation
construct_schema_function()
Modifies model example and description if needed.
Note that schema extra has to be a function, otherwise it's called to soon before all the relations are expanded.
Returns:
Type | Description |
---|---|
Callable
|
callable that will be run by pydantic to modify the schema |
Source code in ormar\models\helpers\validation.py
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
|
generate_example_for_nested_types(type_)
Process nested types like Union[X, Y] or List[X]
Source code in ormar\models\helpers\validation.py
150 151 152 153 154 155 156 157 |
|
generate_example_for_union(type_)
Generates a pydantic example for Union[X, Y, ...]. Note that Optional can also be set as Union[X, None]
Source code in ormar\models\helpers\validation.py
160 161 162 163 164 165 166 167 168 |
|
generate_model_example(model, relation_map=None)
Generates example to be included in schema in fastapi.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
Type[Model]
|
ormar.Model |
required |
relation_map |
Optional[Dict]
|
dict with relations to follow |
None
|
Returns:
Type | Description |
---|---|
Dict[str, int]
|
dict with example values |
Source code in ormar\models\helpers\validation.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
|
generate_pydantic_example(pydantic_model, exclude=None)
Generates dict with example.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pydantic_model |
Type[BaseModel]
|
model to parse |
required |
exclude |
Optional[Set]
|
list of fields to exclude |
None
|
Returns:
Type | Description |
---|---|
Dict
|
dict with fields and sample values |
Source code in ormar\models\helpers\validation.py
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
|
get_nested_model_example(name, field, relation_map)
Gets representation of nested model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
name of the field to follow |
required |
field |
BaseField
|
ormar field |
required |
relation_map |
Dict
|
dict with relation map |
required |
Returns:
Type | Description |
---|---|
Union[List, Dict]
|
nested model or list of nested model repr |
Source code in ormar\models\helpers\validation.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
|
get_pydantic_example_repr(type_)
Gets sample representation of pydantic field for example dict.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
type_ |
Any
|
type of pydantic field |
required |
Returns:
Type | Description |
---|---|
Any
|
representation to include in example |
Source code in ormar\models\helpers\validation.py
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
|
modify_schema_example(model)
Modifies the schema example in openapi schema.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
Type[Model]
|
newly constructed Model |
required |
Source code in ormar\models\helpers\validation.py
222 223 224 225 226 227 228 229 230 |
|
overwrite_binary_format(schema, model)
Overwrites format of the field if it's a LargeBinary field with a flag to represent the field as base64 encoded string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
schema |
Dict[str, Any]
|
schema of current model |
required |
model |
Type[Model]
|
model class |
required |
Source code in ormar\models\helpers\validation.py
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
|
overwrite_example_and_description(schema, model)
Overwrites the example with properly nested children models. Overwrites the description if it's taken from ormar.Model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
schema |
Dict[str, Any]
|
schema of current model |
required |
model |
Type[Model]
|
model class |
required |
Source code in ormar\models\helpers\validation.py
171 172 173 174 175 176 177 178 179 180 181 182 183 |
|
populates_sample_fields_values(example, name, field, relation_map=None)
Iterates the field and sets fields to sample values
Parameters:
Name | Type | Description | Default |
---|---|---|---|
field |
BaseField
|
ormar field |
required |
name |
str
|
name of the field |
required |
example |
Dict[str, Any]
|
example dict |
required |
relation_map |
Optional[Dict]
|
dict with relations to follow |
None
|
Source code in ormar\models\helpers\validation.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
|