You are here

private function JsonApiGenerator::fixReferences in OpenAPI for JSON:API 3.x

Same name and namespace in other branches
  1. 8.2 src/Plugin/openapi/OpenApiGenerator/JsonApiGenerator.php \Drupal\openapi_jsonapi\Plugin\openapi\OpenApiGenerator\JsonApiGenerator::fixReferences()

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

Parameters

array $schema: The schema to fix.

string $prefix: The prefix where this schema is embedded.

Return value

array The modified schema.

1 call to JsonApiGenerator::fixReferences()
JsonApiGenerator::getDefinitions in src/Plugin/openapi/OpenApiGenerator/JsonApiGenerator.php

File

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

Class

JsonApiGenerator
Defines an OpenApi Schema Generator for the JsonApi module.

Namespace

Drupal\openapi_jsonapi\Plugin\openapi\OpenApiGenerator

Code

private function fixReferences(array $schema, string $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;
}