【问题标题】:Is it possible in NSwag to generate just C# client interfaces and annotate their methods with some custom attributes?NSwag 是否可以只生成 C# 客户端接口并使用一些自定义属性注释它们的方法?
【发布时间】:2020-09-19 20:23:41
【问题描述】:

我正在使用 NSwag 为我的 asp.net 核心 web api 生成 C# rest 客户端。目前,我只需要生成客户端接口而不是类本身。我尝试了以下设置来仅生成 C# 客户端接口,但它既不生成也不生成接口。

    GenerateClientClasses = false 
    GenerateClientInterfaces = true

我的设置有什么问题吗?

另外,有没有办法扩展或更改客户端接口的生成代码。例如,如何使用一些自定义属性注释客户端接口方法?例如:

public partial interface IGetEmployeeByIdClient
{
    // How to add the following custom attributes to the generated client interface method
    [MyCustomerAttribute("/api/v1/GetEmployeeById/{id}"] )
    System.Threading.Tasks.Task<GetEmployeeByIdQueryResult> GetEmployeeByIdAsync(string id);  
}

【问题讨论】:

  • 我也遇到了同样的问题,请问你有什么进展吗?

标签: c# .net dotnet-httpclient nswag


【解决方案1】:

这看起来并不直观,但我设法获得了具有以下配置的接口。

var settings = new TypeScriptClientGeneratorSettings
{
    GenerateClientClasses = false,
    GenerateDtoTypes = true,
    GenerateClientInterfaces = true,
    TypeScriptGeneratorSettings =
    {
        TypeStyle = NJsonSchema.CodeGeneration.TypeScript.TypeScriptTypeStyle.Interface
    }
};

【讨论】:

    猜你喜欢
    • 2019-12-08
    • 1970-01-01
    • 2021-11-18
    • 2020-01-29
    • 2018-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-15
    相关资源
    最近更新 更多