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

A parameter in body that is json has to be explicitly serialized #1006

Closed
dwilson6 opened this issue Apr 7, 2017 · 4 comments
Closed

A parameter in body that is json has to be explicitly serialized #1006

dwilson6 opened this issue Apr 7, 2017 · 4 comments

Comments

@dwilson6
Copy link

dwilson6 commented Apr 7, 2017

I've noticed that if I have a POST endpoint with a parameter in the body that is of type object 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 from my server: unexpected token o in JSON at position 1...

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

Would it be reasonable to automatically convert an object to a string if the content type is application/json and it has an "in: body" parameter and the value of said parameter is an object?

Also, if an api endpoint only has one parameter, what do you think about allowing you to call the operation with the interface operation(value) instead of operation({param_name: value})? If an operation only has one parameter, you could check if the argument passed to the operation is an object with a property matching the parameter name (existing behavior) and if not then just use the passed in argument as the value for the parameter (after validating the type). Are there problems with that approach or does that make it too complicated?

@fehguy
Copy link
Contributor

fehguy commented Apr 7, 2017

You are using the 3.x version I take it? This is a regression

@dwilson6
Copy link
Author

dwilson6 commented Apr 7, 2017

Yes, I am

@fehguy
Copy link
Contributor

fehguy commented Apr 7, 2017

We'll get it addressed shortly

@buunguyen
Copy link
Contributor

Fixed in #1034

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