Class ApiVersionConfigurer

java.lang.Object
org.springframework.web.reactive.config.ApiVersionConfigurer

public class ApiVersionConfigurer extends Object
Configure API versioning.
Since:
7.0
Author:
Rossen Stoyanchev
  • Constructor Details

    • ApiVersionConfigurer

      public ApiVersionConfigurer()
  • Method Details

    • useRequestHeader

      public ApiVersionConfigurer useRequestHeader(String headerName)
      Add a resolver that extracts the API version from a request header.
      Parameters:
      headerName - the header name to check
    • useRequestParam

      public ApiVersionConfigurer useRequestParam(String paramName)
      Add a resolver that extracts the API version from a request parameter.
      Parameters:
      paramName - the parameter name to check
    • usePathSegment

      public ApiVersionConfigurer usePathSegment(int index)
      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

      public ApiVersionConfigurer useVersionResolver(ApiVersionResolver... resolvers)
      Add custom resolvers to resolve the API version.
      Parameters:
      resolvers - the resolvers to use
    • setVersionParser

      public ApiVersionConfigurer setVersionParser(@Nullable ApiVersionParser<?> versionParser)
      Configure a parser to parse API versions with.

      By default, SemanticApiVersionParser is used.

      Parameters:
      versionParser - the parser to user
    • setVersionRequired

      public ApiVersionConfigurer setVersionRequired(boolean required)
      Whether requests are required to have an API version. When set to true, 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 one ApiVersionResolver). When a defaultVersion is also set, this is automatically set to false.

      Parameters:
      required - whether an API version is required.
    • setDefaultVersion

      public ApiVersionConfigurer setDefaultVersion(@Nullable String defaultVersion)
      Configure a default version to assign to requests that don't specify one.
      Parameters:
      defaultVersion - the default version to use
    • addSupportedVersions

      public ApiVersionConfigurer addSupportedVersions(String... versions)
      Add to the list of supported versions to check against before raising InvalidApiVersionException 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 to false.

      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

      public ApiVersionConfigurer detectSupportedVersions(boolean detect)
      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 to false if you want to use only explicitly configured supported versions.

      Parameters:
      detect - whether to use detected versions for validation
    • getApiVersionStrategy

      protected @Nullable ApiVersionStrategy getApiVersionStrategy()