mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-17 16:39:29 +00:00
Check resolver set when API version config customized
Closes gh-35256
This commit is contained in:
+11
-3
@@ -26,6 +26,7 @@ import java.util.Set;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.web.accept.ApiVersionParser;
|
||||
import org.springframework.web.accept.InvalidApiVersionException;
|
||||
import org.springframework.web.accept.SemanticApiVersionParser;
|
||||
@@ -49,7 +50,7 @@ public class ApiVersionConfigurer {
|
||||
|
||||
private @Nullable ApiVersionParser<?> versionParser;
|
||||
|
||||
private boolean versionRequired = true;
|
||||
private @Nullable Boolean versionRequired;
|
||||
|
||||
private @Nullable String defaultVersion;
|
||||
|
||||
@@ -188,18 +189,25 @@ public class ApiVersionConfigurer {
|
||||
}
|
||||
|
||||
protected @Nullable ApiVersionStrategy getApiVersionStrategy() {
|
||||
|
||||
if (this.versionResolvers.isEmpty()) {
|
||||
Assert.state(isNotCustomized(), "API version config customized, but no ApiVersionResolver provided");
|
||||
return null;
|
||||
}
|
||||
|
||||
DefaultApiVersionStrategy strategy = new DefaultApiVersionStrategy(this.versionResolvers,
|
||||
(this.versionParser != null ? this.versionParser : new SemanticApiVersionParser()),
|
||||
this.versionRequired, this.defaultVersion, this.detectSupportedVersions,
|
||||
this.deprecationHandler);
|
||||
(this.versionRequired != null ? this.versionRequired : true),
|
||||
this.defaultVersion, this.detectSupportedVersions, this.deprecationHandler);
|
||||
|
||||
this.supportedVersions.forEach(strategy::addSupportedVersion);
|
||||
|
||||
return strategy;
|
||||
}
|
||||
|
||||
private boolean isNotCustomized() {
|
||||
return (this.versionParser == null && this.versionRequired == null &&
|
||||
this.defaultVersion == null && this.supportedVersions.isEmpty());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+11
-2
@@ -26,6 +26,7 @@ import java.util.Set;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.web.accept.ApiVersionDeprecationHandler;
|
||||
import org.springframework.web.accept.ApiVersionParser;
|
||||
import org.springframework.web.accept.ApiVersionResolver;
|
||||
@@ -49,7 +50,7 @@ public class ApiVersionConfigurer {
|
||||
|
||||
private @Nullable ApiVersionParser<?> versionParser;
|
||||
|
||||
private boolean versionRequired = true;
|
||||
private @Nullable Boolean versionRequired;
|
||||
|
||||
private @Nullable String defaultVersion;
|
||||
|
||||
@@ -188,13 +189,16 @@ public class ApiVersionConfigurer {
|
||||
}
|
||||
|
||||
protected @Nullable ApiVersionStrategy getApiVersionStrategy() {
|
||||
|
||||
if (this.versionResolvers.isEmpty()) {
|
||||
Assert.state(isNotCustomized(), "API version config customized, but no ApiVersionResolver provided");
|
||||
return null;
|
||||
}
|
||||
|
||||
DefaultApiVersionStrategy strategy = new DefaultApiVersionStrategy(this.versionResolvers,
|
||||
(this.versionParser != null ? this.versionParser : new SemanticApiVersionParser()),
|
||||
this.versionRequired, this.defaultVersion, this.detectSupportedVersions,
|
||||
(this.versionRequired != null ? this.versionRequired : true),
|
||||
this.defaultVersion, this.detectSupportedVersions,
|
||||
this.deprecationHandler);
|
||||
|
||||
this.supportedVersions.forEach(strategy::addSupportedVersion);
|
||||
@@ -202,4 +206,9 @@ public class ApiVersionConfigurer {
|
||||
return strategy;
|
||||
}
|
||||
|
||||
private boolean isNotCustomized() {
|
||||
return (this.versionParser == null && this.versionRequired == null &&
|
||||
this.defaultVersion == null && this.supportedVersions.isEmpty());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user