SpringDocWebMvcConfiguration relies on unspecified autoconfiguration ordering. Fixes #3313 - #3316
Open
kdelay wants to merge 1 commit into
Open
SpringDocWebMvcConfiguration relies on unspecified autoconfiguration ordering. Fixes #3313#3316kdelay wants to merge 1 commit into
kdelay wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3313
Problem
SpringDocWebMvcConfigurationis gated on@ConditionalOnBean(SpringDocConfiguration.class)but never declares that it has to be evaluated afterSpringDocConfiguration. The condition matches today only becauseorg.springdoc.core.configuration.SpringDocConfigurationhappens to sort beforeorg.springdoc.webmvc.core.configuration.SpringDocWebMvcConfigurationin Spring Boot's auto-configuration sort.Any ordinary third-party auto-configuration whose class name sorts earlier and which orders itself around a springdoc auto-configuration changes the topological sort.
SpringDocWebMvcConfigurationis then evaluated beforeSpringDocConfigurationis registered, the@ConditionalOnBeandoes not match, andOpenApiWebMvcResourcedisappears with no error.The same undeclared assumption exists in every other auto-configuration entry that is gated on
SpringDocConfiguration, so this is not specific to Web MVC. The-mcpstarters already declare it (@AutoConfiguration(after = SpringDocConfiguration.class)); the older@Configuration-based ones do not.Change
Added
@AutoConfigureAfter(SpringDocConfiguration.class)to the 22 auto-configuration entries that carry@ConditionalOnBean(SpringDocConfiguration.class), across the common, webmvc/webflux api, ui and scalar starters. No behaviour other than registration order is touched.Added
SpringDocAutoConfigurationOrderTest, which reads everyAutoConfiguration.importsentry on the classpath with ASM (no class loading, since several entries reference optional types) and asserts that anything gated onSpringDocConfigurationalso declares the order. On the unmodified tree it reports every affected class; it is what surfacedSpringDocKotlinConfiguration, which is easy to miss because it is a.ktfile.Verification
Reproduced with the reporter's project from #3313 (Spring Boot 4.1.0 + Jetty, the two springdoc starters, and one third-party
@AutoConfiguration(after = SpringDocWebMvcConfiguration.class)contributing no beans), on JDK 17 / macOS:OpenApiMissingWithThirdPartyAutoConfigTestfails,OpenApiWebMvcResourceis absent. The baseline test that excludes the third-party auto-configuration passes.Tests run: 2, Failures: 0.mvn installon the full reactor passes on this branch, with two exceptions that also fail on unmodifiedmainhere (checked outmainand re-ran both):test.org.springdoc.api.v31.app193.SpringDocApp193Testin the webmvc-api module (components.schemas.Animal Expected: type but none found) andtest.org.springdoc.api.v31.app3.SpringDocApp3Testin the kotlin-webmvc-tests module (components.schemas.Foo.properties.bar Unexpected: uniqueItems). Every other module is green, 647 tests in webmvc-api included.Note for reviewers: this cannot be reproduced through
ApplicationContextRunnerwithAutoConfigurations.of(...). I tried that first and the test passed with and without the fix, because the ordering constraint only takes effect through the realAutoConfiguration.importsmechanism. That is why the added test asserts the declared order instead of booting a context.