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

Should default to consumes[0] if no requestContentType provided #995

Closed
ponelat opened this issue Apr 6, 2017 · 7 comments
Closed

Should default to consumes[0] if no requestContentType provided #995

ponelat opened this issue Apr 6, 2017 · 7 comments

Comments

@ponelat
Copy link
Member

ponelat commented Apr 6, 2017

The final order of setting the Content-Type header should be as follows..

  • if has no req.body, no req.form add nothing.
  • else if requestContentType, use that.
  • else if has consumes use consumes[0]
  • else if has a "type: file" parameter use multipart/form-data
  • else if has "in: formData" use application/x-www-form-urlencoded
  • else add nothing.
@webron webron assigned bodnia and unassigned webron Apr 6, 2017
@dwilson6
Copy link

dwilson6 commented Apr 6, 2017

I've run into this as well. Is someone already working on this? If not, I can take a crack at it. I've already implemented part of it in my own requestInterceptor function.

Also related, I've noticed that if I have a POST endpoint with a json parameter in the body and I call that operation with the tags interface like client.apis.default.operation({param_name: {}}) (I explicitly set the Content-Type header to application/json), I get an error unexpected token o in JSON at position 1...

To get it to work, I have to serialize the value of the param explicitly client.apis.default.operation({param_name: JSON.stringify({})}).

Would it be reasonable to automatically stringify if the content type is application/json and it has an "in: body" parameter and the value is an object? I can create a separate issue for this if you'd like.

@webron
Copy link
Contributor

webron commented Apr 6, 2017

@dwilson6 we're always looking for community contributions. Nobody has started working on this issue yet.

As for the other thing you bring up, please open a separate ticket. I don't really follow what you're saying, but there are better developers than me on the project who will ;)

@dwilson6
Copy link

I was going to look at this today but it looks like @bodnia has it almost done

bodnia added a commit to bodnia/swagger-js that referenced this issue Apr 14, 2017
@ponelat
Copy link
Member Author

ponelat commented Apr 18, 2017

UPDATE:
Changed the order, to respect the user override requestContentType

@bodnia
Copy link
Contributor

bodnia commented Apr 18, 2017

@ponelat when we do not have any content and (body/form) we should add a content-type for thing that we do not pass, is this correct?

@ponelat
Copy link
Member Author

ponelat commented Apr 18, 2017

you're right.
If the user does feel like overriding this, they should use an explicit header. requestContentType does only make sense for when the client has a body.

@bodnia
Copy link
Contributor

bodnia commented Apr 19, 2017

fixed #1016

@bodnia bodnia closed this as completed Apr 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants