Calling ApiVersionConfigurer.setVersionRequired(true) in a Spring MVC application should a MissingApiVersionException to be thrown when the version is not found.

This currently doesn't appear to be the case, at least in Spring MVC.

I think the cause is this line where getDefaultVersion() is called but validateVersion is not called meaning these lines are not called.

Comment From: philwebb

This issue was noticed by @belyaev-andrey

Comment From: rstoyanchev

Setting defaultVersion implicitly turns off versionRequired. Having a default version assigned to every request in effect means there is always a version. This is mentioned in the Javadoc and is common in other places like the required flag and defaultValue on @RequestParam and other controller method parameter annotations.

In other words this is expected behavior.

Comment From: rstoyanchev

Once #35387 it should make it impossible to have both required=true and a default version set.

Comment From: philwebb

I don't think I specified the default version, I'm pretty sure default version was null and setVersionRequired was true.

When debugging, it seemed that in

https://github.com/spring-projects/spring-framework/blob/d8804c798b821cca14810e2c602f24de16c8d642/spring-web/src/main/java/org/springframework/web/accept/ApiVersionStrategy.java#L71-L75)

It called resolveVersion which returned null, then it called getDefaultVersion() which also returned null. It then returns null immediately, so it never calls the validation logic.

Comment From: rstoyanchev

Oh I see now. Yes that looks wrong.

Comment From: rstoyanchev

Looks like it was introduced in M7 with ffdf941219954ba6603d6d612d70597029221b6e.