You are here

public function JsonApiGenerator::getDefinitions in OpenAPI 8

Get model definitions for Drupal entities and bundles.

Return value

array The model definitions.

Overrides OpenApiGeneratorBase::getDefinitions

File

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

Class

JsonApiGenerator
Defines an OpenApi Schema Generator for the JsonApi module.

Namespace

Drupal\openapi\Plugin\openapi\OpenApiGenerator

Code

public function getDefinitions() {
  static $definitions = [];
  if (!$definitions) {
    foreach ($this->entityTypeManager
      ->getDefinitions() as $entity_type) {
      if ($entity_type instanceof ContentEntityTypeInterface) {
        if ($bundle_type = $entity_type
          ->getBundleEntityType()) {
          $bundle_storage = $this->entityTypeManager
            ->getStorage($bundle_type);
          $bundles = $bundle_storage
            ->loadMultiple();
          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;
            }
          }
        }
        else {
          if ($this
            ->includeEntityTypeBundle($entity_type
            ->id())) {
            $definition_key = $this
              ->getEntityDefinitionKey($entity_type
              ->id());
            $json_schema = $this
              ->getJsonSchema('api_json', $entity_type
              ->id());
            $json_schema = $this
              ->fixReferences($json_schema, '#/definitions/' . $definition_key);
            $definitions[$definition_key] = $json_schema;
          }
        }
      }
    }
  }
  return $definitions;
}