CT14.IT
CT14.IT

Reputation: 1747

VS2019 Adding Connected Service via OpenAPI not generating all required classes

We have a swagger generated OpenAPI definition which has an endpoint that defines it's responses as the following:

"responses": {
  "200": {
    "description": "Success",
    "content": {
      "text/plain": {
        "schema": {
          "type": "file"
        }
      },
      "application/json": {
        "schema": {
          "type": "file"
        }
      },
      "text/json": {
        "schema": {
          "type": "file"
        }
      }
    }
  }
}

When using NSwagStudio to generate a C# Client from swagger.json, the response type translates into a class which gets defined into the generated file like so...

NSwagStudio Generated Endpoint example

public System.Threading.Tasks.Task<FileResponse> FileAsync(LayeredVideo body)
{
    return FileAsync(body, System.Threading.CancellationToken.None);
}

NSwagStudio Geneated FileResponse class

[System.CodeDom.Compiler.GeneratedCode("NSwag", "13.15.10.0 (NJsonSchema v10.6.10.0 (Newtonsoft.Json v12.0.0.0))")]
public partial class FileResponse : System.IDisposable
{
    private System.IDisposable _client;
    private System.IDisposable _response;

    public int StatusCode { get; private set; }

    public System.Collections.Generic.IReadOnlyDictionary<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.IReadOnlyDictionary<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()
    {
        Stream.Dispose();
        if (_response != null)
            _response.Dispose();
        if (_client != null)
            _client.Dispose();
    }
}

however if I attempt to generate the same C# client within VS2019 via the Connected Services interface while the endpoint itself generates the same, it does not define the actual FileResponse class

VS2019 Generated Endpoint example

public System.Threading.Tasks.Task<FileResponse> FileAsync(LayeredVideo body)
{
    return FileAsync(body, System.Threading.CancellationToken.None);
}

This leads to the following error in the generated code.

Screenshot of the error

By my understanding, NSwagStudio and Connected Services use basically the same tech in the background to generate code, so I am confused as to why one solution generates working code and the other doesn't.

Any ideas?

Upvotes: 1

Views: 1025

Answers (0)

Related Questions