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] Swagger Codegen Get Methods not Including Parameters #6723

Closed
gabrielfuller opened this issue Oct 18, 2017 · 10 comments
Closed

Comments

@gabrielfuller
Copy link

Description

I am using Codegen Java file to create the Typescript-Angular 2 API for my C# web api. The code gen tool creates the correct code for post and put, but get and delete do not include the parameters correctly.

Here is the generated put method:

public organizationsUpdatePut(command?: UpdateOrganizationCommand): Observable<UpdateOrganizationCommandResult> {

        let headers = this.defaultHeaders;

        return this.httpClient.put<any>(`${this.basePath}/Organizations/Update`, command, {
            headers: headers,
            withCredentials: this.configuration.withCredentials,
        });
    }

Here is the read method:

public organizationsReadGet(command?: ReadOrganizationCommand): Observable<ReadOrganizationCommandResult> {

        let headers = this.defaultHeaders;

        return this.httpClient.get<any>(`${this.basePath}/Organizations/Read`, {
            headers: headers,
            withCredentials: this.configuration.withCredentials,
        });
    }

As you can see, in the read method, the command parameter is never added to the HttpClient Get method so my call to the API always fails. Any ideas how to fix it? Am I doing something wrong?

Swagger-codegen version

3.0.0-20171009.075709-6

Command line used for generation

java -jar C:\SimOpSolutions\SOSBrowserClientApp\files\swagger-codegen-cli-3.0.0-20171009.075709-6.jar generate -i http://localhost:5000/swagger/v1/swagger.json -l typescript-angular -o C:\SimOpSolutions\SOSBrowserClientApp\sos-app\src\app\sos-api
pause

@macjohnny
Copy link
Contributor

@gabrielfuller can you post the relevant parts of your swagger.json?

@wing328
Copy link
Contributor

wing328 commented Oct 18, 2017

3.0.0-20171009.075709-6

3.0.0 is still being worked on to support OAS (OpenAPI spec) 3.0

I would suggest you to use the 2.3.0 SNAPSHOT version for the time being.

@defmonk0
Copy link
Contributor

While this is still open, I also want to mention that httpClient.delete is not always properly configured either. When generating a delete call that takes body data, it adds it as a parameter to httpClient.delete, but the signature of that function only accepts url and options.

You can reproduce by generating typescript-angular from this spec. In the contacts.service.ts file, there is a function deleteCharactersCharacterIdContacts. The return statement there calls this.httpClient.delete<any>(url, contactIds, options), when it can only take 2 parameters.

@macjohnny
Copy link
Contributor

@defmonk0 see #6649 which has a PR #6754
could you try out that branch and verify your issue is resolved, too, or else create a new issue?

@defmonk0
Copy link
Contributor

@macjohnny So, just got around to testing that particular branch. It technically fixes the bug, allowing the error to go away. That said, it does so by simply not passing the body data at all, even if there is some.

For example, the same delete function as before has this signature:

public deleteCharactersCharacterIdContacts(characterId: number, contactIds: Array<number>, datasource?: string, token?: string, userAgent?: string, xUserAgent?: string): Observable<{}> {}

The contactIds there are meant to be sent via the request body when it does delete. The return statement now properly has this.httpClient.delete<any>(url, options), which is valid, but in no way does it pass the contactIds.

Since this bug is a side affect of that branch, I assume it's not best to open a general issue for it. Should I comment and explain the situation in the PR thread?

@macjohnny
Copy link
Contributor

macjohnny commented Oct 21, 2017

@defmonk0 please state your issue in the PR #6754
however, looking at the API docs https://angular.io/api/common/http/HttpClient , the delete method does not take any body argument:

delete(url: string, options: {...}): Observable<any>

so how is your parameter supposed to be transmitted?

if your request does have query params, they should be added correctly:

return this.httpClient.{{httpMethod}}{{^isResponseFile}}<any>{{/isResponseFile}}(`${this.basePath}{{{path}}}`, {{#bodyParam}}{{paramName}}, {{/bodyParam}}
{{#hasFormParams}}convertFormParamsToString ? formParams.toString() : formParams, {{/hasFormParams}}{
{{#hasQueryParams}}
params: queryParameters,
{{/hasQueryParams}}
headers: headers,
{{#isResponseFile}}
responseType: "blob",
{{/isResponseFile}}
withCredentials: this.configuration.withCredentials,
});

@defmonk0
Copy link
Contributor

This is the API I've been using, if you wanna take a look. Inside contacts->delete, it takes a list of contact IDs in the body of the call. I was aware of HttpClient not supporting body data on their delete calls, so I'm unsure how we'd best go about doing it. Technically, if you we use the request method instead of delete, we can do a delete while we pass body data.

I'll post over in the PR, so we can get more eyes on it.

@gabrielfuller
Copy link
Author

I used the latest 2.3.0 SNAPSHOT and it fixed my issue.

@a-ludi
Copy link

a-ludi commented Nov 1, 2017

I'm using 2.3.0 SNAPSHOT and have the same issue, that the "parameter" are not generated at all.

@gabrielfuller
Copy link
Author

gabrielfuller commented Nov 1, 2017 via email

@wing328 wing328 closed this as completed Nov 30, 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

5 participants