Skip to content

Adds new ApiVersionCustomizer #46653

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

spencergibb
Copy link
Member

This allows users to create beans to customize ApiVersionConfigurer.

This allows users to create beans to customize ApiVersionConfigurer.
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Aug 1, 2025
@wilkinsona
Copy link
Member

Thanks, @spencergibb.

I'm not fully up-to-speed on the background here, but this feels a little out of place to me when considering the WebMvcConfigurer contract and the various sub-configurers with which it's called.

Boot doesn't have customizers for:

  • AsyncSupportConfigurer
  • ContentNegotiationConfigurer
  • PathMatchConfigurer

What's different about ApiVersionConfigurer that it needs an ApiVersionConfigurerCustomizer callback? Put another way, what capabilities does an ApiVersionConfigurerCustomizer unlock that aren't already available by defining an appropriately ordered WebMvcConfigurer that implements configureApiVersioning(ApiVersionConfigurer configurer)?

@wilkinsona wilkinsona added the status: waiting-for-feedback We need additional information before we can continue label Aug 4, 2025
@spencergibb
Copy link
Member Author

Spring Cloud Gateway would like to set the supportedVersionPredicate without totally overriding the boot configurer. I guessed a customizer bean was better than a predicate bean with a qualifier.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Aug 4, 2025
@wilkinsona
Copy link
Member

wilkinsona commented Aug 4, 2025

The WebMvcConfigurers are additive so you can declare one alongside Boot's. Framework will then call each, giving them a change to configure the API version strategy. This means that you can already configure a predicate with a WebMvcConfigurer and make use of the property-based configuration at the same time:

	@Test
	void configureApiVersionStrategyWithPropertiesAndAdditionalWebMvcConfigurer() {
		Predicate<Comparable<?>> supportedVersionPredicate = (comparable) -> true;
		this.contextRunner.withPropertyValues("spring.mvc.apiversion.use.media-type-parameter[application/json]=mtpv")
			.withBean(WebMvcConfigurer.class, () -> new WebMvcConfigurer() {

				@Override
				public void configureApiVersioning(ApiVersionConfigurer configurer) {
					configurer.setSupportedVersionPredicate(supportedVersionPredicate);
				}

			})
			.run((context) -> {
				ApiVersionStrategy versionStrategy = context.getBean("mvcApiVersionStrategy", ApiVersionStrategy.class);
				assertThat(versionStrategy).extracting("supportedVersionPredicate")
					.isEqualTo(supportedVersionPredicate);
				MockHttpServletRequest request = new MockHttpServletRequest();
				request.addHeader(HttpHeaders.CONTENT_TYPE, "application/json;mtpv=123");
				assertThat(versionStrategy.resolveVersion(request)).isEqualTo("123");
			});
	}

@wilkinsona wilkinsona added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels Aug 4, 2025
@spencergibb
Copy link
Member Author

I will try again. IIRC there was a duplicate bean error, but I will double check

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Aug 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants