typescript-generator
typescript-generator copied to clipboard
Implement REST service layer generation technique which unfolds all arguments
Right now this framework could generate controller methods such as:
testControllerMethod( param1: string, param2: number, queryParams: { param3?: string; param4: number; }, data: entityDTO ): RestResponse<SomeData> ;
This means that the method interface is a simple wrapper around http controller which doesn't provide any abstraction over http controller.
The user who uses such methods should be aware of where parameters should go (it is a request parameter? is it a path variable? is it an entity data?).
I would suggest adding a feature flag which provides a service abstraction layer instead of a simple HttpClient wrapper.
Maybe something like: serviceLayerInsteadOfWrapperLayer: boolean
.
I think (not sure yet), that we could relay on null
value of an argument as an indicator for a value to not being provided to the HttpClient
.
So, maybe, we could generate an implementation like the next one:
testServiceMethod( param1: string, param2: number, param3?: string, param4: number, param5: entityDTO ): RestResponse<SomeData>
{
queryParams = {};
if(param3 != null){
queryParams["param3"] = param3;
}
queryParams["param4"] = param4;
return this.httpClient.request({ method: "POST", url: uriEncoding`some/path/${param1}/${param2}`, queryParams: queryParams, data: param5 });
}
@vojtechhabarta What do you think about it? Would it make sense to implement such a feature or do you see any problems if we relay on null
value for optional method arguments?