Problem/Motivation

The jsonapi_include parser is by default enabled in src/EventSubscriber/ResponseSubscriber.php onResponse method:

...
      $need_parse = TRUE; // Here: is default to TRUE.
      if ($this->config->get('jsonapi_include.settings')->get('use_include_query')) {
        $need_parse = !empty($event->getRequest()->query->get('jsonapi_include'));
      }

      if ($need_parse) {
...

And that policy is breaking jsonapi response when the module is enabled but the use_include_query config is not enabled, the module is working well when use_include_query config is enabled.

Steps to reproduce

Enable the module without enabling use_include_query on module configuration form.

Proposed resolution

By default set $need_parse to FALSE like so:

...
      $need_parse = FALSE;
      if ($this->config->get('jsonapi_include.settings')->get('use_include_query')) {
        $need_parse = !empty($event->getRequest()->query->get('jsonapi_include'));
      }

      if ($need_parse) {
...
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

b.khouy created an issue. See original summary.

b.khouy’s picture

b.khouy’s picture

Title: JSON:API include parser should be by default disabled » JSON:API include parser should be disabled by default (V1.7)
Version: 8.x-1.x-dev » 8.x-1.7
b.khouy’s picture

Status: Active » Needs review
b.khouy’s picture

Assigned: b.khouy » Unassigned

ptmkenny made their first commit to this issue’s fork.

ptmkenny’s picture

Status: Needs review » Needs work
Related issues: +#3452446: Add config schema

Thanks for this report. I agree this is a bug, but I think the issue is that the default config is never set. So I propose that we add a default config to this module.

ptmkenny’s picture

Version: 8.x-1.7 » 8.x-1.x-dev
ptmkenny’s picture

Actually, can you provide more info about how the module breaks the response? This may be a documentation issue.

By default, when use_include_query is not enabled, all responses are parsed for includes. If use_include_query is enabled, only responses with the query string are parsed.

ptmkenny’s picture

Status: Needs work » Closed (works as designed)
Related issues: +#3271379: Document what this module actually does and what the settings mean

I think this may just be an issue of bad documentation: https://www.drupal.org/project/jsonapi_include/issues/3271379

Please check the revised documentation/project page, and if this is still an issue, feel free to re-open.