to_camel_case#
- safir.pydantic.to_camel_case(string)#
Convert a string to camel case.
Intended for use with Pydantic as an alias generator so that the model can be initialized from camel-case input, such as Kubernetes objects or settings from Helm charts.
- Parameters:
string (
str) – Input string.- Returns:
String converted to camel-case with the first character in lowercase.
- Return type:
Examples
To support
camelCaseinput to a model, use the following settings:class Model(BaseModel): model_config = ConfigDict( alias_generator=to_camel_case, populate_by_name=True ) some_field: str
This must be added to every class that uses
snake_casefor an attribute and that needs to be initialized fromcamelCase. Alternately, inherit fromCamelCaseModel, which is derived frompydantic.BaseModelwith those settings added.