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][Angular] fix issues with empty body #6754

Merged
merged 8 commits into from
Oct 24, 2017
Merged

[TypeScript][Angular] fix issues with empty body #6754

merged 8 commits into from
Oct 24, 2017

Conversation

macjohnny
Copy link
Contributor

@macjohnny macjohnny commented Oct 19, 2017

PR checklist

  • Read the contribution guidelines.
  • Ran the shell script under ./bin/ to update Petstore sample so that CIs can verify the change. (For instance, only need to run ./bin/{LANG}-petstore.sh and ./bin/security/{LANG}-petstore.sh if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in .\bin\windows\.
  • Filed the PR against the correct branch: 3.0.0 branch for changes related to OpenAPI spec 3.0. Default: master.
  • Copied the technical committee to review the pull request if your PR is targeting a particular programming langauge.

Description of the PR

fixes #6649, #6723

@macjohnny
Copy link
Contributor Author

macjohnny commented Oct 19, 2017

* Check if act as Restful update method
*
* @return true if act as Restful update method, false otherwise
*/
Copy link
Contributor

@pgrm pgrm Oct 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the comment is wrong 😉 this is what I came up with, but wasn't fast enough to create a PR

/**
 * Check if body param is allowed for the request method
 *
 * @return true if request method is PUT, PATCH or POST; false otherwise
 */

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, now I see it. I updated the PR accordingly

Copy link
Contributor

@pgrm pgrm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@macjohnny update the comment in the java file, otherwise it looks cool, thx for creating the PR 👍

@pgrm
Copy link
Contributor

pgrm commented Oct 19, 2017

@wing328 you can mark this one also with bug and typescript

@macjohnny
Copy link
Contributor Author

@wing328 @sebastianhaas the checks passed, how about merging?

@defmonk0
Copy link
Contributor

defmonk0 commented Oct 21, 2017

Hello! I was having some trouble with delete calls (it was passing 3 parameters, when the delete method can only take 2), so @macjohnny asked me to try this branch to see if it fixed the problem.

While it does fix the parameter mismatch, it doesn't quite fix the problem altogether. This is the API I've been using, with the contacts->delete method. As you can see, it wants a list of contact_ids in the body of the request. This PR still has an issue where it doesn't pass body data for delete requests at all (which is valid swagger, even if it's uncommon).

As I understand it, Angular does not currently support body data in the options of the delete method. As an alternative, the request method does. If we used request instead, we could have full control over what gets passed around.

I don't have much experience with mustache templates, but I also think it's worth considering using the request method for all of the call types. It would be more consistent, so it might simplify the template in the long run. I'm open to input on this, if anyone has any particular thoughts on using one over the other.

@sebastianhaas
Copy link
Contributor

I don't have much experience with mustache templates, but I also think it's worth considering using the request method for all of the call types. It would be more consistent, so it might simplify the template in the long run. I'm open to input on this, if anyone has any particular thoughts on using one over the other.

@defmonk0 either that, or you could try and file a request with the Angular team. Not sure if body data in a delete is inside specs though, so they might as well not agree on doing this. Would be interesting to do some research on that, maybe I'll find some time today.

@macjohnny
Copy link
Contributor Author

@defmonk0 @sebastianhaas the HTTP standard does not explicitly forbid body data with DELETE requests. however, it seems that the body data does not have any semantic meaning, which is why it is discouraged. See discussions e.g. here:
https://stackoverflow.com/questions/14323716/restful-alternatives-to-delete-request-body
https://stackoverflow.com/questions/299628/is-an-entity-body-allowed-for-an-http-delete-request

Copy link
Contributor

@sebastianhaas sebastianhaas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this might be a useful addition, but maybe @wing328 needs to step in here as this is a more general question to me, whether swagger codegen wants to enforce APIs to comply with standards or tries to maximize compatibility.

Approved = <any> 'approved',
Delivered = <any> 'delivered'
}
export type StatusEnum = 'placed' | 'approved' | 'delivered';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know why you got these changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess because the v4.3 was not re-generated after the changes introduced in #6233
this means that 4.3 somehow is not checked by CI. @wing328 can you fix that?

@@ -21,3 +21,5 @@ export interface Tag {
name?: string;

}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And these empty lines?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, and did someone delete the newline at the end? And does your output contain one or two blank lines in the end? It appears to be two, but maybe that's just Github

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sebastianhaas i cannot tell where the newlines come from, but they also appear in e.g. #6769, so it is just about re-generating the files

@macjohnny
Copy link
Contributor Author

@sebastianhaas so does this PR look good to you?

@sebastianhaas
Copy link
Contributor

sebastianhaas commented Oct 23, 2017

Yes, I guess so, I'm always in favor of enforcing standards, however, for a project like a codegen it might also be sensible to maximize compatibility. Maybe using an option flag though.

@macjohnny
Copy link
Contributor Author

@sebastianhaas alright, but I suggest to merge this PR and discuss the DELETE body issue in #6723 , and eventually create another PR.

@pgrm
Copy link
Contributor

pgrm commented Oct 23, 2017

@sebastianhaas / @macjohnny / @defmonk0 FYI - it seems more of an incomplete typescript restriction, than actually intended use case that DELETE would allow to set a body when using the request method, meaning that the angular team might remove this possibility in the future.

My reasoning is based on the following method signature:

request<R>(req: HttpRequest<any>): Observable<HttpEvent<R>>;

and here are the constructors for HttpRequest:

constructor(method: 'DELETE' | 'GET' | 'HEAD' | 'JSONP' | 'OPTIONS', url: string, init?: {
    headers?: HttpHeaders;
    reportProgress?: boolean;
    params?: HttpParams;
    responseType?: 'arraybuffer' | 'blob' | 'json' | 'text';
    withCredentials?: boolean;
});
constructor(method: 'POST' | 'PUT' | 'PATCH', url: string, body: T | null, init?: {
    headers?: HttpHeaders;
    reportProgress?: boolean;
    params?: HttpParams;
    responseType?: 'arraybuffer' | 'blob' | 'json' | 'text';
    withCredentials?: boolean;
});
constructor(method: string, url: string, body: T | null, init?: {
    headers?: HttpHeaders;
    reportProgress?: boolean;
    params?: HttpParams;
    responseType?: 'arraybuffer' | 'blob' | 'json' | 'text';
    withCredentials?: boolean;
});

@sebastianhaas
Copy link
Contributor

@pgrm good catch, even more so, let's merge this PR and discuss options re compatibility with non-standard API definitions in another place.

@wing328
Copy link
Contributor

wing328 commented Oct 23, 2017

If no more feedback/question on this, I'll merge this tomorrow (Tue)

@macjohnny macjohnny closed this Oct 24, 2017
@macjohnny macjohnny reopened this Oct 24, 2017
@wing328 wing328 merged commit 66cbab1 into swagger-api:master Oct 24, 2017
@wing328 wing328 changed the title Bugfix/6649 angular http client empty body [TypeScript][Angular] fix issues with empty body Oct 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Angular 4+ TypeScript coge generator with HttpClient is broken if post / put / patch don't have body
5 participants