openapi-typescript-codegen icon indicating copy to clipboard operation
openapi-typescript-codegen copied to clipboard

Transform properties name from snake_case to camelCase

Open matt-odk opened this issue 2 years ago • 1 comments

Hello,

Is there a way to transform response property name from snake_case to camelCase for API response models ?

matt-odk avatar Sep 15 '22 08:09 matt-odk

We use Python on the server which uses snake_case and following standards we like JSON responses to be in camelCase, turns out that this isn't the responsibility of the api client generator (we use OTC codegen).

The Open API schema is meant to expose what the code generators use to build the API client, and it's the responsibility of the server layer to transpose between snake_case and camelCase.

In our case we use FastAPI and translate between when we get the JSON payload and when the Pydantic models are exposed. I have documented this here.

I also recommend reading this article (if you are using Python) - CamelCase Models with FastAPI and Pydantic.

Hopefully it points you in the right direction.

devraj avatar Sep 20 '22 07:09 devraj