-
Notifications
You must be signed in to change notification settings - Fork 762
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
Reopen 1010: Default request Content-Type header and parameter in body as object #1022
Comments
Thanks, @srihakum. For future reference, if you feel a ticket was wrongly closed, just add a comment to it and we'll reopen it. #1010 does mention that there are two separate tickets covering it, which are not included in 3.0.5. If you'd like to try it, clone the repository, build it locally, and use it in your app. We have a release slated for tomorrow, if you'd rather wait, but if you can spare the time to test it and validate it before we publish it, we'd appreciate it. |
@webron I just tried today with 3.0.0.7 but it this issue is not fixed. |
I'm running into the same issue. Given the spec consumes When calling using v3 of swagger-js and fails:
I presume that the change is near this line. If there is no I haven't figured out how to override the content-type on a request. |
@kwv just looked the spec and issue you described - you don't even have a body parameter? In that case, regardless of the http verb, there's really no reason to send the |
Digging into this more, the server response is expected given the 3.0.9 implementation. Per S.O. on RFC-7231 when there is no content-type provided That swagger-js serializes the POST data as a URL parameter is an implementation detail. Swagger-js end users can't specify that data should be passed a body parameter. Nor can they explicitly set The
I wouldn't disagree that the specific operation should have a more precise consumes statement. However if a global content-type is specified, swagger-js should use that by default. From the example code here, 2.x of swagger-js behaved differently. |
Thanks for the reply, but I still don't understand why you would expect or need to send the As you said, you don't need to specify what's a body parameter and what's not, because swagger-js knows it from the spec. From the sound of what you describe, the current implementation around this is correct. Like you said, it accepts the request data, and handles the details in accordance to the spec. And if there's no payload, there's no need to send the header. |
I'm not sure if I'm doing anything wrong, but since I upgraded to version 3 all of my POST requests default to |
@marjan-georgiev, from what you describe, I think overriding the content-type would be more of a workaround than a fix of the root problem. Can you share your spec so we can reproduce the issue you're having? |
This problem is already partially addressed by SwaggerClient.execute({ ...});
SwaggerClient.buildRequest({ ... }); When working with Tags Interface, this functionality doesn't work, because appropriate options are not properly passed. In order to make this work, we have to replace this line: Line 21 in 7cec49c
with ...pick(swaggerJs, 'requestInterceptor', 'attachContentTypeForEmptyPayload', 'responseInterceptor', 'userFetch'), |
Can confirm we also use the Tags feature and the attachContentTypeForEmptyPayload option doesn't seem to work so we need to override / workaround the problem with request interceptors for any POST requests having an empty body. |
I do not have permission to reopen 1010 hence new issue. Sorry for duplication. With the latest fix it seems the consumes is being used to fill up Content-Type, However if the spec does not have consumes it still remains the same. In 2.x it was getting defaulted to application/json. The body serialisations issue also still exists.
This issue is in further reference to #991
With version 3.0.5 a swagger client instance tries to make an API request the following issues are observed
However while using 2.0.32 there is no need to set these explicitly. So is there a way we can get back the old behaviour with latest version, like adding "application/json" as default content type and the adding body parameter as JSON object rather than string.
Code example:
The text was updated successfully, but these errors were encountered: