You are here

protected function OpenApiGeneratorBase::getEntityResponses in OpenAPI 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/openapi/OpenApiGeneratorBase.php \Drupal\openapi\Plugin\openapi\OpenApiGeneratorBase::getEntityResponses()

Get possible responses for an entity type.

Parameters

string $entity_type_id: The entity type.

string $method: The method.

string $bundle_name: The bundle name.

Return value

array The entity responses.

2 calls to OpenApiGeneratorBase::getEntityResponses()
JsonApiGenerator::getEntityResponsesJsonApi in src/Plugin/openapi/OpenApiGenerator/JsonApiGenerator.php
RestGenerator::getPaths in src/Plugin/openapi/OpenApiGenerator/RestGenerator.php
Returns the paths information.

File

src/Plugin/openapi/OpenApiGeneratorBase.php, line 467

Class

OpenApiGeneratorBase
Defines base class for OpenApi Generator plugins.

Namespace

Drupal\openapi\Plugin\openapi

Code

protected function getEntityResponses($entity_type_id, $method, $bundle_name = NULL) {
  $method = strtolower($method);
  $responses = [];
  $schema_response = [];
  if ($definition_ref = $this
    ->getDefinitionReference($entity_type_id, $bundle_name)) {
    $schema_response = [
      'schema' => [
        '$ref' => $definition_ref,
      ],
    ];
  }
  switch ($method) {
    case 'get':
      $responses['200'] = [
        'description' => 'successful operation',
      ] + $schema_response;
      break;
    case 'post':
      unset($responses['200']);
      $responses['201'] = [
        'description' => 'Entity created',
      ] + $schema_response;
      break;
    case 'delete':
      unset($responses['200']);
      $responses['201'] = [
        'description' => 'Entity deleted',
      ];
      break;
  }
  return $responses;
}