Is it possible in NSwag to generate just C# client interfaces and annotate their methods with some custom attributes?
Asked Answered
L

1

9

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);  
}
Lipinski answered 19/9, 2020 at 20:23 Comment(1)
I have the same problem, did you make any progress with it?Labile
B
6

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
    }
};
Backwater answered 8/10, 2021 at 13:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.