There's only one use:
\Drupal\jsonapi\Resource\EntityResource::buildWrappedResponse() does this:

  protected function buildWrappedResponse($data, $response_code = 200, array $headers = []) {
    return new ResourceResponse(new DocumentWrapper($data), $response_code, $headers);
  }

DocumentWrapper(Interface) has zero meaningful documentation, nor does it refer back to http://jsonapi.org/format — which would have been the indirect way of figuring out why this exists and what purpose it serves.

I suspect it's a wrapper for normalized entity objects (or any normalized data, really), to correspond to http://jsonapi.org/format/#document-structure. But if that's the case, it's extremely confusing that there's only a getData() method and not also getErrors() and getMeta() (at minimum, not even talking about links or jsonapi or included).

Comments

Wim Leers created an issue. See original summary.

wim leers’s picture

Component: Documentation » Code
Priority: Normal » Major
Issue tags: +maintainability

I also just realized part of the reason why I have a hard time understanding this at all: \Drupal\jsonapi\Resource\DocumentWrapper(Interface), but the corresponding (de)normalizer is called \Drupal\jsonapi\Normalizer\DocumentRootNormalizer!

This should be made consistent.

Also, I think JsonApiDocument and JsonApiDocumentNormalizer would be a whole lot clearer. Or even JsonApiDocumentTopLevel and JsonApiDocumentTopLevelNormalizer.This would clearly correspond 1:1 to http://jsonapi.org/format/#document-top-level.

e0ipso’s picture

+1 to JsonApiDocumentTopLevel and JsonApiDocumentTopLevelNormalizer.

wim leers’s picture

Assigned: Unassigned » wim leers

Alright!

wim leers’s picture

Title: Document or remove DocumentWrapper(Interface) » Rename DocumentWrapper to JsonApiDocumentTopLevel and DocumentRootNormalizer to JsonApiDocumentTopLevelNormalizer
Status: Active » Needs review
StatusFileSize
new30.63 KB

Done.

Did what we described in #2 + #3. Plus:

  1. \Drupal\jsonapi\Normalizer\RelationshipNormalizer no longer gets this injected, because it didn't use it anyway!
  2. removed the corresponding interfaces, because these are internal APIs anyway, there's no point in providing interfaces. It's fine to typehint to the specific implementation class then.
15 files changed, 64 insertions(+), 113 deletions(-)

Status: Needs review » Needs work

The last submitted patch, 5: 2831185-5.patch, failed testing.

wim leers’s picture

Status: Needs work » Needs review
StatusFileSize
new1.03 KB
new31.22 KB

Fixing a few nitpicky oversights.

wim leers’s picture

StatusFileSize
new4.5 KB
new34.76 KB

I totally missed DocumentRootNormalizerTest.

The last submitted patch, 7: 2831185-6.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 8: 2831185-8.patch, failed testing.

wim leers’s picture

Status: Needs work » Needs review
StatusFileSize
new35.43 KB
new1.18 KB

Oh hah apparently there's also \Drupal\Tests\jsonapi\Unit\Normalizer\DocumentRootNormalizerTest — #8 fixed the kernel test.

Status: Needs review » Needs work

The last submitted patch, 12: 2831185-12.patch, failed testing.

wim leers’s picture

Status: Needs work » Needs review
StatusFileSize
new35.71 KB
new993 bytes

Turns out \Drupal\Tests\jsonapi\Unit\Normalizer\ConfigEntityNormalizerTest was incredibly wrong, and hence I'm required to update it here.

wim leers’s picture

e0ipso’s picture

Status: Needs review » Reviewed & tested by the community

Merging.

  • e0ipso committed b064a20 on 8.x-1.x authored by Wim Leers
    refactor(Maintainability) Rename DocumentWrapper to...
e0ipso’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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