question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Reopen 1010: Default request Content-Type header and parameter in body as object

See original GitHub issue

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 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

  1. Content-Type header is not added in the request.
  2. 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:open
  • Created 6 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
srihakumcommented, Apr 25, 2017

@webron I just tried today with 3.0.0.7 but it this issue is not fixed.

1reaction
kwvcommented, May 16, 2017

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/

A list of MIME types the APIs can consume. This is global to all APIs but can be overridden on specific API calls.)

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do you set the Content-Type header for an HttpClient ...
Make sure request headers are used with HttpRequestMessage , response headers with HttpResponseMessage , and content headers with HttpContent objects.
Read more >
Solved: Remember to include a Content-Type header set to a...
I am trying to create HTTP Request "When a HTTP request is recevied". Whenever i add "Request Body JSON Schema" the Flow designer...
Read more >
Sending HTTP Requests | Using Caché Internet Utilities
ContentType specifies the Content-Type header, which specifies the Internet media type of the request body. The default type is none.
Read more >
Content-Type - HTTP - MDN Web Docs - Mozilla
The Content-Type representation header is used to indicate the original media type of the resource (prior to any content encoding applied ...
Read more >
Error Code 1010 calling POST translate - LibreTranslate API
I have a Content-Type header set of 'aplication/json'; ... I would try to pass the parameters as POST body parameters rather than with...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found