You are here

private function JsonApiGenerator::fixReferences in OpenAPI 8

When embedding JSON Schemas you need to make sure to fix any possible $ref

Parameters

array $schema: The schema to fix.

$prefix: The prefix where this schema is embedded.

Return value

array

1 call to JsonApiGenerator::fixReferences()
JsonApiGenerator::getDefinitions in src/Plugin/openapi/OpenApiGenerator/JsonApiGenerator.php
Get model definitions for Drupal entities and bundles.

File

src/Plugin/openapi/OpenApiGenerator/JsonApiGenerator.php, line 737

Class

JsonApiGenerator
Defines an OpenApi Schema Generator for the JsonApi module.

Namespace

Drupal\openapi\Plugin\openapi\OpenApiGenerator

Code

private function fixReferences(array $schema, $prefix) {
  foreach ($schema as $name => $item) {
    if (is_array($item)) {
      $schema[$name] = $this
        ->fixReferences($item, $prefix);
    }
    if ($name === '$ref' && is_string($item) && strpos($item, '#/') !== FALSE) {
      $schema[$name] = preg_replace('/#\\//', $prefix . '/', $item);
    }
  }
  return $schema;
}