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
camelCase
input to a model, use the following settings:class Model(BaseModel): some_field: str model_config = ConfigDict( alias_generator=to_camel_case, populate_by_name=True )
This must be added to every class that uses
snake_case
for an attribute and that needs to be initialized fromcamelCase
. Alternately, inherit fromCamelCaseModel
, which is derived frompydantic.BaseModel
with those settings added.