Exception in client when processing binary response #1932

Open
xplicit opened this Issue Mar 7, 2017 · 2 comments

Comments

Projects
None yet
3 participants
@xplicit

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

This comment has been minimized.

Show comment
Hide comment
@mannyvw

mannyvw 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

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

This comment has been minimized.

Show comment
Hide comment
@fearthecowboy

fearthecowboy Jul 18, 2017

Member

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.

Member

fearthecowboy commented Jul 18, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment