mirror of
https://github.com/kennethreitz/pydantic.git
synced 2026-06-05 23:00:18 +00:00
943a8a06e5
* fix alias priority so alias_generators don't take priority * improve test names * remove debugs * Apply suggestions from code review * more tests and allow custom alias_priority on fields * precedence tests and docs * tweaks and add change * suggestions
20 lines
526 B
Python
20 lines
526 B
Python
from pydantic import BaseModel, Field
|
|
|
|
class Voice(BaseModel):
|
|
name: str = Field(None, alias='ActorName')
|
|
language_code: str = None
|
|
mood: str = None
|
|
|
|
class Character(Voice):
|
|
act: int = 1
|
|
|
|
class Config:
|
|
fields = {'language_code': 'lang'}
|
|
|
|
@classmethod
|
|
def alias_generator(cls, string: str) -> str:
|
|
# this is the same as `alias_generator = to_camel` above
|
|
return ''.join(word.capitalize() for word in string.split('_'))
|
|
|
|
print(Character.schema(by_alias=True))
|