protected function JsonApiGenerator::getJsonSchema in OpenAPI for JSON:API 3.x
Same name and namespace in other branches
- 8.2 src/Plugin/openapi/OpenApiGenerator/JsonApiGenerator.php \Drupal\openapi_jsonapi\Plugin\openapi\OpenApiGenerator\JsonApiGenerator::getJsonSchema()
1 call to JsonApiGenerator::getJsonSchema()
- JsonApiGenerator::getDefinitions in src/
Plugin/ openapi/ OpenApiGenerator/ JsonApiGenerator.php
File
- src/
Plugin/ openapi/ OpenApiGenerator/ JsonApiGenerator.php, line 765
Class
- JsonApiGenerator
- Defines an OpenApi Schema Generator for the JsonApi module.
Namespace
Drupal\openapi_jsonapi\Plugin\openapi\OpenApiGeneratorCode
protected function getJsonSchema($described_format, $entity_type_id, $bundle_name = NULL) {
if ($entity_type_id !== $bundle_name) {
$schema = $this->schemaFactory
->create($entity_type_id, $bundle_name);
}
else {
$schema = $this->schemaFactory
->create($entity_type_id);
}
if ($schema) {
$json_schema = $this->serializer
->normalize($schema, "schema_json:{$described_format}");
unset($json_schema['$schema'], $json_schema['id']);
$json_schema = $this
->cleanSchema($json_schema);
if (!$bundle_name) {
// Add discriminator field.
$entity_type = $this->entityTypeManager
->getDefinition($entity_type_id);
if ($bundle_field = $entity_type
->getKey('bundle')) {
$json_schema['discriminator'] = $bundle_field;
}
}
}
else {
$json_schema = [
'type' => 'object',
'title' => $this
->t('@entity_type Schema', [
'@entity_type' => $entity_type_id,
]),
'description' => $this
->t('Describes the payload for @entity_type entities.', [
'@entity_type' => $entity_type_id,
]),
];
}
return $json_schema;
}