private function setAttributes(ClassMetadataInfo $metadata, Metadata\AttributeInterface $entity)
    {
        foreach ($metadata->fieldMappings as $fieldKey => $mapping) {
            if (isset($mapping['id'])) {
                // Id field. Skip.
                continue;
            }
            if (isset($mapping['reference'])) {
                // Relationship. Skip.
                continue;
            }
            if (isset($mapping['inherited']) || isset($mapping['declared'])) {
                // Inherited. Skip.
                continue;
            }
            if (!isset($mapping['type'])) {
                // Unable to map. No type.
                throw new RuntimeException(sprintf('Cannot create an attribute for field "%s" because no data type was found', $fieldKey));
            }

            $entityDataType = isset($mapping['embedded']) ? 'object' : $this->getDataType($mapping['type']);
            // $this->validator->validateDataType($apiDataType);

            switch ($entityDataType) {
                // case 'object':
                //     $attribute = new Metadata\ObjectAttributeMetadata($fieldKey, 'object');
                //     // @todo This needs some work. How do we determine the child attributes of polymorphic embedded documents?
                //     if (isset($mapping['embedded']) && isset($mapping['targetDocument'])) {
                //         $childMetadata = $this->mf->getMetadataFor($mapping['targetDocument']);
                //         if (false === $this->isPolymorphicType($childMetadata)) {
                //             $this->setAttributes($childMetadata, $attribute);
                //         }
                //     }
                //     break;
                // case 'array':
                //     $attribute = new Metadata\ArrayAttributeMetadata($fieldKey, 'array', 'mixed');
                //     break;
                default:
                    $attribute = new Metadata\AttributeMetadata($fieldKey, $entityDataType);
                    break;
            }
            $entity->addAttribute($attribute);
        }
        return $entity;
    }