RicoSuter/NSwag

FileResponse compile-time error

Open

#1,875 opened on Jan 8, 2019

View on GitHub
 (20 comments) (0 reactions) (0 assignees)C# (1,189 forks)batch import
help wantedproject: NSwag.CodeGeneration.CSharp (Controllers)type: bug

Repository metrics

Stars
 (6,291 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

Hi,

I'I have one issue with NSWAG (i'm using the latest 12.0.10.0).

When i have in openapi 3.0 definition , response for api which downloads a file, like this:

responses: '200': description: The content of the file content: application/octet-stream: schema: type: string format: binary

In my C# Web Api controller generated code , i have compile-time error in:

HttpResponseMessage response = Request.CreateResponse(status, result.Result);

where Result doesn't exists in FileResponse class:

  public partial class FileResponse : System.IDisposable
  {
    private System.IDisposable _client;
    private System.IDisposable _response;

    public int StatusCode { get; private set; }

    public System.Collections.Generic.Dictionary<string, System.Collections.Generic.IEnumerable<string>> Headers { get; private set; }

    public System.IO.Stream Stream { get; private set; }

    public bool IsPartial
    {
      get { return StatusCode == 206; }
    }

    public FileResponse(int statusCode, System.Collections.Generic.Dictionary<string, System.Collections.Generic.IEnumerable<string>> headers, System.IO.Stream stream, System.IDisposable client, System.IDisposable response)
    {
      StatusCode = statusCode;
      Headers = headers;
      Stream = stream;
      _client = client;
      _response = response;
    }

    public void Dispose()
    {
      if (Stream != null)
        Stream.Dispose();
      if (_response != null)
        _response.Dispose();
      if (_client != null)
        _client.Dispose();
    }
  }

So either this is a compile-time error with generated code or i should use some other type of response ?

Thank you.

Contributor guide