-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[typescript-angular] Bug - Parameters named "responseType" cause conflict. #5853
Comments
👍 Thanks for opening this issue! The team will review the labels and make any necessary changes. |
We have also stumbled into this issue and would be glad if this could be resolved. We have a parameter named |
Thanks for the detailed problem description and the suggestions!
I think that the conflict is possible regardless on that. Even if we do not camelize the param name in the generator, it's still possible that the api-spec itself has the name in camel case that matches exactly the local variable name.
This would probably do the trick. I see that AbstractTypeScriptClientCodegen already lists a couple of such local variable names as reserved: Lines 116 to 117 in e82546f
Looks like each individual typescript generator (Angular, Fetch, etc) should add to this list its own set of local var names specific to that generator's templates
Can fix your particular case, but still has a conflict potential with other api specs that can define arbitrary param names |
I'd be interested to know if this can be achieved as an "end user" of this plugin/tool. Is there any way to configure this without forking and re-publishing code? The query parameter The current workaround is to downgrade to 4.2.3 and set |
I'm encountering the same issue using @latest version (4.3.x I think). In any case, setting modelPropertyNaming=snake_case was not working. Same scenario, required param of oAuth2. I used the same workaround as the others, downgrading to 4.2.3 and setting the modelPropertyNaming to original. Any updates? A lot of time passed |
Maybe related... Using a |
+1 seeing this issue in all modern versions of openapi cli. The only working version for me on npm is "1.0.18-4.2.3" with additional properties of "supportsES6=true", "withInterfaces=true", "modelPropertyNaming=original", "useSingleRequestParameter=true". Unfortunately this version is not capable of making an api.module.ts compatible with angular version 10.x.x. due to ModuleWithProviders needing to be post typed. Meaning the the workaround is no longer viable! So anyone who has an angular 10+ project and wants a client for a service which implements oauth2 will not be able to use the cli tool at all. Can the client not just have some prefix for internal variable to avoid collision in the namespace of parameters? Or some other simple defensive technique? Its comes across as very strange that this is such a systemic issue. I also see other issues with: So if i have a route with no query parameters but a security query parameter the codegen tool does not create the QueryParameter variable and it end up confused looking for VREyeParameters. |
I'm also seeing a similar issue in |
I have a similar problem with the regular We have a request parameter with the name
|
Having similar issue and workaround of downgrading version and changing However, above not really a viable solution for me so have submitted #9202 to try and resolve |
With merge #9202, I get following error when building my Angular v11 project :
code: return this.httpClient.get<SocialMedia>(`${this.configuration.basePath}/providers/social`,
{
responseType_: <any>responseType_,
withCredentials: this.configuration.withCredentials,
headers: headers,
observe: observe,
reportProgress: reportProgress
}
); HttpClient doesn't have a property named after manually removing trailing underscore, I can build my project again. return this.httpClient.get<SocialMedia>(`${this.configuration.basePath}/providers/social`,
{
responseType: <any>responseType_,
withCredentials: this.configuration.withCredentials,
headers: headers,
observe: observe,
reportProgress: reportProgress
}
); |
@zijam thanks for reporting! |
@macjohnny I'm currently unable to file a PR now. Can you revert the changes for now. |
For anyone who comes across this, I found a workaround. I was having a similar issue with the Using the --template CLI option , I was able to rename I'm using v5.3.1, YMMV. |
+1 @Ellfish, this solved my problem too.
|
This worked for me too, thanks! Just replace |
Description
If you name a parameter responseType (or response_type etc.) the generated client method signature expects a parameter called
responseType
. However, the generated code of such method declares a variableresponseType
, which causes the compiler to throw the error messageDuplicate identifier 'responseType'.
Method signature:
public authorize(responseType?: 'code', state?: string, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: undefined}): Observable<any> {
Variable declaration:
let responseType: 'text' | 'json' = 'json';
openapi-generator version
v4.3.0 - It jused to work with v4.2.3
OpenAPI declaration file content or url
###swagger.json
Command line used for generation
docker run --rm -v ${PWD}:/local openapitools/openapi-generator-cli generate
-i /local/swagger.json
-g typescript-angular
-o /local/out
--additional-properties modelPropertyNaming=original,ngVersion=9.0.0,npmVersion=1.0.0,npmName=@package/scope,npmRepository=https://gitlab.com/api/v4/projects/123/packages/npm/
Steps to reproduce
authenticate()
generated in out/api/oAuth.service.tsRelated issues/PRs
No similar issues, but the PR which changed the behavior. It swapped the logic of
toVarName()
andtoParamName()
: #5427Suggest a fix/enhancement
With 4.2.3, the method parameter kept its case. Due to a change in 4.3.0, all parameters are now camelized. I could probably fix the code myself, and I'm willing to open a PR. I'm just not sure what you guys think the best way would be:
Best regards, and thanks a lot in advance.
The text was updated successfully, but these errors were encountered: