Skip to content

fix: remove consumed annotations from analysis registry#2024

Merged
DerManoMann merged 3 commits into
zircote:masterfrom
DerManoMann:fix/remove-merged-annotations-from-analysis
Jun 14, 2026
Merged

fix: remove consumed annotations from analysis registry#2024
DerManoMann merged 3 commits into
zircote:masterfrom
DerManoMann:fix/remove-merged-annotations-from-analysis

Conversation

@DerManoMann

@DerManoMann DerManoMann commented Jun 13, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Adds Analysis::removeAnnotation() as a proper API for removing annotations from the analysis registry — removes from both SplObjectStorage and $context->annotations array (full inverse of addAnnotation)
  • MergeJsonContent and MergeXmlContent now fully clean up after consuming annotations:
    • Remove from analysis registry
    • Update _context to reflect the new parent (MediaType), so tree-walking validation sees the annotation in the correct location
  • Replaces all direct $analysis->annotations->offsetUnset() calls across processors (AugmentRefs, AugmentTags, BuildPaths, MergeIntoOpenApi) with the new method for consistency
  • Adds ADR-001 documenting context keys and the annotation lifecycle contract for processors

Background

After converting JsonContent into MediaType + schema, the processor removed it from $parent->_unmerged but:

  1. Left it in the analysis's SplObjectStorage and $context->annotations
  2. Left _context->nested pointing at the old parent

When validation walks the tree via collectAnnotations(), it finds the JsonContent (reused as MediaType->schema) and validates it. With the stale context, this could produce spurious "Unexpected @OA\JsonContent()" warnings — particularly for annotations created dynamically by processors.

Test plan

  • Full test suite passes (1037 tests, 12,937,597 assertions)
  • Verify no orphan JsonContent/XmlContent warnings with dynamically-created annotations (openapi-extras integration)

🤖 Generated with Claude Code

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>
@DerManoMann DerManoMann force-pushed the fix/remove-merged-annotations-from-analysis branch from 38090ad to 6892b72 Compare June 13, 2026 06:40
DerManoMann and others added 2 commits June 13, 2026 19:04
…Type

After merge, the consumed annotation is reused as MediaType->schema but
its _context->nested still pointed at the old parent. Validation walks
the tree via collectAnnotations() and would find the annotation in an
unexpected location. Update _context to reflect the new parent.

Also adds ADR-001 documenting context keys and the annotation lifecycle
contract for processors.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@DerManoMann DerManoMann merged commit 060af3b into zircote:master Jun 14, 2026
17 checks passed
@DerManoMann DerManoMann deleted the fix/remove-merged-annotations-from-analysis branch June 14, 2026 06:52
@github-actions

Copy link
Copy Markdown
Contributor

Created backport PR for 5.x:

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin backport-2024-to-5.x
git worktree add --checkout .worktree/backport-2024-to-5.x backport-2024-to-5.x
cd .worktree/backport-2024-to-5.x
git reset --hard HEAD^
git cherry-pick -x 060af3bb9c4cba6a5859aba2c51cd1c129479410

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant