/**
  * Builds the JSON-LD context for the given resource.
  *
  * @param ResourceInterface|null $resource
  *
  * @return array
  */
 public function getContext(ResourceInterface $resource = null)
 {
     $context = parent::getContext($resource);
     if ($resource) {
         $normalizedOutput = $this->documentationHelper->normalizeClassParameter($resource->getEntityClass(), $resource);
         $data = $this->documentationHelper->getParametersParser($normalizedOutput, $resource);
         $embeds = $this->documentationHelper->transformerHelper->getAvailableIncludes($resource->getShortName());
         $context['@embed'] = implode(',', $embeds);
         foreach ($data as $key => $value) {
             $context[$key] = '#' . $resource->getShortName() . '/' . $key;
         }
     }
     return $context;
 }
 /**
  * Gets and populates if applicable a Hydra operation.
  *
  * @param ResourceInterface  $resource
  * @param OperationInterface $operation
  * @param string             $prefixedShortName
  * @param bool               $collection
  *
  * @return array
  */
 protected function getHydraOperation(ResourceInterface $resource, OperationInterface $operation, $prefixedShortName, $collection)
 {
     $method = $operation->getRoute()->getMethods();
     if (is_array($method)) {
         // If all methods are allowed, default to GET
         $method = isset($method[0]) ? $method[0] : 'GET';
     }
     $methodDoc = $this->documentationHelper->getReflectionMethod($operation->getRoute()->getDefault('_controller'));
     $annotation = $methodDoc !== null ? $this->documentationHelper->getMethodAnnotation($methodDoc) : null;
     $hydraOperation = $operation->getContext();
     $hydraOperation['hydra:entrypoint'] = $operation->getRoute()->getPath();
     switch ($method) {
         case 'GET':
             if ($collection) {
                 if (!isset($hydraOperation['hydra:title'])) {
                     $hydraOperation['hydra:title'] = sprintf('Retrieves the collection of %s resources.', $resource->getShortName());
                 }
                 if (!isset($hydraOperation['returns'])) {
                     $hydraOperation['returns'] = 'hydra:PagedCollection';
                 }
                 foreach ($resource->getFilters() as $filter) {
                     foreach ($filter->getDescription($resource) as $key => $value) {
                         $hydraOperation["hydra:search"][$key] = ['requirement' => '[a-zA-Z0-9-]+', 'description' => $key . ' filter', 'default' => ''];
                     }
                 }
             } else {
                 if (!isset($hydraOperation['hydra:title'])) {
                     $hydraOperation['hydra:title'] = null !== $annotation && null !== $annotation->getDescription() ? $annotation->getDescription() : sprintf('Retrieves %s resource.', $resource->getShortName());
                 }
                 if (null !== $annotation) {
                     $hydraOperation['returns'] = $annotation->getOutput();
                 }
             }
             break;
         case 'POST':
             if (!isset($hydraOperation['@type'])) {
                 $hydraOperation['@type'] = 'hydra:CreateResourceOperation';
             }
             if (!isset($hydraOperation['hydra:title'])) {
                 $hydraOperation['hydra:title'] = sprintf('Creates a %s resource.', $resource->getShortName());
             }
             break;
         case 'PUT':
             if (!isset($hydraOperation['@type'])) {
                 $hydraOperation['@type'] = 'hydra:ReplaceResourceOperation';
             }
             if (!isset($hydraOperation['hydra:title'])) {
                 $hydraOperation['hydra:title'] = sprintf('Replaces the %s resource.', $resource->getShortName());
             }
             break;
         case 'DELETE':
             if (!isset($hydraOperation['hydra:title'])) {
                 $hydraOperation['hydra:title'] = sprintf('Deletes the %s resource.', $resource->getShortName());
             }
             if (!isset($hydraOperation['returns'])) {
                 $hydraOperation['returns'] = 'owl:Nothing';
             }
             break;
     }
     if (!isset($hydraOperation['returns']) && ('GET' === $method && !$collection || 'POST' === $method || 'PUT' === $method)) {
         $hydraOperation['returns'] = $prefixedShortName;
     }
     if (!isset($hydraOperation['expects']) && ('POST' === $method || 'PUT' === $method)) {
         $hydraOperation['expects'] = $prefixedShortName;
     }
     if (!isset($hydraOperation['@type'])) {
         $hydraOperation['@type'] = 'hydra:Operation';
     }
     if (!isset($hydraOperation['hydra:method'])) {
         $hydraOperation['hydra:method'] = $method;
     }
     if (!isset($hydraOperation['rdfs:label']) && isset($hydraOperation['hydra:title'])) {
         $hydraOperation['rdfs:label'] = $hydraOperation['hydra:title'];
     }
     ksort($hydraOperation);
     return $hydraOperation;
 }