Class ApiVersionConfigurer
- Since:
- 7.0
- Author:
- Rossen Stoyanchev
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddSupportedVersions
(String... versions) Add to the list of supported versions to check against before raisingInvalidApiVersionException
for unknown versions.detectSupportedVersions
(boolean detect) Whether to use versions from mappings for supported version validation.protected @Nullable ApiVersionStrategy
setDefaultVersion
(@Nullable String defaultVersion) Configure a default version to assign to requests that don't specify one.setVersionParser
(@Nullable ApiVersionParser<?> versionParser) Configure a parser to parse API versions with.setVersionRequired
(boolean required) Whether requests are required to have an API version.usePathSegment
(int index) Add a resolver that extracts the API version from a path segment.useRequestHeader
(String headerName) Add a resolver that extracts the API version from a request header.useRequestParam
(String paramName) Add a resolver that extracts the API version from a request parameter.useVersionResolver
(ApiVersionResolver... resolvers) Add custom resolvers to resolve the API version.
-
Constructor Details
-
ApiVersionConfigurer
public ApiVersionConfigurer()
-
-
Method Details
-
useRequestHeader
Add a resolver that extracts the API version from a request header.- Parameters:
headerName
- the header name to check
-
useRequestParam
Add a resolver that extracts the API version from a request parameter.- Parameters:
paramName
- the parameter name to check
-
usePathSegment
Add a resolver that extracts the API version from a path segment.- Parameters:
index
- the index of the path segment to check; e.g. for URL's like "/{version}/..." use index 0, for "/api/{version}/..." index 1.
-
useVersionResolver
Add custom resolvers to resolve the API version.- Parameters:
resolvers
- the resolvers to use
-
setVersionParser
Configure a parser to parse API versions with.By default,
SemanticApiVersionParser
is used.- Parameters:
versionParser
- the parser to user
-
setVersionRequired
Whether requests are required to have an API version. When set totrue
,MissingApiVersionException
is raised, resulting in a 400 response if the request doesn't have an API version. When set to false, a request without a version is considered to accept any version.By default, this is set to
true
when API versioning is enabled by adding at least oneApiVersionResolver
). When adefaultVersion
is also set, this is automatically set tofalse
.- Parameters:
required
- whether an API version is required.
-
setDefaultVersion
Configure a default version to assign to requests that don't specify one.- Parameters:
defaultVersion
- the default version to use
-
addSupportedVersions
Add to the list of supported versions to check against before raisingInvalidApiVersionException
for unknown versions.By default, actual version values that appear in request mappings are used for validation. Therefore, use of this method is optional. However, if you prefer to use explicitly configured, supported versions only, then set
detectSupportedVersions
tofalse
.Note that the initial API version, if not explicitly declared in any request mappings, may need to be declared here instead as a supported version.
- Parameters:
versions
- supported version values to add
-
detectSupportedVersions
Whether to use versions from mappings for supported version validation.By default, this is
true
in which case mapped versions are considered supported versions. Set this tofalse
if you want to use only explicitly configuredsupported versions
.- Parameters:
detect
- whether to use detected versions for validation
-
getApiVersionStrategy
-