protected function RestGenerator::getEntityParameters in OpenAPI 8
Get parameters for an entity type.
Parameters
\Drupal\Core\Entity\EntityTypeInterface $entity_type: The entity type.
string $method: The HTTP method.
string $bundle_name: The bundle name.
Return value
array Parameters for the entity resource.
1 call to RestGenerator::getEntityParameters()
- RestGenerator::getPaths in src/
Plugin/ openapi/ OpenApiGenerator/ RestGenerator.php - Returns the paths information.
File
- src/
Plugin/ openapi/ OpenApiGenerator/ RestGenerator.php, line 303
Class
- RestGenerator
- Defines an OpenApi Schema Generator for the Rest module.
Namespace
Drupal\openapi\Plugin\openapi\OpenApiGeneratorCode
protected function getEntityParameters(EntityTypeInterface $entity_type, $method, $bundle_name = NULL) {
$parameters = [];
if (in_array($method, [
'GET',
'DELETE',
'PATCH',
])) {
$keys = $entity_type
->getKeys();
if ($entity_type instanceof ConfigEntityTypeInterface) {
$key_type = 'string';
}
else {
if ($entity_type instanceof FieldableEntityInterface) {
$key_field = $this->fieldManager
->getFieldStorageDefinitions($entity_type
->id())[$keys['id']];
$key_type = $key_field
->getType();
}
else {
$key_type = 'string';
}
}
$parameters[] = [
'name' => $entity_type
->id(),
'in' => 'path',
'required' => TRUE,
'type' => $key_type,
'description' => $this
->t('The @id,id, of the @type.', [
'@id' => $keys['id'],
'@type' => $entity_type
->id(),
]),
];
}
if (in_array($method, [
'POST',
'PATCH',
])) {
$parameters[] = [
'name' => 'body',
'in' => 'body',
'description' => $this
->t('The @label object', [
'@label' => $entity_type
->getLabel(),
]),
'required' => TRUE,
'schema' => [
'$ref' => '#/definitions/' . $this
->getEntityDefinitionKey($entity_type
->id(), $bundle_name),
],
];
}
return $parameters;
}