Hi!
I've got a file returning endpoint defined in openapi 3.0.1.
Result of endpoint defined as prescribed there: https://swagger.io/docs/specification/describing-responses/#response-that-returns-a-file:
>
responses:
'200':
description: OK
content:
application/octet-stream:
schema:
type: string
format: binary
(!) Autorest-generated code for this endpoint tries to read result content as JSON instead of Stream:
``` C#
// Deserialize Response
if ((int)_statusCode == 200)
{
_responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
try
{
_result.Body = SafeJsonConvert.DeserializeObject
}
catch (JsonException ex)
{
_httpRequest.Dispose();
if (_httpResponse != null)
{
_httpResponse.Dispose();
}
throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
}
}
If I try to change type to "file", response interpreted properly, as a stream:
``` C#
// Deserialize Response
if ((int)_statusCode == 200)
{
_result.Body = await _httpResponse.Content.ReadAsStreamAsync().ConfigureAwait(false);
}
But the schema with type "file" is invalid in OpenAPI 3.
Looks like a bug. It seems autorest should generate stream-returning code for "format: binary" in any case.
I'm having the exact same issue with the Java client generator too.
Using your suggestion of changing the type to string and the format to binary does make the client generate an InputStream in Java too, but unfortunately I can't seem to read the data off of it reliably - the connection seems to get reset after reading a few bytes.
Do you have any feedback about it?
I'm trying to get around by applying custom transform:
directive:
- from: swagger-document
where: $.paths.*.get.responses.*.content."application/octet-stream".schema[]
transform: |
{
$.type = "file";
$.format = "binary";
}
reason: polyfill
But no luck, the type not changed.
Could you give me any feedback about this transformation at least? Why it does not work? Selector is right...
Believe this is resolve in the latest version of core with the generator v3. Resulting operation:

Please reopen if you are still having problems
Most helpful comment
I'm having the exact same issue with the Java client generator too.
Using your suggestion of changing the type to string and the format to binary does make the client generate an InputStream in Java too, but unfortunately I can't seem to read the data off of it reliably - the connection seems to get reset after reading a few bytes.