Invalid output JSON schema in UrlLinkEnhancer

Created on 10 September 2021, about 3 years ago
Updated 6 September 2023, about 1 year ago

Problem/Motivation

If link's options contain nested arrays, doUndoTransform() fails with following error.
TypeError: Adaptor Drupal\jsonapi_extras\Plugin\ResourceFieldEnhancerBase returned invalid output data: [] funktsioonist Drupal\jsonapi_extras\Plugin\ResourceFieldEnhancerBase->undoTransform() (real 66 failis /var/www/html/vendor/e0ipso/shaper/src/DataAdaptor/DataAdaptorTransformerTrait.php)

Proposed resolution

It seems that changing "options" type from "array" to "object" helps.

I'll see if I can manage writing a test.

🐛 Bug report
Status

Fixed

Version

3.0

Component

Code

Created by

🇪🇪Estonia luuph

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇺🇸United States shadcn

    @bbrala what's blocking here? How can I help?

  • 🇳🇱Netherlands Rene Bakx Netherlands

    Adding the backwards compatible as suggested in #14 actually breaks it again.

    'oneOf' => [
          ['type' => 'array'],
          ['type' => 'object'],
    ],
    

    The check on array fails in the external library mentioned in #6

    JsonSchema\Exception\InvalidArgumentException: Array is an invalid type for Array in JsonSchema\Constraints\TypeConstraint->validateType() 
    
  • Status changed to Needs review over 1 year ago
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    Composer require-dev failure
  • 🇪🇸Spain budalokko Girona

    the backwards compatible code in #13 or #15 fails because an empty array is also considered an object:

    https://github.com/justinrainbow/json-schema/blob/5174319bd0f45fe90bb88e...

    and oneOf only allows one of the items to be valid. Replacing oneOf by anyOf as in the attached patch fixes the issue in a backwards-compatible way.

  • 🇩🇪Germany osopolar 🇩🇪 GER 🌐

    I have a similar issue but my problem is with title. On a migration I only set the link uri but not the link title, therefore the link title is NULL (not empty string). Looking at the link fields table in the database suggest says that NULL is allowed for uri, title and options. Should we modify the schema respectively? At least for title?

      public function getOutputJsonSchema() {
        return [
          'type' => 'object',
          'properties' => [
            'uri' => ['type' => 'string'],
            'title' => [
              'anyOf' => [
                ['type' => 'null'],
                ['type' => 'string'],
              ],
            ],
            'options' => [
              'anyOf' => [
                ['type' => 'array'],
                ['type' => 'object'],
              ],
            ],
            'url' => ['type' => 'string'],
          ],
        ];
      }
    

    My current workaround is to set title to empty string in migration.

  • 🇩🇪Germany osopolar 🇩🇪 GER 🌐
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.0.7 + Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    17 pass
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    17 pass
  • 🇮🇹Italy dgsiegel

    When you create a node and put it into a menu via the sidebar, the title will be null. When you create or update a menu entry via admin/structure/menu, the title will be "". As we're not using any options, https://www.drupal.org/project/jsonapi_extras/issues/3232279#comment-146... 🐛 Invalid output JSON schema in UrlLinkEnhancer Fixed works for us.

    • bbrala committed b7098439 on 8.x-3.x
      Issue #3232279 by luuph, acbramley, budalokko, osopolar, bbrala, shadcn...
  • Status changed to Fixed about 1 year ago
  • 🇳🇱Netherlands bbrala Netherlands

    Ok, seems like extending is the way to go, i wish we had better test coverage here, but not gonna ask to fix that right now.

    Thanks for the help everyone.

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

Production build 0.71.5 2024