Schema ContextBuilder Overrides Configured RefProvider and DataPreProcessor during configureContextDefaults()

Created on 2 October 2023, about 1 year ago
Updated 17 November 2023, about 1 year ago

Problem/Motivation

When trying to configure a schema context for processing, one might use the ContextBuilder::configureContextDefaults() method to ensure default configuration flags are set for consistency on the context object. This is preferred, but if a refProvider or dataPreProcessor were already assigned to the context, such as for custom processing, this method overrides those configured values with the service's configured defaults.

Steps to reproduce

  1. Create a new Schema Context object
  2. Assign a custom refProvider and/or dataPreProcessor
  3. Pass the context into configureContextDefaults()
  4. Compare the custom provider or preprocessor against the one now assigned to the context
  5. Observe they are no longer the same
    $preConfiguredRefProvider = new \Swaggest\JsonSchema\RemoteRef\Preloaded();
    $preConfiguredDataPreProcessor = \Drupal::service('patternkit.schema.data_preprocessor.factory')
      ->getPreProcessor('normalizer');
    $context = new \Swaggest\JsonSchema\Context($preConfiguredRefProvider);
    \Drupal::service('patternkit.schema.context_builder')->configureContextDefaults($context);

    assert($preConfiguredRefProvider !== $context->getRemoteRefProvider());
    assert($preConfiguredDataPreProcessor !== $context->getDataPreProcessor());

Proposed resolution

Don't override existing assignments for ref provider or data preprocessor in configureContextDefaults().

User interface changes

None

API changes

None

Data model changes

None

πŸ› Bug report
Status

Fixed

Version

9.1

Component

Module Core

Created by

πŸ‡ΊπŸ‡ΈUnited States slucero Arkansas

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

Comments & Activities

Production build 0.71.5 2024