frhagn / Typewriter

Automatic TypeScript template generation from C# source files
http://frhagn.github.io/Typewriter
Apache License 2.0
537 stars 132 forks source link

Question: How to remove API method parameters of type Interface #307

Open MarcoGaribaldi opened 5 years ago

MarcoGaribaldi commented 5 years ago

Hi!

ASP.NET Core API controllers allow to inject interfaces into a controller method as in the following example:

public async Task<IActionResult> GetEmployeeAsync([FromServices] IGetEmployeeServiceAsync service, [FromQuery] int id)

I want to skip the service parameter when generating an Angular data service. I have managed to resolve the matter this way:

$Methods[
public $name = ($Parameters(p => p.Name != "service")[$name: $Type][, ]) : ng.IHttpPromise<$ReturnType> => 
{
    return this.$http<$ReturnType>({
        url: '$ApiUrl', 
        method: '$HttpMethod', 
        data: $RequestData
    });
}
]

It works but it is not robust enough, as it relies on the fact that the parameter is named service. Is there a better way to skip parameters of type interface?