Problem/Motivation
JSON:API has a soft dependency on justinrainbow/json-schema
; validation is performed automatically if the dependency is enabled via a check in \Drupal\jsonapi\EventSubscriber\ResourceResponseValidator:
use JsonSchema\Validator;
...
elseif (class_exists(Validator::class)) {
$this->validator = new Validator();
}
@larowlan has previously noted that this causes severe performance issues at runtime, and the fix is to uninstall the dependency.
However, Experience Builder uses justinrainbow/json-schema
at runtime (although at the time of writing this is not explicitly declared): #3469516: Declare explicit runtime dependency on `justinrainbow/json-schema`
In turn this will cause performance issues on sites that want to use both Experience Builder and JSON:API.
Steps to reproduce
Proposed resolution
Move ResourceResponseValidator behind some kind of feature flag instead of magically enabling it when the dependency is present. This could be a development mode flag similar to the Twig debug mode, or a feature flag module.
It may even be preferable to move this out of core to a contrib module, as this doesn't feel like it is necessarily in the core use case. Tagging for product manager review. see #2. Also I (bbrala) dont think we should remove it right now.
Remaining tasks
- Discuss the best solution
- Implement.
User interface changes
n.a.
Introduced terminology
n.a.
API changes
New parameter in services.yml
Data model changes
n.a.
Release notes snippet
n.a.