/**
  * Parses an attribute.
  *
  * @param ResourceInterface          $resource
  * @param AttributeMetadataInterface $attributeMetadata
  * @param string                     $io
  * @param Type|null                  $type
  *
  * @return array
  */
 private function parseAttribute(ResourceInterface $resource, AttributeMetadataInterface $attributeMetadata, $io, Type $type = null)
 {
     $data = array('dataType' => null, 'required' => $attributeMetadata->isRequired(), 'description' => $attributeMetadata->getDescription(), 'readonly' => !$attributeMetadata->isWritable());
     if (null == $type) {
         if (!isset($attributeMetadata->getTypes()[0])) {
             // Default to string
             $data['dataType'] = DataTypes::STRING;
             return $data;
         }
         // Use the first type found as primary
         $type = $attributeMetadata->getTypes()[0];
     }
     if ($type->isCollection()) {
         $data['actualType'] = DataTypes::COLLECTION;
         if ($collectionType = $type->getCollectionType()) {
             $subAttribute = $this->parseAttribute($resource, $attributeMetadata, $io, $collectionType);
             if (self::IRI === $subAttribute['dataType']) {
                 $data['dataType'] = 'array of IRIs';
                 $data['subType'] = DataTypes::STRING;
                 return $data;
             }
             $data['subType'] = $subAttribute['subType'];
             $data['children'] = $subAttribute['children'];
         }
         return $data;
     }
     $phpType = $type->getType();
     if ('object' === $phpType) {
         $class = $type->getClass();
         if ('DateTime' === $class) {
             $data['dataType'] = DataTypes::DATETIME;
             $data['format'] = sprintf('{DateTime %s}', \DateTime::ATOM);
             return $data;
         }
         if (self::OUT_PREFIX === $io && $attributeMetadata->isNormalizationLink() || self::IN_PREFIX === $io && $attributeMetadata->isDenormalizationLink()) {
             $data['dataType'] = self::IRI;
             $data['actualType'] = DataTypes::STRING;
             return $data;
         }
         $data['actualType'] = DataTypes::MODEL;
         $data['subType'] = $class;
         $data['children'] = $resource->getEntityClass() === $class ? [] : $this->parseClass($resource, $class, $io);
         return $data;
     }
     $data['dataType'] = isset(self::$typeMap[$type->getType()]) ? self::$typeMap[$type->getType()] : DataTypes::STRING;
     return $data;
 }