getPaths function

Implementation

List<PathControllerReflectiveBinding> getPaths(ClassMirror mirror) {
  final paths = <PathControllerReflectiveBinding>[];
  Path? basePath;

  // If the class has a @Path specified, we'll set it as the base
  mirror.metadata.forEach((metadata) {
    if (metadata.type == pathAnnotation) {
      basePath = metadata.reflectee as Path;
    }
  });

  mirror.declarations.forEach((key, value) {
    value.metadata.forEach((meta) {
      if (_allHttpVerbs.contains(meta.type)) {
        // This is indeed a verb!
        final injectable = (meta.reflectee as RouteBindingDecorator);
        paths.add(PathControllerReflectiveBinding(
            (basePath?.path ?? '') + injectable.path,
            injectable.verb,
            value.simpleName,
            [...?(basePath?.middleware), ...injectable.middleware]));
      }
    });
  });

  return paths;
}