Skip to content

Exception in client when processing binary response #1932

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

Closed
xplicit opened this issue Mar 7, 2017 · 3 comments
Closed

Exception in client when processing binary response #1932

xplicit opened this issue Mar 7, 2017 · 3 comments

Comments

@xplicit
Copy link

xplicit commented Mar 7, 2017

When response schema contains binary format for representing byte [] array similar like in the sample, autorest should generate method with return type byte[]

"200": {
"description": "successful operation",
"schema": {
"type": "string",
"format": "binary"
}
},

But it generates method with return type string which tries to convert binary array of bytes to string and when method is called, the exception is raised.

public static string FindPetsWithByteArray(this ISwaggerPetstore operations, long petId)
{
return operations.FindPetsWithByteArrayAsync(petId).GetAwaiter().GetResult();
}

Exception is thrown at this line:

_result.Body = SafeJsonConvert.DeserializeObject<string>(_responseContent, DeserializationSettings);

Releated info about binary format:

OAI/OpenAPI-Specification#50 (comment)
OAI/OpenAPI-Specification#430

@mannyvw
Copy link

mannyvw commented Apr 20, 2017

Did you get anywhere with this having the same issue @xplicit . At moment am thinking might have to convert end point to return base64 encoded data but not ideal

thanks

@fearthecowboy
Copy link
Contributor

Have no idea how we missed seeing this.

Is the whole response a byte array? if so, you should use stream for the response.

Otherwise, if the response is a json with embedded binary data, ... you have to encode it as a string. JSON doesn't support directly embedded binary data.

@MiYanni
Copy link
Contributor

MiYanni commented Nov 7, 2019

Answer provided. Closing.

@MiYanni MiYanni closed this as completed Nov 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants