我正在尝试将项目改编为.net5,并希望使用添加 OpenAPI 服务引用的新功能。据我了解,NSwag 将用于生成客户端。我过去已经使用 NSwag 来实现此目的,我可以使用clientBaseInterface选项来指定客户端接口的基本接口,即
interface IClient: **IClientBase** {}
class Client: IClient {}
Run Code Online (Sandbox Code Playgroud)
另请参阅https://github.com/RicoSuter/NSwag/issues/2772。
我尝试对我的 .net5 项目使用以下配置,但不会为生成的类型指定基本接口:
<ItemGroup>
<OpenApiReference Include="openapi.json" CodeGenerator="NSwagCSharp" Namespace="MyNamespace">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<ClassName>MyOpenApiClient</ClassName>
<OutputPath>MyOpenApiClient.cs</OutputPath>
<Options>/GenerateClientInterfaces:true /UseBaseUrl:false /ExceptionClass:OpenApiException /ClientBaseInterface:MyBaseInterface</Options>
</OpenApiReference>
</ItemGroup>
Run Code Online (Sandbox Code Playgroud)
有谁知道如何在 .net 项目文件中使用此选项?
更新: 由于 NSwag 正在创建部分类和接口,一个简单的解决方法是在部分接口中添加 IClientBase 接口,即
// partial extension
partial interface IClient : **IClientBase** {}
// generated code
partial interface IClient {}
partial class Client: IClient {}
Run Code Online (Sandbox Code Playgroud)
然而,了解我们是否可以直接在 .net 项目文件中管理它仍然很有趣。