Reopen 1010: Default request Content-Type header and parameter in body as object
See original GitHub issueI 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 https://github.com/swagger-api/swagger-js/issues/991
With version 3.0.5 a swagger client instance tries to make an API request the following issues are observed
- Content-Type header is not added in the request.
- If a parameter used in HTTP body is added to the request the client expects it to be in the string format.
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:
var Swagger = require('swagger-client');
new Swagger({
"url":"https://staging.cloud-elements.com/elements/api-v2/elements/44/docs"
})
.then(function (client) {
client.apis.zohocrm.createAccount({"Authorization":"...","body":{"Account Name":"XYZ1"}})
.then(function(response){
console.log(response);
})
.catch(function (error) {
console.log(error);
});
}).catch(function (error) {
console.log(error);
});
Issue Analytics
- State:
- Created 6 years ago
- Comments:9 (5 by maintainers)
@webron I just tried today with 3.0.0.7 but it this issue is not fixed.
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
application/octet-stream
may be inferred.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
content-type
. That is the convenience of a HTTP framework like Swagger, it merely accepts the request data and handles the details in accordance to the spec.The
consumes
attribute of the spec explicitly sets a global default. Per http://swagger.io/specification/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.