models
models
¶
Pydantic model generation for cocapi responses
create_dynamic_model
¶
create_dynamic_model(
response: dict[str, Any], endpoint_type: str
) -> dict[str, Any] | Any
Create a Pydantic model from JSON response.
First tries to match a concrete model from the schema registry. Falls back to dynamic model generation for unknown endpoints.
| PARAMETER | DESCRIPTION |
|---|---|
response
|
The JSON response data
TYPE:
|
endpoint_type
|
Type of endpoint (clan, player, etc.)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, Any] | Any
|
Either a Pydantic model instance or the original dict |
Source code in cocapi/models.py
17 18 19 20 21 22 23 24 25 26 27 28 29 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 58 59 | |
validate_pydantic_available
¶
validate_pydantic_available() -> bool
Check if Pydantic is available for dynamic model creation
Source code in cocapi/models.py
122 123 124 | |
get_pydantic_info
¶
get_pydantic_info() -> dict[str, Any]
Get information about Pydantic availability and version
Source code in cocapi/models.py
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |