Concern 1: class-level documentation
Class-level documentation is incomplete.
For examples, see the class-level docblocks at:
\Drupal\editor\Annotation\Editor\Drupal\Core\Layout\Annotation\Layout\Drupal\rest\Annotation\RestResource- …
Concern 2: annotation keys that aren't technically allowed
For example, \Drupal\jsonapi_hypermedia\Plugin\Derivative\EntityPublishedLinkProvider::getDerivativeDefinitions() generates the following annotation keys:
link_key→ ✅ because it is described by the annotationlink_context→ ✅ because it is described by the annotationoperation→ ❌ because it is NOT described by the annotationpublished_entity_key→ ❌ because it is NOT described by the annotation
I think I mentioned this before when we looked at an early PoC together. I don't remember the outcome. If we're going to keep it like this, this at least needs be documented explicitly.
What if Drupal core starts validating annotations in the future?
I looked at the published_entity_key example in detail. In principle it's possible to live without this, but the consequence then is a costly $entity->getEntityType()->getKey('published') lookup for every resource object. I see how incurring this cost once at build time instead of N times at run time is appealing. I'm fine with doing it at build time. But I am concerned about putting arbitrary keys in the annotation.
Usually, I would argue this is premature optimization. But $entity->getEntityType() will only incur an expensive lookup once per request per entity type, subsequent calls hit a static cache. Although it requires many function calls to reach that static cache. Which is why I'm leaning towards not calling this premature optimization.
Concern 3: all examples in the module use derivers
It'd be good to have at least one example not use a deriver. Even if it's a test one.
Comments
Comment #2
wim leersComment #3
wim leersComment #4
wim leersComment #5
wim leersComment #7
gabesulliceI've expanded and moved the class property documentation up to the class-level docs.
As we discussed in Slack, I think I'm going to remove the existing link providers and make some explicit examples instead. I think it's better for this module to provide a PHP-only API and have no impact on actual JSON:API responses itself.
I'll open another issue for that and credit you.
Comment #8
wim leers👍
Comment #11
wim leersRE: concern 2. I like how you've added a
default_configurationannotation key (although I think that could use a better name, such asmeta, but then I'm not sure that's truly better — naming things is hard 🤓).RE: concern 3.
AuthenticationLinkProvideris a nice addition!