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

[Javascript] Problems on deserialize text type and on file response #3297

Open
ghost opened this issue Jul 5, 2016 · 5 comments
Open

[Javascript] Problems on deserialize text type and on file response #3297

ghost opened this issue Jul 5, 2016 · 5 comments

Comments

@ghost
Copy link

ghost commented Jul 5, 2016

Hi,
I'm testing my api on the generated nodejs(javascript) client. I've found two problems, that break the client when called.
First:
when I've a call that return text/plain, SuperAgent initialize the body to {}, so data it's never null and doesn't verify the if condition, and in the end it gives an error.
deserialize
I've done a fix for my case, just adding this line in the if clauses
"if (data == null || (returnType==='String' && Object.keys(data).length === 0 && data.constructor === Object))" but I think this is a bug and has to be correct

Second:
I've a call where the response is a file
file
And this is fine on other language like java or ruby, but not on javascript. It gives this error:
file2

Thanks in advance for support

I'm using Swagger-codegen version 2.2.0

@wing328
Copy link
Contributor

wing328 commented Jul 5, 2016

@donFotter I think you're correct in saying that the Javascript API client does not support plain text response or binary data response at the moment.

May I know if you've cycle to contribute a fix to address the issue?

Here is a good starting point: https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/resources/Javascript/ApiClient.mustache#L297

@ghost
Copy link
Author

ghost commented Jul 6, 2016

I'm sorry, but I'm really in trouble with the development of the new api which I'm working on.
As posted before, I've made an own solution(changing the if clause). If this could help, consider this my contribution

@wing328
Copy link
Contributor

wing328 commented Jul 7, 2016

@donFotter that's ok. Thanks again for sharing the fix.

We'll see if someone from the community has cycle to contribute a fix.

@wing328 wing328 modified the milestones: v2.3.0, v2.2.0 Jul 7, 2016
@wing328 wing328 modified the milestones: v2.2.1, v2.2.2 Aug 8, 2016
@wing328 wing328 modified the milestones: v2.2.2, Future Feb 15, 2017
@jfiala
Copy link
Contributor

jfiala commented Mar 1, 2017

I've had a similar problem with an API returning content-type text but in json format.
If the returnType is an array, convertToType will fail when accessing it with the map property.

There are two option to fix this:
a) set the Content-Type to "application/json", then superagent will be able to parse and will return response.body.
b) parse the response.text as json:
Here we need to parse the data as JSON before passing it on
// Parse the response text, otherwise we cannot access it in the next step convertToType
data = JSON.parse(response.text);

However, of course this will only work for Json data so I'm not sure about unintended side-effects.
Anyway, the current implementation fails for Json data of format Array.
Of course option a) is the cleaner solution and is recommended.

If agreed upon, I can supply a PR to parse the response.text as JSON as suggested above. This will only be applied if superagent is unable to supply the response.body itself.

@wing328
Copy link
Contributor

wing328 commented Apr 26, 2017

If agreed upon, I can supply a PR to parse the response.text as JSON as suggested above. This will only be applied if superagent is unable to supply the response.body itself.

When you've time, please file a PR so that we can review the change.

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

2 participants