@param ServerDoc $doc

@return array
194989
protected function getDefaultSchemaList(ServerDoc $doc) : array
    {
        $propertyList = [
            'code' => [
                'type' => 'integer',
            ],
        ];

        $errorList = array_merge($doc->getServerErrorList(), $doc->getGlobalErrorList());
        $errorList = array_reduce(
            array_map(
                function (MethodDoc $methodDoc) {
                    return $methodDoc->getCustomErrorList();
                },
                $doc->getMethodList()
            ),
            function (array $carry, array $subErrorList) {
                $carry = array_merge($carry, $subErrorList);

                return $carry;
            },
            $errorList
        );
        $codeList = array_unique(
            array_map(
                function (ErrorDoc $errorDoc) {
                    return $errorDoc->getCode();
                },
                $errorList
            )
        );

        if (count($codeList) > 0) {
            $propertyList['code']['enum'] = array_values($codeList);
        }

        return [
            'Default-Error' => [
                'allOf' => [
                    $this->shapeNormalizer->getErrorShapeDefinition(),
                    [
                        'type' => 'object',
                        'properties' => $propertyList,
                    ],
                ],
            ],
        ];
    }
1149509
private function getOperationHydraDoc(string $method, array $hydraDoc): array
    {
        if (!isset($hydraDoc['hydra:supportedOperation']) || !\is_array($hydraDoc['hydra:supportedOperation'])) {
            return [];
        }

        foreach ($hydraDoc['hydra:supportedOperation'] as $supportedOperation) {
            if ($supportedOperation['hydra:method'] === $method) {
                return $supportedOperation;
            }
        }

        return [];
    }
1084028
protected function appendObjectDoc(TypeDoc $doc, array $siblingsDoc, array $paramDocRequired) : array
    {
        if (!$doc instanceof ObjectDoc) {
            return [$siblingsDoc, $paramDocRequired];
        }

        if (true === $doc->isAllowExtraSibling()) {
            $siblingsDoc['additionalProperties']['description'] = "Extra property";
        }

        $self = $this;
        $siblingDocList = array_reduce(
            $doc->getSiblingList(),
            function (array $carry, TypeDoc $sibling) use ($self) {
                $carry[$sibling->getName()] = $self->normalize($sibling);

                return $carry;
            },
            []
        );
        $requiredSiblings = array_keys(// Keeps only keys
            array_filter(// Remove not required
                array_reduce(// Convert to $carray[PROPERTY_NAME] = IS_REQUIRED
                    $doc->getSiblingList(),
                    function (array $carry, TypeDoc $sibling) {
                        $carry[$sibling->getName()] = $sibling->isRequired();

                        return $carry;
                    },
                    []
                )
            )
        );

        $siblingsDoc = $this->appendIfValueHaveSiblings('properties', $siblingDocList, $siblingsDoc);
        $paramDocRequired = $this->appendIfValueHaveSiblings('required', $requiredSiblings, $paramDocRequired);

        return [$siblingsDoc, $paramDocRequired];
    }
963253
protected function data(ServerRequestInterface $request, Document $document)
    {
        $postId = array_get($request->getQueryParams(), 'post');
        $actor = $request->getAttribute('actor');
        $file = array_get($request->getUploadedFiles(), 'image');

        return $this->bus->dispatch(
            new UploadImage($postId, $file, $actor)
        );
    }
442477
protected function getMethodErrorsExternalSchemaList(ServerDoc $doc) : array
    {
        $list = [];
        foreach ($doc->getMethodList() as $method) {
            foreach ($method->getCustomErrorList() as $errorDoc) {
                $key = $this->definitionRefResolver->getErrorDefinitionId(
                    $errorDoc,
                    DefinitionRefResolver::CUSTOM_ERROR_DEFINITION_TYPE
                );
                $list[$key] = $this->errorDocNormalizer->normalize($errorDoc);
            }
        }

        return $list;
    }
724188
protected function appendCollectionDoc(TypeDoc $docObject) : array
    {
        $docArray = [];
        if ($docObject instanceof CollectionDoc) {
            $siblingDocList = $this->getSiblingDocList($docObject);
            if (count($siblingDocList)) {
                $docArray['siblings'] = $siblingDocList;
            }
            if (true === $docObject->isAllowExtraSibling()) {
                $docArray['allowExtra'] = $docObject->isAllowExtraSibling();
            }
            if (true === $docObject->isAllowMissingSibling()) {
                $docArray['allowMissing'] = $docObject->isAllowMissingSibling();
            }
        }

        return $docArray;
    }
442873
public function serializeDocument(DocumentInterface $document, bool $identifiersOnly = false): array
    {
        $result = [];

        if ($this->shouldContainData($document)) {
            $result['data'] = (!$document->shouldBeHandledAsCollection() && $document->data()->isEmpty()) ?
                null : $this->createData($document, $identifiersOnly);
        }

        if (!$document->metaInformation()->isEmpty()) {
            $result['meta'] = $document->metaInformation()->all();
        }

        if (!$document->links()->isEmpty()) {
            foreach ($document->links()->all() as $link) {
                $result['links'][$link->name()] = $this->serializeLink($link);
            }
        }

        if (!$document->included()->isEmpty()) {
            foreach ($document->included()->all() as $resource) {
                $result['included'][] = $this->serializeResource(
                    $resource,
                    false
                );
            }
        }

        if (!$document->errors()->isEmpty()) {
            foreach ($document->errors()->all() as $error) {
                $result['errors'][] = $this->serializeError($error);
            }
        }

        // informations about json api
        $result['jsonapi'] = [
            'version' => '1.0'
        ];

        return $result;
    }
1119904
public function getDocumentActualData(object $document) : array
    {
        $class      = $this->dm->getClassMetadata(get_class($document));
        $actualData = [];
        foreach ($class->reflFields as $name => $refProp) {
            $mapping = $class->fieldMappings[$name];
            // skip not saved fields
            if (isset($mapping['notSaved']) && $mapping['notSaved'] === true) {
                continue;
            }
            $value = $refProp->getValue($document);
            if ((isset($mapping['association']) && $mapping['type'] === 'many')
                && $value !== null && ! ($value instanceof PersistentCollectionInterface)) {
                // If $actualData[$name] is not a Collection then use an ArrayCollection.
                if (! $value instanceof Collection) {
                    $value = new ArrayCollection($value);
                }

                // Inject PersistentCollection
                $coll = $this->dm->getConfiguration()->getPersistentCollectionFactory()->create($this->dm, $mapping, $value);
                $coll->setOwner($document, $mapping);
                $coll->setDirty(! $value->isEmpty());
                $class->reflFields[$name]->setValue($document, $coll);
                $actualData[$name] = $coll;
            } else {
                $actualData[$name] = $value;
            }
        }
        return $actualData;
    }
1228290
public static function process(array $docs)
    {
        return self::flatmap(function ($doc) {
            return self::flatmap(function ($tag) {
                return self::flatmap(function ($type) {
                    return self::processType($type);
                }, self::processTag($tag));
            }, $doc->getTags());
        }, $docs);
    }
432685
public function normalize(TypeDoc $doc) : array
    {
        $siblingsDoc = $paramDocRequired = [];

        $siblingsDoc = $this->appendArrayDoc($doc, $siblingsDoc);
        list (
            $siblingsDoc,
            $paramDocRequired
            ) = $this->appendObjectDoc($doc, $siblingsDoc, $paramDocRequired);

        $format = ($doc instanceof StringDoc ? $doc->getFormat() : null);

        return $this->appendIfValueNotNull('description', $doc->getDescription())
            + ['type' => $this->schemaTypeNormalizer->normalize($doc)]
            + $this->appendIfValueNotNull('format', $format)
            + ['nullable' => $doc->isNullable()]
            + $paramDocRequired
            + $this->appendIfValueNotNull('default', $doc->getDefault())
            + $this->appendIfValueNotNull('example', $doc->getExample())
            + $this->appendIfValueHaveSiblings('enum', array_values($doc->getAllowedValueList()))
            + $this->getMinMaxDoc($doc)
            + $siblingsDoc
        ;
    }
607479
protected function docToArray(RpbSearchDoc $doc)
    {
        if ( ! $doc->hasFields()) {
            return [];
        }

        $values = [];

        foreach ($doc->fields as $pair) {
            $values[$pair->key][] = $pair->value;
        }

        return $values;
    }
585826
protected function getDocForObject($docBlock, array $objects = []): array
    {
        $objectName = $docBlock->getObjectName();

        if (!isset($objects[$objectName])) {
            $object = new SmdSimpleObject();
            $object->name = $objectName;
            $objects[$objectName] = $object;
        } else {
            $object = $objects[$objectName];
        }

        $object->parameters = $this->getExtendedParameters($docBlock, $object->parameters);

        return $objects;
    }
267223
protected function getSiblingDocList(CollectionDoc $docObject) : array
    {
        $docArray = [];
        foreach ($docObject->getSiblingList() as $siblingDocObject) {
            $siblingDocArray = $this->normalize($siblingDocObject);
            // Use name if :
            // - parent is object
            // - parent is array and name is an integer
            if ($docObject instanceof ObjectDoc
                || (
                    $docObject instanceof ArrayDoc
                    && is_int($siblingDocObject->getName())
                )
            ) {
                $docArray[$siblingDocObject->getName()] = $siblingDocArray;
            } else {
                $docArray[] = $siblingDocArray;
            }
        }

        return $docArray;
    }
1101460
protected function getMethodErrorsExternalSchemaList(ServerDoc $doc) : array
    {
        $list = [];
        foreach ($doc->getMethodList() as $method) {
            $list = array_merge(
                $list,
                $this->normalizeErrorList(
                    $method->getCustomErrorList(),
                    DefinitionRefResolver::CUSTOM_ERROR_DEFINITION_TYPE
                )
            );
        }

        return $list;
    }
653497
public function getContext($serverSide)
    {
        $request = $this->requestStack->getCurrentRequest();

        return [
            'serverSide' => $serverSide,
            'href' => $request->getSchemeAndHttpHost().$request->getRequestUri(),
            'location' => $request->getRequestUri(),
            'scheme' => $request->getScheme(),
            'host' => $request->getHost(),
            'port' => $request->getPort(),
            'base' => $request->getBaseUrl(),
            'pathname' => $request->getPathInfo(),
            'search' => $request->getQueryString(),
        ];
    }
743022
public function getShardKeyQuery($document)
    {
        if ( ! $this->class->isSharded()) {
            return array();
        }

        $shardKey = $this->class->getShardKey();
        $keys = array_keys($shardKey['keys']);
        $data = $this->uow->getDocumentActualData($document);

        $shardKeyQueryPart = array();
        foreach ($keys as $key) {
            $mapping = $this->class->getFieldMappingByDbFieldName($key);
            $this->guardMissingShardKey($document, $key, $data);
            $value = Type::getType($mapping['type'])->convertToDatabaseValue($data[$mapping['fieldName']]);
            $shardKeyQueryPart[$key] = $value;
        }

        return $shardKeyQueryPart;
    }
528964
protected function getMinMaxDoc(TypeDoc $doc) : array
    {
        $paramDocMinMax = [];
        if ($doc instanceof StringDoc) {
            $paramDocMinMax = $this->appendIfValueNotNull('minLength', $doc->getMinLength(), $paramDocMinMax);
            $paramDocMinMax = $this->appendIfValueNotNull('maxLength', $doc->getMaxLength(), $paramDocMinMax);
        } elseif ($doc instanceof NumberDoc) {
            $paramDocMinMax = $this->appendNumberMinMax($doc, $paramDocMinMax);
        } elseif ($doc instanceof CollectionDoc) {
            if ($doc instanceof ObjectDoc) {
                $paramDocMinMax = $this->appendIfValueNotNull('minProperties', $doc->getMinItem(), $paramDocMinMax);
                $paramDocMinMax = $this->appendIfValueNotNull('maxProperties', $doc->getMaxItem(), $paramDocMinMax);
            } else {
                $paramDocMinMax = $this->appendIfValueNotNull('minItems', $doc->getMinItem(), $paramDocMinMax);
                $paramDocMinMax = $this->appendIfValueNotNull('maxItems', $doc->getMaxItem(), $paramDocMinMax);
            }
        }

        return $paramDocMinMax;
    }