Problem/Motivation

#2977669: Spec Compliance: some entity types have an "id", "type" or "uuid" field, this violates the spec introduced "native" support for:

  • aliasing fields
  • omitting fields

Proposed resolution

Rather than having JSON API Extras maintain its own logic for this, rely on JSON API instead.

Complication: this will only work in JSON API 2.x. This is why we'll commit to JSON API Extras 3.x (which will be JSON API 2.x compatible).

Remaining tasks

  1. Patch
  2. Review
  3. Decide when to commit, or to which branch.

User interface changes

None.

API changes

None.

Data model changes

None.

Comments

Wim Leers created an issue. See original summary.

wim leers’s picture

Status: Active » Needs review
StatusFileSize
new5.98 KB
wim leers’s picture

  1. +++ b/jsonapi_extras.services.yml
    @@ -10,12 +10,12 @@ services:
    -    arguments: ['@jsonapi.link_manager', '@jsonapi.resource_type.repository', '@entity_type.manager']
    +    parent: serializer.normalizer.entity.jsonapi
    ...
    -    arguments: ['@jsonapi.link_manager', '@jsonapi.resource_type.repository', '@entity_type.manager']
    +    parent: serializer.normalizer.config_entity.jsonapi
    

    These are bugfixes against HEAD, that JSON API Extras needs anyway. This makes it MUCH more robust.

  2. +++ b/src/Entity/JsonapiResourceConfig.php
    @@ -121,4 +121,29 @@ class JsonapiResourceConfig extends ConfigEntityBase {
    +  public function getFieldMapping() {
    
    +++ b/src/ResourceType/ConfigurableResourceType.php
    @@ -55,7 +55,10 @@ class ConfigurableResourceType extends ResourceType {
    +      $resource_config->getFieldMapping()
    

    This is the key change: we construct some value to feed in to JSON API's infra.

  3. +++ b/src/ResourceType/ConfigurableResourceType.php
    @@ -69,20 +72,6 @@ class ConfigurableResourceType extends ResourceType {
    -  public function getPublicName($field_name) {
    ...
    -  public function getInternalName($field_name) {
    
    @@ -95,16 +84,6 @@ class ConfigurableResourceType extends ResourceType {
    -  public function isFieldEnabled($field_name) {
    
    @@ -189,24 +168,4 @@ class ConfigurableResourceType extends ResourceType {
    -  private function translateFieldName($field_name, $from, $to) {
    

    And now all this can be deleted.

e0ipso’s picture

Decide when to commit, or to which branch.

We'll commit to jsonapi_extras-3.x.

e0ipso’s picture

Issue summary: View changes
e0ipso’s picture

Status: Needs review » Needs work

Thanks for this! This is very much needed for 3.x


  1. +++ b/src/Entity/JsonapiResourceConfig.php
    @@ -121,4 +121,29 @@ class JsonapiResourceConfig extends ConfigEntityBase {
    +  public function getFieldMapping() {
    

    It feels that this can be computed once and stored in a static cache.

  2. +++ b/src/ResourceType/ConfigurableResourceType.php
    +++ b/src/ResourceType/ConfigurableResourceType.php
    @@ -55,7 +55,10 @@ class ConfigurableResourceType extends ResourceType {
    
    @@ -55,7 +55,10 @@ class ConfigurableResourceType extends ResourceType {
           $entity_type_id,
           $bundle,
           $deserialization_target_class,
    -      (bool) $resource_config->get('disabled')
    +      (bool) $resource_config->get('disabled'),
    +      TRUE,
    +      TRUE,
    +      $resource_config->getFieldMapping()
         );
    

    This contains the key change, but does not apply to the current dev branch.

wim leers’s picture

Assigned: Unassigned » wim leers

Will reroll!

wim leers’s picture

Title: Use aliasing capabilities provided by JSON API 2.x » [PP-1] Use aliasing capabilities provided by JSON API 2.x
Status: Needs work » Postponed

This cannot land without jsonapi_extras becoming compatible with jsonapi 2.x first. Hence this is blocked on #3004582: Make JSON API Extras 2.x (next release: 2.10) compatible with JSON API 2.0-beta2.

e0ipso’s picture

Title: [PP-1] Use aliasing capabilities provided by JSON API 2.x » Use aliasing capabilities provided by JSON API 2.x
Status: Postponed » Needs work
e0ipso’s picture

Status: Needs work » Closed (outdated)

I think this work was already done.

e0ipso’s picture

Status: Closed (outdated) » Needs work

It seems that the previous fix mentioned in #10 was wrong. This shall fix it.

e0ipso’s picture

Status: Needs work » Needs review
StatusFileSize
new1.53 KB

  • e0ipso committed 8ed6447 on 8.x-3.x
    Issue #2986408 by e0ipso, Wim Leers: Use aliasing capabilities provided...
e0ipso’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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