diff --git a/src/Parser/Documentor.php b/src/Parser/Documentor.php index 919d02c..254e4ae 100644 --- a/src/Parser/Documentor.php +++ b/src/Parser/Documentor.php @@ -21,6 +21,8 @@ namespace PSX\Schema\Parser; use phpDocumentor\Reflection\TypeResolver; +use phpDocumentor\Reflection\Types\Context; +use phpDocumentor\Reflection\Types\ContextFactory; use PSX\Schema\Definitions; use PSX\Schema\Exception\ParserException; use PSX\Schema\Exception\TypeNotFoundException; @@ -41,6 +43,7 @@ */ class Documentor extends Popo { + private ContextFactory $contextFactory; private TypeResolver $typeResolver; private Popo\Resolver\Documentor $documentor; @@ -48,6 +51,7 @@ public function __construct() { parent::__construct(); + $this->contextFactory = new ContextFactory(); $this->typeResolver = new TypeResolver(); $this->documentor = new Popo\Resolver\Documentor(); } @@ -62,7 +66,12 @@ public function parse(string $schema, ?ContextInterface $context = null): Schema try { $typeName = 'InlineType' . substr(md5($schema), 0, 8); - $result = $this->documentor->buildPropertyType($this->typeResolver->resolve($schema)); + $parts = explode('@', $schema, 2); + $type = $parts[0] ?? null; + $namespace = $parts[1] ?? null; + + $typeContext = !empty($namespace) ? new Context($namespace) : null; + $result = $this->documentor->buildPropertyType($this->typeResolver->resolve($type, $typeContext)); if ($result instanceof MapPropertyType) { $schema = $result->getSchema(); diff --git a/src/SchemaSource.php b/src/SchemaSource.php index 47f3558..ac0d157 100644 --- a/src/SchemaSource.php +++ b/src/SchemaSource.php @@ -91,9 +91,9 @@ public static function fromClass(string $class): self /** * A PHP doc type i.e. array */ - public static function fromType(string $type): self + public static function fromType(string $type, ?string $namespace = null): self { - return new self('php+doc', $type); + return new self('php+doc', $type . (!empty($namespace) ? '@' . $namespace : '')); } public static function fromTypeHub(string $user, string $document, string $version): self