Reputation: 123
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);
}
Upvotes: 9
Views: 3832
Reputation: 755
You have to set GenerateClientClasses
to true
to generate the class and then set SuppressClientClassesOutput
to true
to not output the class. The interface will now reflect the methods in the class but will not be a part of your output.
Upvotes: 0
Reputation: 101
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
}
};
Upvotes: 6