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 annotation
  • link_context → ✅ because it is described by the annotation
  • operation → ❌ because it is NOT described by the annotation
  • published_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

Wim Leers created an issue. See original summary.

wim leers’s picture

Issue summary: View changes
wim leers’s picture

Title: \Drupal\jsonapi_hypermedia\Annotation\JsonapiHypermediaLinkProvider has incomplete documentation » The \Drupal\jsonapi_hypermedia\Annotation\JsonapiHypermediaLinkProvider annotation
Issue summary: View changes
wim leers’s picture

Issue summary: View changes
wim leers’s picture

Issue summary: View changes

  • gabesullice committed a012d27 on 8.x-1.x
    Issue #3077985 by gabesullice, Wim Leers: The \Drupal\jsonapi_hypermedia...
gabesullice’s picture

Status: Active » Fixed

I'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.

wim leers’s picture

👍

  • gabesullice committed 8b7f944 on 8.x-1.x
    Issue #3079586 by gabesullice, Wim Leers: Followup to issue #3077985:...

  • gabesullice committed 33a679d on 8.x-1.x authored by Wim Leers
    Issue #3079586 by gabesullice, Wim Leers: Followup to issue #3077985:...
  • gabesullice committed 77b39f6 on 8.x-1.x authored by Wim Leers
    Issue #3079586 by gabesullice, Wim Leers: Followup to issue #3077985:...
  • gabesullice committed e54d6e1 on 8.x-1.x authored by Wim Leers
    Issue #3079586 by gabesullice, Wim Leers: Followup to issue #3077985:...
wim leers’s picture

RE: concern 2. I like how you've added a default_configuration annotation key (although I think that could use a better name, such as meta, but then I'm not sure that's truly better — naming things is hard 🤓).

RE: concern 3. AuthenticationLinkProvider is a nice addition!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.