OpenAPITools / OpenAPITools/openapi-generator
[REQ][typescript-axios] Add case conversion for model property names
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Is your feature request related to a problem? Please describe.
It is common to have the backend and the frontend use different cases in the API contract. I see that the flag used case conversion of the model property names was removed in https://github.com/OpenAPITools/openapi-generator/pull/10447. I (think I) understand why this was removed but it would really help if we can make this feature work.
Describe the solution you'd like
I'm not familiar with JS/typescript/axios. But based on the description of the PR, it looks like we need to have some sort of mapping between the original property names and case converted property names. So, we can save this map along with the models interface, add pass this as an arg to createRequestFunction.
export const createRequestFunction = function (axiosArgs: RequestArgs, globalAxios: AxiosInstance, BASE_PATH: string, configuration?: Configuration, requestPropertyMap?: ModelPropertyMap, responsePropertyMap?: ModelPropertymap) {
axiosArgs = reMapProperties(axiosArgs, requestPropertyMap);
return <T = unknown, R = AxiosResponse<T>>(axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => {
const axiosRequestArgs = {...axiosArgs.options, url: (configuration?.basePath || basePath) + axiosArgs.url};
return reMapProperties(axios.request<T, R>(axiosRequestArgs), responsePropertyMap);
};
}
Describe alternatives you've considered
Most online solutions suggest using axios response and request hooks/interceptors. I'm completely new to axios and was not able to properly use them in this context. If someone thinks this might be a better or the right approach, and can help me a bit it would be great!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with modules/openapi-generator/src/main/resources/typescript-axios/common.mustache, especially createRequestFunction, and review the case-conversion removal described in pull request 10447. Trace how generated models and request and response data are represented. Done means generated TypeScript Axios clients consistently map model property names in both outgoing requests and incoming responses.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100