Interface ApiVersionStrategy
- All Known Implementing Classes:
DefaultApiVersionStrategy
public interface ApiVersionStrategy
The main component that encapsulates configuration preferences and strategies
to manage API versioning for an application.
- Since:
- 7.0
- Author:
- Rossen Stoyanchev, Jonathan Kaplan
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionReturn a default version to use for requests that don't specify one.voidhandleDeprecations(Comparable<?> version, Object handler, ServerWebExchange exchange) Check if the requested API version is deprecated, and if so handle it accordingly, e.g.Comparable<?> parseVersion(String version) Parse the version of a request into an Object.resolveApiVersion(ServerWebExchange exchange) Resolve the version value from a request.default Mono<Comparable<?>> Convenience method to resolve, parse, and validate the request version, or return the default version if configured.default @Nullable Comparable<?> Deprecated, for removal: This API element is subject to removal in a future version.resolveVersion(ServerWebExchange exchange) Deprecated, for removal: This API element is subject to removal in a future version.as of 7.0.3, in favor ofresolveApiVersion(ServerWebExchange)voidvalidateVersion(@Nullable Comparable<?> requestVersion, ServerWebExchange exchange) Validate a request version, including required and supported version checks.
-
Method Details
-
resolveApiVersion
Resolve the version value from a request.- Parameters:
exchange- the current exchange- Returns:
- a
Monoemitting the raw version as aString, or an emptyMonoif no version is found - Since:
- 7.0.3
- See Also:
-
resolveVersion
@Deprecated(since="7.0.3", forRemoval=true) @Nullable String resolveVersion(ServerWebExchange exchange) Deprecated, for removal: This API element is subject to removal in a future version.as of 7.0.3, in favor ofresolveApiVersion(ServerWebExchange)Resolve the version value from a request, e.g. from a request header.- Parameters:
exchange- the current exchange- Returns:
- the version, if present or
null - See Also:
-
parseVersion
Parse the version of a request into an Object.- Parameters:
version- the value to parse- Returns:
- an Object that represents the version
- See Also:
-
validateVersion
void validateVersion(@Nullable Comparable<?> requestVersion, ServerWebExchange exchange) throws MissingApiVersionException, InvalidApiVersionException Validate a request version, including required and supported version checks.- Parameters:
requestVersion- the version to validateexchange- the exchange- Throws:
MissingApiVersionException- if the version is required, but not specifiedInvalidApiVersionException- if the version is not supported
-
getDefaultVersion
@Nullable Comparable<?> getDefaultVersion()Return a default version to use for requests that don't specify one. -
resolveParseAndValidateApiVersion
Convenience method to resolve, parse, and validate the request version, or return the default version if configured.- Parameters:
exchange- the current exchange- Returns:
- a
Monoemitting the request version, a validation error, or an emptyMonoif there is no version - Since:
- 7.0.3
-
resolveParseAndValidateVersion
@Deprecated(since="7.0.3", forRemoval=true) default @Nullable Comparable<?> resolveParseAndValidateVersion(ServerWebExchange exchange) Deprecated, for removal: This API element is subject to removal in a future version.Convenience method to return the parsed and validated request version, or the default version if configured.- Parameters:
exchange- the current exchange- Returns:
- the parsed request version, or the default version
-
handleDeprecations
Check if the requested API version is deprecated, and if so handle it accordingly, e.g. by setting response headers to signal the deprecation, to specify relevant dates and provide links to further details.- Parameters:
version- the resolved and parsed request versionhandler- the handler chosen for the exchangeexchange- the current exchange- See Also:
-
resolveParseAndValidateApiVersion(ServerWebExchange)