Skip to content

Commit 38090ad

Browse files
DerManoMannclaude
andcommitted
fix: remove consumed annotations from analysis registry
Add Analysis::removeAnnotation() and use it in all processors that consume/merge annotations. MergeJsonContent and MergeXmlContent now properly remove the original JsonContent/XmlContent from the analysis after transforming them into MediaType + Schema, preventing orphan annotations from appearing in validation. Replaces all direct $analysis->annotations->offsetUnset() calls with the new method for consistency. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent fbdb28f commit 38090ad

7 files changed

Lines changed: 11 additions & 4 deletions

File tree

src/Analysis.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ public function addAnnotation(OA\AbstractAnnotation $annotation, Context $contex
9797
}
9898
}
9999

100+
public function removeAnnotation(OA\AbstractAnnotation $annotation): void
101+
{
102+
$this->annotations->offsetUnset($annotation);
103+
}
104+
100105
/**
101106
* @param list<OA\AbstractAnnotation> $annotations
102107
*/

src/Processors/AugmentRefs.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ protected function removeDuplicateRefs(Analysis $analysis): void
8888
if (!Generator::isDefault($allOfSchema->ref)) {
8989
if (in_array($allOfSchema->ref, $refs)) {
9090
$dupes[] = $allOfSchema->ref;
91-
$analysis->annotations->offsetUnset($allOfSchema);
91+
$analysis->removeAnnotation($allOfSchema);
9292
unset($schema->allOf[$ii]);
9393
continue;
9494
}

src/Processors/AugmentTags.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ private function removeUnusedTags(array $usedTagNames, array $declaredTags, Anal
104104
foreach ($declaredTags as $tag) {
105105
if (!in_array($tag->name, $tagsToKeep)) {
106106
if (false !== $index = array_search($tag, $analysis->openapi->tags, true)) {
107-
$analysis->annotations->offsetUnset($tag);
107+
$analysis->removeAnnotation($tag);
108108
unset($analysis->openapi->tags[$index]);
109109
$analysis->openapi->tags = array_values($analysis->openapi->tags);
110110
}

src/Processors/BuildPaths.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function __invoke(Analysis $analysis): void
2626
$annotation->_context->logger->warning($annotation->identity() . ' is missing required property "path" in ' . $annotation->_context);
2727
} elseif (isset($paths[$annotation->path])) {
2828
$paths[$annotation->path]->mergeProperties($annotation);
29-
$analysis->annotations->offsetUnset($annotation);
29+
$analysis->removeAnnotation($annotation);
3030
} else {
3131
$paths[$annotation->path] = $annotation;
3232
}

src/Processors/MergeIntoOpenApi.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public function __invoke(Analysis $analysis): void
9898
}
9999
}
100100

101-
$analysis->annotations->offsetUnset($components);
101+
$analysis->removeAnnotation($components);
102102
}
103103

104104
$merge = array_filter($merge, static fn (OA\AbstractAnnotation $annotation): bool => !$annotation instanceof OA\Components);

src/Processors/MergeJsonContent.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public function __invoke(Analysis $analysis): void
5353
if ($index !== false) {
5454
array_splice($parent->_unmerged, $index, 1);
5555
}
56+
$analysis->removeAnnotation($jsonContent);
5657
}
5758
}
5859
}

src/Processors/MergeXmlContent.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public function __invoke(Analysis $analysis): void
5050
if ($index !== false) {
5151
array_splice($parent->_unmerged, $index, 1);
5252
}
53+
$analysis->removeAnnotation($xmlContent);
5354
}
5455
}
5556
}

0 commit comments

Comments
 (0)