forked from nanotaboada/python-samples-fastapi-restful
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplayer.py
More file actions
63 lines (51 loc) · 2.29 KB
/
player.py
File metadata and controls
63 lines (51 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
60
61
62
63
"""
Pydantic models defining the data schema for football players.
- `MainModel`: Base model with common config for camelCase aliasing.
- `PlayerModel`: Represents a football player with personal and team details.
These models are used for data validation and serialization in the API.
"""
from typing import Optional
from pydantic import BaseModel, ConfigDict
from pydantic.alias_generators import to_camel
class MainModel(BaseModel):
"""
Base model configuration for all Pydantic models in the application.
This class sets a common configuration for alias generation and name population
for any model that inherits from it. It uses camelCase for JSON field names.
Attributes:
model_config (ConfigDict): Configuration for Pydantic models, including:
alias_generator (function): A function to generate field aliases.
Here, it uses `to_camel` to convert field names to camelCase.
populate_by_name (bool): Allows population of fields by name when using
Pydantic models.
"""
model_config = ConfigDict(alias_generator=to_camel, populate_by_name=True)
class PlayerModel(MainModel):
"""
Pydantic model representing a football Player.
Attributes:
id (int): The unique identifier for the Player.
first_name (str): The first name of the Player.
middle_name (Optional[str]): The middle name of the Player, if any.
last_name (str): The last name of the Player.
date_of_birth (Optional[str]): The date of birth of the Player, if provided.
squad_number (int): The unique squad number assigned to the Player.
position (str): The playing position of the Player.
abbr_position (Optional[str]): The abbreviated form of the Player's position,
if any.
team (Optional[str]): The team to which the Player belongs, if any.
league (Optional[str]): The league where the team plays, if any.
starting11 (Optional[bool]): Indicates if the Player is in the starting 11,
if provided.
"""
id: int
first_name: str
middle_name: Optional[str]
last_name: str
date_of_birth: Optional[str]
squad_number: int
position: str
abbr_position: Optional[str]
team: Optional[str]
league: Optional[str]
starting11: Optional[bool]