Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.
At the moment, I just need to generate the client interfaces and not the classes themselves.
I tried the following settings to generate just C# client interfaces but it does not generate nor classes neither interfaces.

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);  
}
like image 762
Sayari Avatar asked Oct 26 '22 17:10

Sayari


1 Answers

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
    }
};
like image 104
Damian Fijorek Avatar answered Oct 29 '22 22:10

Damian Fijorek