Skip to content

fix(model-resolver): retain identical recursive properties#5232

Open
bender316 wants to merge 1 commit into
swagger-api:masterfrom
bender316:bug/fix-recursive-properties-omission
Open

fix(model-resolver): retain identical recursive properties#5232
bender316 wants to merge 1 commit into
swagger-api:masterfrom
bender316:bug/fix-recursive-properties-omission

Conversation

@bender316

@bender316 bender316 commented Jul 14, 2026

Copy link
Copy Markdown

Pull Request

Description

This PR fixes a bug where recursive properties are silently dropped from the generated OpenAPI schema if they happen to share the exact same name and annotations as a property in their wrapper class.

Root cause:
The cycle detection cache (processedTypes) in ModelConverterContextImpl uses AnnotatedType to prevent infinite recursion. Previously, AnnotatedType.equals() did not check the parent class for schema properties. As a result, when it encountered a child property with the exact same signature as a previously processed wrapper property, it mistakenly treated it as a self-referential cycle and dropped it.

Fix:
Updated AnnotatedType.equals() and hashCode() to conditionally include the parent class name when schemaProperty == true. This correctly differentiates identically-annotated properties across different classes while preserving the cycle guard for truly self-referential loops.

Fixes: #5231
Fixes: #5226

Type of Change

  • 🐛 Bug fix
  • ✨ New feature
  • ♻️ Refactor (non-breaking change)
  • 🧪 Tests
  • 📝 Documentation
  • 🧹 Chore (build or tooling)

Checklist

  • I have added/updated tests as needed
  • I have added/updated documentation where applicable
  • The PR title is descriptive
  • The code builds and passes tests locally
  • I have linked related issues (if any)

Screenshots / Additional Context

  • Includes RecursivePropertyMissingTest.java to prevent future regressions.
  • Fixed a legacy test expectation (ArrayOfSubclassTest_expected30.json) that was previously masking this bug by falsely asserting that the property should be omitted.

Swagger's ModelConverterContextImpl uses AnnotatedType to track types currently being processed to prevent infinite loops. However, AnnotatedType equality previously ignored the parent schema. This caused properties with identical signatures (same type, name, annotations) but belonging to different parent classes to be incorrectly treated as a recursion cycle, returning a null schema and dropping the property entirely.

This commit updates AnnotatedType's equals() and hashCode() to include the parent schema's name when checking equality for schema properties. This guarantees identical properties in different classes are tracked independently, while still properly catching true self-referential cycles.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant