public function JsonApiGenerator::getDefinitions in OpenAPI for JSON:API 8.2
Same name and namespace in other branches
- 3.x src/Plugin/openapi/OpenApiGenerator/JsonApiGenerator.php \Drupal\openapi_jsonapi\Plugin\openapi\OpenApiGenerator\JsonApiGenerator::getDefinitions()
File
- src/
Plugin/ openapi/ OpenApiGenerator/ JsonApiGenerator.php, line 704
Class
- JsonApiGenerator
- Defines an OpenApi Schema Generator for the JsonApi module.
Namespace
Drupal\openapi_jsonapi\Plugin\openapi\OpenApiGeneratorCode
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;
}