redstone-dart / redstone

A metadata driven microframework for Dart.
http://redstone-dart.github.io/redstone
MIT License
342 stars 42 forks source link

Plugins not working within Groups in v0.6 #122

Closed cgarciae closed 9 years ago

cgarciae commented 9 years ago

For test purposes I have this class

class User {
  @Field() String name;
}

and this test route which decoded to JSON in v0.5 but fails to decode in v0.6

@app.Group ('/test')
class TT {

  @app.Route('/test')
  @Encode()
  testTest() async {
    return new User()
      ..name = "Cristian";
  }
}

If you extract the method testTest from the Group as a top level function

@app.Route('/test')
@Encode()
testTest() async {
  return new User()
    ..name = "Cristian";
}

it works ok. @luizmineo any hints on this?

luizmineo commented 9 years ago

It seems a bug in the Processor class, which implements the Manager interface. More specifically, take a look at this method

Try to change it to:

  List<HandlerMetadata> _getRoutes(dynamic metadata) {
    if (metadata is ApplicationMetadata) {
      return []
        ..addAll(metadata.routes)
        ..addAll(metadata.groups.expand(_getRoutes));
    } else if (metadata is GroupMetadata) {
      return []
        ..addAll(metadata.defaultRoutes)
        ..addAll(metadata.routes);
    }

    return [];
  }

I didn't test it myself, so I can't guarantee that this fix the problem.

cgarciae commented 9 years ago

@luizmineo thanks! I'll do the change, test and update the repo.

cgarciae commented 9 years ago

Worked!