[英]Is it possible in NSwag to generate just C# client interfaces and annotate their methods with some custom attributes?
I am using NSwag to generate C# rest client for my asp.net core web api.我正在使用 NSwag 为我的 asp.net 核心 web api 生成 C# rest 客户端。 At the moment, I just need to generate the client interfaces and not the classes itself.
目前,我只需要生成客户端接口而不是类本身。 I tried the following settings to generate just C# client interfaces but it does not generate nor classes neither interfaces.
我尝试了以下设置来仅生成 C# 客户端接口,但它既不生成也不类也不生成接口。
GenerateClientClasses = false
GenerateClientInterfaces = true
Is there anything wrong with my settings?我的设置有问题吗?
Also, Is there any way to extend or change the generated code of the client interfaces.另外,有什么方法可以扩展或更改客户端接口的生成代码。 For example how I can annotate the client interface methods with some custom attributes?
例如,我如何使用一些自定义属性来注释客户端接口方法? For example:
例如:
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);
}
This does not look intuitive but I managed to get just interfaces with following configuration.这看起来并不直观,但我设法通过以下配置获得了接口。
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.