Prepare to support API versioning for fn

Add default method to resolve, parse, and validate version
Simplify tests
This commit is contained in:
rstoyanchev
2025-06-27 16:22:44 +01:00
parent d045f44693
commit 224f1af08e
7 changed files with 65 additions and 56 deletions
@@ -62,6 +62,27 @@ public interface ApiVersionStrategy {
*/
@Nullable Comparable<?> getDefaultVersion();
/**
* Convenience method to return the parsed and validated request version,
* or the default version if configured.
* @param request the current request
* @return the parsed request version, or the default version
*/
default @Nullable Comparable<?> resolveParseAndValidateVersion(HttpServletRequest request) {
String value = resolveVersion(request);
if (value == null) {
return getDefaultVersion();
}
try {
Comparable<?> version = parseVersion(value);
validateVersion(version, request);
return version;
}
catch (Exception ex) {
throw new InvalidApiVersionException(value, null, ex);
}
}
/**
* Check if the requested API version is deprecated, and if so handle it
* accordingly, e.g. by setting response headers to signal the deprecation,