Skip to content

Fix customizer ordering - #3330

Merged
bnasslahsen merged 3 commits into
springdoc:mainfrom
king-407:issue-3320-ordered-customizers
Sep 6, 2026
Merged

Fix customizer ordering#3330
bnasslahsen merged 3 commits into
springdoc:mainfrom
king-407:issue-3320-ordered-customizers

Conversation

@king-407

Copy link
Copy Markdown
Contributor

Summary

Fixes #3320.

This updates Springdoc customizer execution so customizers are applied according to Spring ordering semantics such as @Order.

Previously, several customizer collections were stored as Sets and iterated directly, so the execution order could depend on set iteration order instead of Spring's ordering rules.

Changes

  • Apply OpenApiCustomizer instances in Spring order.
  • Apply OperationCustomizer instances in Spring order.
  • Apply RouterOperationCustomizer instances in Spring order.
  • Apply DataRestRouterOperationCustomizer instances in Spring order.
  • Apply OpenApiLocaleCustomizer beans using Spring's ordered bean stream.
  • Add a focused regression test for ordered customizer execution.

Testing

mvn -q -pl springdoc-openapi-starter-common -Dtest=SpringDocCustomizersTest test
git diff --check

Signed-off-by: king-407 <95581750+king-407@users.noreply.github.com>
Fixes springdoc#3320

Signed-off-by: king-407 <95581750+king-407@users.noreply.github.com>
Signed-off-by: king-407 <95581750+king-407@users.noreply.github.com>
@zhujianxintian

Copy link
Copy Markdown

@king-407 Thank you for your help! Much appreciated 🙏

However, there is one thing I don't quite understand: why was the existing custom item collection API retained? I noticed that most of the places where it was used have also been modified, and it seems that using ObjectProvider wouldn't make much of a difference.

(I prefer using ObjectProvider because when reading the source code, if the type is ObjectProvider, it indicates that @Order is likely supported—this is more intuitive than List or Set. With List or Set, you only know @Order works if you check the call site, or if you don't read the source code and just use @Order directly.)

I'm curious—is this due to compatibility concerns, or is there another reason?

@king-407

Copy link
Copy Markdown
Contributor Author

@zhujianxintian Thanks for taking a look.

Yes, the main reason was to keep the change narrow and avoid changing the existing SpringDocCustomizers construction API in this PR.

SpringDocCustomizers is also created from GroupedOpenApi customizer collections, not only from Spring bean injection, so I kept the existing collection-based API and centralized the ordering at the point where the customizers are consumed.

That said, I agree that ObjectProvider communicates Spring ordering support more clearly when reading the code. If the maintainers prefer that direction, I’m happy to refactor the bean-injected customizers to use ObjectProvider while keeping the grouped/custom collection path working as well.

@zhujianxintian

Copy link
Copy Markdown

Thank you for your reply, I understand the reason for doing this now.

Both ObjectProvider and your approach can satisfy Spring's ordering support; the former is more concise but more aggressive, while the latter is more stable and compatible.

I raised this question only because I wanted to improve readability further, but perhaps the latter is indeed more prudent at the moment. Both ways are good.

Thank you for your contribution.

@bnasslahsen
bnasslahsen merged commit 5f171f1 into springdoc:main Sep 6, 2026
bnasslahsen added a commit that referenced this pull request Sep 6, 2026
PR #3330 reads the OpenApiLocaleCustomizer beans through getBeanProvider, which
a mocked ApplicationContext answers with null, unlike the getBeansOfType call it
replaced. Stub the provider with an empty ordered stream.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
bnasslahsen pushed a commit that referenced this pull request Sep 6, 2026
Customizer collections were iterated in set order, so @order and Ordered were
ignored. They are now sorted with AnnotationAwareOrderComparator at the point
where they are consumed, which leaves the existing collection-based
construction API (also used by GroupedOpenApi) untouched.

Backport of PR #3330, fixes #3320.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.

Please make the customizers support @Order.

3 participants