Package org.springframework.web.accept
Class DefaultApiVersionStrategy
java.lang.Object
org.springframework.web.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 SummaryConstructorsConstructorDescriptionDefaultApiVersionStrategy(List<ApiVersionResolver> versionResolvers, ApiVersionParser<?> versionParser, boolean versionRequired, @Nullable String defaultVersion) Create an instance.
- 
Method SummaryModifier and TypeMethodDescriptionvoidaddSupportedVersion(String... versions) Add to the list of known, supported versions to check against inApiVersionStrategy.validateVersion(java.lang.Comparable<?>, jakarta.servlet.http.HttpServletRequest).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(HttpServletRequest request) Resolve the version value from a request, e.g.toString()voidvalidateVersion(@Nullable Comparable<?> requestVersion, HttpServletRequest request) Validate a request version, including required and supported version checks.
- 
Constructor Details- 
DefaultApiVersionStrategypublic DefaultApiVersionStrategy(List<ApiVersionResolver> versionResolvers, ApiVersionParser<?> versionParser, boolean versionRequired, @Nullable String defaultVersion) Create an instance.- Parameters:
- versionResolvers- one or more resolvers to try; the first non-null value returned by any resolver becomes the resolved used
- versionParser- parser for to raw version values
- versionRequired- whether a version is required; if a request does not have a version, and a- defaultVersionis not specified, validation fails with- MissingApiVersionException
- defaultVersion- a default version to assign to requests that don't specify one
 
 
- 
- 
Method Details- 
getDefaultVersionDescription copied from interface:ApiVersionStrategyReturn a default version to use for requests that don't specify one.- Specified by:
- getDefaultVersionin interface- ApiVersionStrategy
 
- 
addSupportedVersionAdd to the list of known, supported versions to check against inApiVersionStrategy.validateVersion(java.lang.Comparable<?>, jakarta.servlet.http.HttpServletRequest). Request versions that are not in the supported result inInvalidApiVersionExceptioninApiVersionStrategy.validateVersion(java.lang.Comparable<?>, jakarta.servlet.http.HttpServletRequest).- Parameters:
- versions- the versions to add
 
- 
resolveVersionDescription copied from interface:ApiVersionStrategyResolve the version value from a request, e.g. from a request header.- Specified by:
- resolveVersionin interface- ApiVersionStrategy
- Parameters:
- request- the current request
- Returns:
- the version, if present or null
 
- 
parseVersionDescription copied from interface:ApiVersionStrategyParse the version of a request into an Object.- Specified by:
- parseVersionin interface- ApiVersionStrategy
- Parameters:
- version- the value to parse
- Returns:
- an Object that represents the version
 
- 
validateVersionpublic void validateVersion(@Nullable Comparable<?> requestVersion, HttpServletRequest request) throws MissingApiVersionException, InvalidApiVersionException Description copied from interface:ApiVersionStrategyValidate a request version, including required and supported version checks.- Specified by:
- validateVersionin interface- ApiVersionStrategy
- Parameters:
- requestVersion- the version to validate
- request- the request
- Throws:
- MissingApiVersionException- if the version is required, but not specified
- InvalidApiVersionException- if the version is not supported
 
- 
toString
 
-