簡體   English   中英

在 NSwag 中是否可以只生成 C# 客戶端接口並使用一些自定義屬性注釋它們的方法?

[英]Is it possible in NSwag to generate just C# client interfaces and annotate their methods with some custom attributes?

我正在使用 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);  
}

這看起來並不直觀,但我設法通過以下配置獲得了接口。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM