Skip to content

Exception when multiple OpenAPI services refrences is added in Visual Studio 2019 (swagger endpoints) #18204

@vsfeedback

Description

@vsfeedback

This issue has been moved from a ticket on Developer Community.


I try to use the service reference OpenAPI in Visual Studio 2019, to generate clients based on existing swagger endpoints. It works fine when one endpoint is added, but multiple endpoints in different namespaces does not work.
The reason is that the autogenerated APIException class is only generated in in the first "OpenApiReference".
I tried to set the option "generateExceptionClasses" but it didn't have any effect.
Also tried to give the exception different names with the option "exceptionClass", but the exception class was only created in the first client.

This is the code that fails:

  <ItemGroup>
    <OpenApiReference Include="OpenAPIs\api1Swagger.json" CodeGenerator="NSwagCSharp" Namespace="API1">
      <SourceUri>https://api1/swagger/v1/swagger.json</SourceUri>
      <ClassName>{controller}Client</ClassName>
      <OutputPath>API1Client.cs</OutputPath>
    </OpenApiReference>
    <OpenApiReference Include="OpenAPIs\api2Swagger.json" CodeGenerator="NSwagCSharp" Namespace="API2">
      <SourceUri>https://api2/swagger/v1/swagger.json</SourceUri>
      <ClassName>{controller}Client</ClassName>
      <OutputPath>API2Client.cs</OutputPath>
    </OpenApiReference>
  </ItemGroup>

It's possible to solve the problem with the following code, but I don't like to reference to API1 in API2:

  <ItemGroup>
    <OpenApiReference Include="OpenAPIs\api1Swagger.json" CodeGenerator="NSwagCSharp" Namespace="API1">
      <SourceUri>https://api1/swagger/v1/swagger.json</SourceUri>
      <ClassName>{controller}Client</ClassName>
      <OutputPath>API1Client.cs</OutputPath>
    </OpenApiReference>
    <OpenApiReference Include="OpenAPIs\api2Swagger.json" CodeGenerator="NSwagCSharp" Namespace="API2">
      <SourceUri>https://api2/swagger/v1/swagger.json</SourceUri>
      <ClassName>{controller}Client</ClassName>
      <OutputPath>API2Client.cs</OutputPath>
      <Options>/ExceptionClass:"API1. ApiException"</Options>
    </OpenApiReference>
  </ItemGroup>

Any way to slove this?


Original Comments

Visual Studio Feedback System on 12/5/2019, 00:01 AM:

We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.

Visual Studio Feedback System on 12/6/2019, 01:28 AM:

Thank you for sharing your feedback! Our teams prioritize action on product issues with broad customer impact. See details at: https://docs.microsoft.com/en-us/visualstudio/ide/report-a-problem?view=vs-2017#faq. In case you need answers to common questions or need assisted support, be sure to use https://visualstudio.microsoft.com/vs/support/. We’ll keep you posted on any updates to this feedback.


Original Solutions

(no solutions)

Metadata

Metadata

Assignees

No one assigned

    Labels

    affected-fewThis issue impacts only small number of customersarea-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesbugThis issue describes a behavior which is not expected - a bug.feature-openapiseverity-minorThis label is used by an internal tool

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions