Skip to content

Commit

Permalink
Added getAnnotationForSource method(analyse)
Browse files Browse the repository at this point in the history
  • Loading branch information
dkulyk committed Jan 31, 2024
1 parent 85c250b commit 59694ac
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
15 changes: 14 additions & 1 deletion src/Analysis.php
Original file line number Diff line number Diff line change
Expand Up @@ -323,14 +323,27 @@ public function getAnnotationsOfType($classes, bool $strict = false): array
/**
* @param string $fqdn the source class/interface/trait
*/
public function getSchemaForSource(string $fqdn, string $class = OA\Schema::class): ?OA\AbstractAnnotation
public function getSchemaForSource(string $fqdn): ?OA\Schema
{
return $this->getAnnotationForSource($fqdn, OA\Schema::class);
}

/**
* @template T of OA\AbstractAnnotation
*
* @param string $fqdn the source class/interface/trait
* @param class-string<T> $class
* @return T|null
*/
public function getAnnotationForSource(string $fqdn, string $class): ?OA\AbstractAnnotation
{
$fqdn = '\\' . ltrim($fqdn, '\\');

foreach ([$this->classes, $this->interfaces, $this->traits, $this->enums] as $definitions) {
if (array_key_exists($fqdn, $definitions)) {
$definition = $definitions[$fqdn];
if (is_iterable($definition['context']->annotations)) {
/** @var OA\AbstractAnnotation $annotation */
foreach (array_reverse($definition['context']->annotations) as $annotation) {
if (is_a($annotation, $class) && $annotation->isRoot($class) && !$annotation->_context->is('generated')) {
return $annotation;
Expand Down
2 changes: 1 addition & 1 deletion src/Processors/AugmentRefs.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ protected function resolveFQCNRefs(Analysis $analysis): void
// check if we have a schema for this
if ($refSchema = $analysis->getSchemaForSource($annotation->ref)) {
$annotation->ref = OA\Components::ref($refSchema);
} elseif ($refSchema = $analysis->getSchemaForSource($annotation->ref, get_class($annotation))) {
} elseif ($refSchema = $analysis->getAnnotationForSource($annotation->ref, get_class($annotation))) {
$annotation->ref = OA\Components::ref($refSchema);
}
}
Expand Down

0 comments on commit 59694ac

Please sign in to comment.