You are here

public function JsonApiGenerator::getDefinitions 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::getDefinitions()

File

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

Class

JsonApiGenerator
Defines an OpenApi Schema Generator for the JsonApi module.

Namespace

Drupal\openapi_jsonapi\Plugin\openapi\OpenApiGenerator

Code

public function getDefinitions() {
  static $definitions = [];
  if (!$definitions) {
    foreach ($this->entityTypeManager
      ->getDefinitions() as $entity_type) {
      if ($entity_type instanceof ContentEntityTypeInterface) {
        $bundles = $this->entityTypeBundleInfo
          ->getBundleInfo($entity_type
          ->id());
        foreach ($bundles as $bundle_name => $bundle) {
          if ($this
            ->includeEntityTypeBundle($entity_type
            ->id(), $bundle_name)) {
            $definition_key = $this
              ->getEntityDefinitionKey($entity_type
              ->id(), $bundle_name);
            $json_schema = $this
              ->getJsonSchema('api_json', $entity_type
              ->id(), $bundle_name);
            $json_schema = $this
              ->fixReferences($json_schema, '#/definitions/' . $definition_key);
            $definitions[$definition_key] = $json_schema;
          }
        }
      }
    }
  }
  return $definitions;
}