-
I have an API that returns objects whose fields have snake_case names. openapi-generator can convert those to camelCase for me when I use it to generate typescript interfaces. Can Orval do something similar? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Not at the moment, the only solution is to use a mutator that transforms the data of your API and a transformer to transform all your types in camelCase. But could be a good feature to add |
Beta Was this translation helpful? Give feedback.
-
We have a similar situation our API built in
def generate_operation_id(route: APIRoute) -> str:
"""
With a little help from FastAPI docs
https://bit.ly/3rXeAvH
Globally use the path name as the operation id thus
making things a lot more readable, note that this requires
you name your functions really well.
Read more about this on the FastAPI docs
https://shorturl.at/vwz03
"""
return route.name and then configuration app = FastAPI(
generate_unique_id_function=generate_operation_id,
....
)
def to_lower_camel(name: str) -> str:
"""
Converts a snake_case string to lowerCamelCase
"""
upper = "".join(word.capitalize() for word in name.split("_"))
return upper[:1].lower() + upper[1:]
class AppBaseModel(BaseModel):
""" Pydantic base model for applications
This class is used to define the base model for all schema
that we use in the Application, it configures pydantic to
translate between camcelCase and snake_case for the JSON
amongst other default settings.
populate_by_name will allow pydantic to translate SQLAlchemy
results into serializable models, while being able to translate
the aliases back to the original names when serializing to JSON.
For a full set of options, see:
https://pydantic-docs.helpmanual.io/usage/model_config/
"""
model_config = ConfigDict(
populate_by_name=True,
alias_generator=to_lower_camel,
) The solution is specific to |
Beta Was this translation helpful? Give feedback.
Not at the moment, the only solution is to use a mutator that transforms the data of your API and a transformer to transform all your types in camelCase. But could be a good feature to add