Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DartObject getField doesn't retrieve field from parent #375

Closed
RicardoRB opened this issue Aug 15, 2022 · 2 comments
Closed

DartObject getField doesn't retrieve field from parent #375

RicardoRB opened this issue Aug 15, 2022 · 2 comments

Comments

@RicardoRB
Copy link

Having an annotation that extends from another abstract annotation with fields, isn't possible to get the field from the children with _parentAnnotationTypeChecker.firstAnnotationOf(methodElement).

Acceptance Criteria:

GIVEN

abstract class Bind {
  const Bind([this.path = '']);

  /// The path to bind the property to.
  /// If not set, the entire route would be by [Controller].
  final String path;
}

class Get extends Bind {
  const Get([super.path]);
}

WHEN
city_controller.dart

@Controller('/cities')
class CityController {
  CityController(this._cityService);

  final CityService _cityService;

  @Get()
  Response getCities(Request request) {
    return Response.ok(jsonEncode(_cityService.getCities()));
  }

  @Get('/<id>')
  Response getCity(@PathParam() int id) {
    return Response.ok(_cityService.getCity(id));
  }
}

controller_generator.dart

const _bindType = TypeChecker.fromRuntime(Bind);
final controllerPath = controllerAnnotation.read('path').stringValue;
final bind = _bindType.firstAnnotationOf(methodElement);
final path = '$controllerPath${bind?.getField('path')?.toStringValue() ?? ''}';

OUTPUT
['/cities','/cities']

EXPECTED
['/cities','/cities/<id>']

@srawlins
Copy link
Member

Is this referring to the DartObject class defined in package:analyzer?

@RicardoRB
Copy link
Author

Is this referring to the DartObject class defined in package:analyzer?

You are right, closing the issue here, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants