Skip to content
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-Angular2] When #isKeyInQuery but no #hasFormParams, generated API breaks. #4703

Closed
27leaves opened this issue Feb 3, 2017 · 2 comments

Comments

@27leaves
Copy link
Contributor

27leaves commented Feb 3, 2017

Description

When generating an endpoint without a formParam, but isKeyInQuery the template generates

if (this.configuration.apiKey) {
    formParams.set('{{keyParamName}}', this.configuration.apiKey);
}

But formParams never gets initialized before or used afterwards, because apparently hasFormParams is false.

{{#hasFormParams}}
        let formParams = new URLSearchParams();
{{/hasFormParams}}
{{#hasFormParams}}
            body: formParams.toString(),
{{/hasFormParams}}
Swagger-codegen version

2.2.1

Command line used for generation

used typescript-angular2 from http://editor.swagger.io/#/

File

https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/resources/typescript-angular2/api.mustache

@wing328
Copy link
Contributor

wing328 commented Feb 3, 2017

@creat-or Thanks for reporting the issue. The API key should not be put in the form parameter. It should be stored in the query parameter instead so https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/resources/typescript-angular2/api.mustache#L140 should be changed as follows:

            queryParameters.set('{{keyParamName}}', this.configuration.apiKey);

May I know if you've time to contribute the fix?

@27leaves
Copy link
Contributor Author

27leaves commented Feb 3, 2017

Thanks! OK, I will look into it! :)

27leaves added a commit to 27leaves/swagger-codegen that referenced this issue Feb 3, 2017
wing328 pushed a commit that referenced this issue Feb 4, 2017
* fix issue #4703

* run petstore
davidgri pushed a commit to davidgri/swagger-codegen that referenced this issue May 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants