ApiPlatform\Core\Swagger\Serializer\DocumentationNormalizer::getType PHP Method

getType() private method

Gets the Swagger's type corresponding to the given PHP's type.
private getType ( string $type, boolean $isCollection, string $className = null, boolean $readableLink = null ) : array
$type string
$isCollection boolean
$className string
$readableLink boolean
return array
    private function getType(string $type, bool $isCollection, string $className = null, bool $readableLink = null) : array
    {
        if ($isCollection) {
            return ['type' => 'array', 'items' => $this->getType($type, false, $className, $readableLink)];
        }
        if (Type::BUILTIN_TYPE_STRING === $type) {
            return ['type' => 'string'];
        }
        if (Type::BUILTIN_TYPE_INT === $type) {
            return ['type' => 'integer'];
        }
        if (Type::BUILTIN_TYPE_FLOAT === $type) {
            return ['type' => 'number'];
        }
        if (Type::BUILTIN_TYPE_BOOL === $type) {
            return ['type' => 'boolean'];
        }
        if (Type::BUILTIN_TYPE_OBJECT === $type) {
            if (null === $className) {
                return ['type' => 'string'];
            }
            if (is_subclass_of($className, \DateTimeInterface::class)) {
                return ['type' => 'string', 'format' => 'date-time'];
            }
            if (!$this->resourceClassResolver->isResourceClass($className)) {
                return ['type' => 'string'];
            }
            if (true === $readableLink) {
                return ['$ref' => sprintf('#/definitions/%s', $this->resourceMetadataFactory->create($className)->getShortName())];
            }
        }
        return ['type' => 'string'];
    }