call method
Fill the parameters for req and call the controller.
A path param that does not fit its type answers 404.
Without a DTO it is sync and gives what the controller gives.
Implementation
FutureOr<dynamic> call(DoxRequest req) {
int count = args.length;
if (count == 1 && args[0].kind == ArgKind.request) {
return fn(req);
}
List<dynamic> values = List<dynamic>.filled(count, null);
ControllerArg? dtoArg;
int dtoIndex = -1;
for (int i = 0; i < count; i++) {
ControllerArg arg = args[i];
switch (arg.kind) {
case ArgKind.request:
values[i] = req;
case ArgKind.path:
values[i] = _path(arg, req.param[arg.param]);
case ArgKind.dto:
dtoArg = arg;
dtoIndex = i;
}
}
// path params first: when one is wrong, the DTO is not checked
if (dtoArg != null) return _callWithDto(req, dtoArg, dtoIndex, values);
return _apply(values);
}