swagger-api / swagger-api/swagger-client
Reopen 1010: Default request Content-Type header and parameter in body as object
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 2.7k
- Forks
- 765
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 6
Description
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
- 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);
});
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the Swagger client setup and the client.apis.zohocrm.createAccount entry point shown in the example. Reproduce the request against the referenced staging URL, then inspect how the request handles consumes, the Content-Type header, and body parameters. Done means the default application/json behavior and object body serialization match the described 2.x behavior when consumes is absent.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- api
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100