RouteInfo.fromJson constructor

RouteInfo.fromJson(
  1. Map<String, dynamic> json,
  2. String fullRoute
)

Builds a RouteInfo from a JSON node representing a single path item.

The json map is expected to contain one or more HTTP method keys (e.g., get, post, delete) with their corresponding details. The fullRoute parameter is the path key from the parent paths object.

Implementation

factory RouteInfo.fromJson(Map<String, dynamic> json, String fullRoute) {
  late HttpMethodType httpMethod;
  late HttpMethodInfo httpMethodInfo;
  json.forEach((method, info) {
    info as Map<String, dynamic>;
    httpMethod = HttpMethodType.values.firstWhere((e) {
      return e.name.toLowerCase() == method.toLowerCase();
    }, orElse: () {
      return HttpMethodType.values.first;
    });
    httpMethodInfo = HttpMethodInfo.fromJson(info);
  });
  return RouteInfo(
    fullRoute: fullRoute,
    httpMethod: httpMethod,
    httpMethodInfo: httpMethodInfo,
  );
}