'Missing ApiException' compiler error
See original GitHub issueCurrently I have a project that uses multiple openapi.json v3 files. We used the official openapi tools described in this link: https://docs.microsoft.com/en-us/aspnet/core/web-api/microsoft.dotnet-openapi?view=aspnetcore-3.1
Because of the following code the generated c# client do not compile:
<ItemGroup>
<!-- @(CurrentOpenApiReference) item group will never contain more than one item. -->
<CurrentOpenApiReference>
<Command>$(_NSwagCommand) openapi2csclient /className:%(ClassName) /namespace:%(Namespace)</Command>
</CurrentOpenApiReference>
<CurrentOpenApiReference>
<Command Condition="! %(FirstForGenerator)">%(Command) /GenerateExceptionClasses:false</Command>
</CurrentOpenApiReference>
<CurrentOpenApiReference>
<Command>%(Command) /input:"%(FullPath)" /output:"%(OutputPath)" %(Options)</Command>
</CurrentOpenApiReference>
</ItemGroup>
Why did you make this design decision of not generating the Exception code for the remaining clients? The commented affirmation of only one item is not true.
I managed it to work by adding a AdditionalNamespaceUsages
options but for me it feels like a hack.
Below I added a sample of a csproj to reproduce the issue:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
<PackageReference Include="NSwag.ApiDescription.Client" Version="13.5.0" />
</ItemGroup>
<ItemGroup>
<OpenApiReference Include=".\OpenApi1.json">
<Namespace>Integration.ExternalApi1</Namespace>
</OpenApiReference>
<OpenApiReference Include=".\OpenApi2.json">
<Namespace>Integration.ExternalApi2</Namespace>
<!-- Workaround to make the generated code compile -->
<!--<Options>/AdditionalNamespaceUsages:Integration.ExternalApi1</Options>-->
</OpenApiReference>
</ItemGroup>
</Project>
Issue Analytics
- State:
- Created 3 years ago
- Reactions:11
- Comments:13
Top Results From Across the Web
Developers - 'Missing ApiException' compiler error -
Currently I have a project that uses multiple openapi.json v3 files. We used the official openapi tools described in this link: ...
Read more >ApiException required Throwable, found CustomException
When I do this the compiler is complaining telling me that the types are incompatible and that it's expecting Throwable but it found...
Read more >GetIdeas example - ApiException not instance of Throwable?
I ask because the error that java.rmi.RemoteException is not in your classpath indicates that you are missing some key dependencies. If it helps,...
Read more >» Compilation errors
error, 198, Argument $method is missing from the Docblock of getUrl ... error, 5, No summary for class \mixisLv\Reamaze\Exceptions\ApiException ...
Read more >Reference to type 'Task<>' claims it is defined in 'System. ...
Hi, I'm liking the idea of the new Checkout API (it's just what I need), and after following through the Quick Start guide...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I stumbled on this one when I had to generate a new version of a client side-by-side.
I had a look at https://github.com/RicoSuter/NSwag/blob/85ae862fd6d68173a201a79e0ad06e0be2ec5de1/src/NSwag.CodeGeneration.CSharp/CSharpClientGeneratorSettings.cs to check the options we have.
Finally, I decided not to use a generated ApiException class, but instead move that to my own file.
I do have the same issue. Used the following workaround:
Here is the ApiException code