OpenAPITools / OpenAPITools/openapi-generator
[REQ] [typescript-axios] - application/x-www-form-urlencoded - use model as parameter for high-level api function
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.
I use OpenIdConnect for authorization, which requires the token endpoint to accept a complex model. Unfortunately, it also requires the use of application/x-www-form-url-encoded. It will successfully generate the model for it (OpenIdConnectRequest), with all values properly notated to be nullable/default undefined.
However, when it generates the high-level API function, it does not use the model, and instead does this:
exchange(accessToken?: string, acrValues?: string, assertion?: string, audiences?: Array<string>, claims?: object, claimsLocales?: string, clientAssertion?: string, clientAssertionType?: string, clientId?: string, clientSecret?: string, code?: string, codeChallenge?: string, codeChallengeMethod?: string, codeVerifier?: string, display?: string, grantType?: string, identityProvider?: string, idTokenHint?: string, loginHint?: string, maxAge?: number, nonce?: string, password?: string, postLogoutRedirectUri?: string, prompt?: string, redirectUri?: string, refreshToken?: string, request?: string, requestId?: string, requestUri?: string, resources?: Array<string>, responseMode?: string, responseType?: string, scope?: string, state?: string, token?: string, tokenTypeHint?: string, registration?: object, uiLocales?: string, username?: string, options?: any): (axios?: AxiosInstance, basePath?: string) => AxiosPromise<void> {
const localVarAxiosArgs = AuthorizationApiAxiosParamCreator(configuration).exchange(accessToken, acrValues, assertion, audiences, claims, claimsLocales, clientAssertion, clientAssertionType, clientId, clientSecret, code, codeChallenge, codeChallengeMethod, codeVerifier, display, grantType, identityProvider, idTokenHint, loginHint, maxAge, nonce, password, postLogoutRedirectUri, prompt, redirectUri, refreshToken, request, requestId, requestUri, resources, responseMode, responseType, scope, state, token, tokenTypeHint, registration, uiLocales, username, options);
return (axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => {
const axiosRequestArgs = {...localVarAxiosArgs.options, url: basePath + localVarAxiosArgs.url};
return axios.request(axiosRequestArgs);
};
},
This is not something specific to typescript-axios, it is an inherent operation performed by the underlying DefaultCodegen class, as both it and the abstract typescript generators both call super when handling this logic.
Describe the solution you'd like
What I would love to see is the generation of this high level API function:
exchange(request: OpenIdConnectRequest, options?: any): (axios?: AxiosInstance, basePath?: string) => AxiosPromise<void> {
const localVarAxiosArgs = AuthorizationApiAxiosParamCreator(configuration).exchange([access all request options here], options);
return (axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => {
const axiosRequestArgs = {...localVarAxiosArgs.options, url: basePath + localVarAxiosArgs.url};
return axios.request(axiosRequestArgs);
};
},
(Where it says [access all request options here], it would have the same as the prior code, just each parameter would be prepended with request. I just didn't want to go through each one and add that to every parameter.)
Describe alternatives you've considered
A few other alternatives I've considered are to just go into the file and change it myself, but my RESTful service is still under heavy development, so the API client changes pretty much every day to be able to meet expanding needs as they arise, so I'd rather not do that.
I could also just make my own high-level function in a separate file that calls this function, but accepts the proper object and then spreads the parameters as they are needed. However, when sending a login request, it only needs the values "username", "password", and "grantType". (The OpenIdConnect nuget package configuration won't accept the function as the token endpoint unless it accepts the full model, however.) So I'd rather not have a function call of eighteen undefined's and three values - it's sloppy code.
Additional context
I have very little experience with Java, so I wouldn't know where to begin on a pull request.
However, I understand that this is a terribly minor issue, and I'd be willing to spend the time figuring it out myself, if needed.
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 by tracing the typescript-axios high-level API generation through DefaultCodegen and the abstract TypeScript generators mentioned in the issue. Compare the generated exchange function with the requested OpenIdConnectRequest-shaped signature; done means the generated function accepts the model while retaining the request parameters and options behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, typescript
- Domain
- devtools, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100