dbinfrago / dbinfrago/capella-collab-manager
Snake case to Camel case mapper for types
- Dominant language
- Python
- Stars
- 37
- Forks
- 6
- PR merge metrics
- No merged PRs in 30d
Description
Currently, we sometimes have to maintain two different types in the frontend, one that maps the backend response containing snake case keys (e.g., project_slug) and another camelCase conform type for the semantically same type. This is very inconvenient as it decreases the maintainability by including unnecessary types and also led to the need of simple but annoying mapper functions (i.e., simply mapping the snake case to camel case type).
One solution for that can be seen here: [CamelCase Models with FastAPI and Pydantic](https://medium.com/analytics-vidhya/camel-case-models-with-fast-api-and-pydantic-5a8acb6c0eee). Here the mapping is achieved by simply creating another abstraction between the `BaseModel` and the actual pydantic types that transforms the field name to camel case. This would obviously be a breaking change, as our return objects are then in camel case but this should't be a problem. The advantage of this approach is, that we could iteratively apply it to our models, as we just have to change `BaseModel` to something like `CamelCaseModel` (or `CamelCaseBaseModel`) so we don't have to adjust all models in the frontend at once.
Another solution could be to add this mapping as an interceptor in the frontend. The advantage of this approach would be that we keep the snake case responses but on the other side it would then be harder to make the transition towards fully camel case types iteratively. In addition, I think that the backend solution is easier to implement but I didn't check concrete solutions for the frontend up to now.
Contributor guide
Assessment
This issue has not been assessed yet.