| 1 |
from typing import Any |
| 2 |
|
| 3 |
from pydantic import BaseModel, TypeAdapter |
| 4 |
|
| 5 |
|
| 6 |
def parse_object_as(object_type: type, data: Any): |
| 7 |
return TypeAdapter(object_type).validate_python(data) |
| 8 |
|
| 9 |
|
| 10 |
def get_field_type(field): |
| 11 |
return field.annotation |
| 12 |
|
| 13 |
|
| 14 |
def get_model_fields(model): |
| 15 |
if not isinstance(model, type): |
| 16 |
model = model.__class__ |
| 17 |
return model.model_fields |
| 18 |
|
| 19 |
|
| 20 |
def parse_model(model_type: type[BaseModel], data: Any): |
| 21 |
return model_type.model_validate(data) |
| 22 |
|
| 23 |
|
| 24 |
def get_extra_field_info(field, parameter: str): |
| 25 |
if isinstance(field.json_schema_extra, dict): |
| 26 |
return field.json_schema_extra.get(parameter) |
| 27 |
return None |
| 28 |
|
| 29 |
|
| 30 |
def get_config_value(model, parameter: str): |
| 31 |
return model.model_config.get(parameter) |
| 32 |
|
| 33 |
|
| 34 |
def get_model_dump(model, *args: Any, **kwargs: Any): |
| 35 |
return model.model_dump(*args, **kwargs) |