Skip to content

fix: AnnotationUtils cache misses due to reinstantiation of ModelConverterContext#5114

Open
ldt-fweichert wants to merge 5 commits intoswagger-api:masterfrom
ldt-fweichert:fix-annotation-utils-cache-misses
Open

fix: AnnotationUtils cache misses due to reinstantiation of ModelConverterContext#5114
ldt-fweichert wants to merge 5 commits intoswagger-api:masterfrom
ldt-fweichert:fix-annotation-utils-cache-misses

Conversation

@ldt-fweichert
Copy link
Copy Markdown

@ldt-fweichert ldt-fweichert commented Apr 7, 2026

Description

ModelConverterContextImpl stores each already processed type and it's corresponding Schema internally. When types are discovered multiple times during resolution, they should be converted only once. Multiple usages of static helper functions on AnnotationUtils instantiated a new ModelConverterContext instead of reusing the initial one effectivley ignoring the cache of processed types.

This PR adds a ModelConverterContext context-Parameter to some AnnotationUtils helpers to reuse the instance during resolution. This speeds up resolution, especially with Recursive Models, where resolving Models with 10 subtypes could require at least multiple hours of processing time.

Two questions from my side remain:

  • Should ModelConverterContext be instantiated inside AnnotationUtils at all? If no, the overloads created in this PR should be removed entirely, to ensure correct usage. An additional null-check should be added as well.
  • My added test of checking for big differences in timing between models with 2 subtypes and models with 10 subtypes is admittedly not that maintainable. I'd be open to alternative ideas for testing, although it served my use-case pretty well.

Fixes: #5091

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)

@ldt-fweichert ldt-fweichert force-pushed the fix-annotation-utils-cache-misses branch from 5847db2 to 0f4e682 Compare April 7, 2026 09:40
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.

[Bug]: Exponential recursive model processing

1 participant