Class DefaultApiVersionStrategy
java.lang.Object
org.springframework.web.reactive.accept.DefaultApiVersionStrategy
- All Implemented Interfaces:
ApiVersionStrategy
Default implementation of
ApiVersionStrategy
that delegates to the
configured version resolvers and version parser.- Since:
- 7.0
- Author:
- Rossen Stoyanchev
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultApiVersionStrategy
(List<ApiVersionResolver> versionResolvers, ApiVersionParser<?> versionParser, boolean versionRequired, @Nullable String defaultVersion, boolean detectSupportedVersions) Create an instance. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addMappedVersion
(String... versions) Internal method to add to the list of actual version values that appear in request mappings, which allows supported versions to be discovered rather thanconfigured
.void
addSupportedVersion
(String... versions) Add to the list of supported versions to check against inApiVersionStrategy.validateVersion(java.lang.Comparable<?>, org.springframework.web.server.ServerWebExchange)
before raisingInvalidApiVersionException
for unknown versions.Return a default version to use for requests that don't specify one.Comparable
<?> parseVersion
(String version) Parse the version of a request into an Object.resolveVersion
(ServerWebExchange exchange) Resolve the version value from a request, e.g.toString()
void
validateVersion
(@Nullable Comparable<?> requestVersion, ServerWebExchange exchange) Validate a request version, including required and supported version checks.
-
Constructor Details
-
DefaultApiVersionStrategy
public DefaultApiVersionStrategy(List<ApiVersionResolver> versionResolvers, ApiVersionParser<?> versionParser, boolean versionRequired, @Nullable String defaultVersion, boolean detectSupportedVersions) Create an instance.- Parameters:
versionResolvers
- one or more resolvers to try; the first non-null value returned by any resolver becomes the resolved usedversionParser
- parser for to raw version valuesversionRequired
- whether a version is required; if a request does not have a version, and adefaultVersion
is not specified, validation fails withMissingApiVersionException
defaultVersion
- a default version to assign to requests that don't specify onedetectSupportedVersions
- whether to use API versions that appear in mappings for supported version validation (true), or use only explicitly configured versions (false).
-
-
Method Details
-
getDefaultVersion
Description copied from interface:ApiVersionStrategy
Return a default version to use for requests that don't specify one.- Specified by:
getDefaultVersion
in interfaceApiVersionStrategy
-
addSupportedVersion
Add to the list of supported versions to check against inApiVersionStrategy.validateVersion(java.lang.Comparable<?>, org.springframework.web.server.ServerWebExchange)
before raisingInvalidApiVersionException
for unknown versions.By default, actual version values that appear in request mappings are considered supported, and use of this method is optional. However, if you prefer to use only explicitly configured, supported versions, then set
detectSupportedVersions
flag tofalse
.- Parameters:
versions
- the supported versions to add- See Also:
-
addMappedVersion
Internal method to add to the list of actual version values that appear in request mappings, which allows supported versions to be discovered rather thanconfigured
.If you prefer to use explicitly configured, supported versions only, set the
detectSupportedVersions
flag tofalse
.- Parameters:
versions
- the versions to add- See Also:
-
resolveVersion
Description copied from interface:ApiVersionStrategy
Resolve the version value from a request, e.g. from a request header.- Specified by:
resolveVersion
in interfaceApiVersionStrategy
- Parameters:
exchange
- the current exchange- Returns:
- the version, if present or
null
-
parseVersion
Description copied from interface:ApiVersionStrategy
Parse the version of a request into an Object.- Specified by:
parseVersion
in interfaceApiVersionStrategy
- Parameters:
version
- the value to parse- Returns:
- an Object that represents the version
-
validateVersion
public void validateVersion(@Nullable Comparable<?> requestVersion, ServerWebExchange exchange) throws MissingApiVersionException, InvalidApiVersionException Description copied from interface:ApiVersionStrategy
Validate a request version, including required and supported version checks.- Specified by:
validateVersion
in interfaceApiVersionStrategy
- Parameters:
requestVersion
- the version to validateexchange
- the exchange- Throws:
MissingApiVersionException
- if the version is required, but not specifiedInvalidApiVersionException
- if the version is not supported
-
toString
-