Skip to content

Commit 40eb9c2

Browse files
committed
Add docs for API version deprecation support
Closes gh-35049
1 parent 482cfb0 commit 40eb9c2

File tree

6 files changed

+96
-45
lines changed

6 files changed

+96
-45
lines changed

framework-docs/modules/ROOT/pages/web/webflux-versioning.adoc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,20 @@ You can also specify a default version to use.
7979

8080

8181

82+
[[webflux-versioning-deprecation-handler]]
83+
== ApiVersionDeprecationHandler
84+
[.small]#xref:web/webmvc-versioning.adoc#mvc-versioning-deprecation-handler[See equivalent in the Reactive stack]#
85+
86+
This strategy can be configured to send hints and information about deprecated versions to
87+
clients via response headers. The built-in `StandardApiVersionDeprecationHandler`
88+
can set the "Deprecation" "Sunset" headers and "Link" headers as defined in
89+
https://datatracker.ietf.org/doc/html/rfc9745[RFC 9745] and
90+
https://datatracker.ietf.org/doc/html/rfc8594[RFC 8594]. You can also configure a custom
91+
handler for different headers.
92+
93+
94+
95+
8296
[[webflux-versioning-mapping]]
8397
== Request Mapping
8498
[.small]#xref:web/webmvc-versioning.adoc#mvc-versioning-mapping[See equivalent in the Servlet stack]#

framework-docs/modules/ROOT/pages/web/webflux/config.adoc

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ reliance on it.
690690
== API Version
691691
[.small]#xref:web/webmvc/mvc-config/api-version.adoc[See equivalent in the Servlet stack]#
692692

693-
To enable API versioning with a request header, use the following:
693+
To enable API versioning, use the `ApiVersionConfigurer` callback of `WebFluxConfigurer`:
694694

695695
[tabs]
696696
======
@@ -722,19 +722,30 @@ Kotlin::
722722
----
723723
======
724724

725-
Alternatively, the version can be resolved from a request parameter, from a path segment,
726-
or through a custom `ApiVersionResolver`.
725+
You can resolve the version through one of the built-in options listed below, or
726+
alternatively use a custom `ApiVersionResolver`:
727+
728+
- Request header
729+
- Request parameter
730+
- Path segment
731+
- Media type parameter
727732

728733
TIP: When using a path segment, consider configuring a shared path prefix externally
729734
in xref:web/webmvc/mvc-config/path-matching.adoc[Path Matching] options.
730735

731-
Raw version values are parsed with `SemanticVersionParser` by default, but you can use
736+
By default, the version is parsed with `SemanticVersionParser`, but you can also configure
732737
a custom xref:web/webflux-versioning.adoc#webflux-versioning-parser[ApiVersionParser].
733738

734-
"Supported" versions are transparently detected from versions declared in request mappings
735-
for convenience, but you can turn that off through a flag in the WebFlux config, and use only
736-
the versions configured explicitly in the config. Requests with a version that is not
737-
supported are rejected with `InvalidApiVersionException` resulting in a 400 response.
739+
Supported versions are transparently detected from versions declared in request mappings
740+
for convenience, but you can turn that off through a flag in the WebFlux config, and
741+
consider only the versions configured explicitly in the config as supported.
742+
Requests with a version that is not supported are rejected with
743+
`InvalidApiVersionException` resulting in a 400 response.
744+
745+
You can set an `ApiVersionDeprecationHandler` to send information about deprecated
746+
versions to clients. The built-in standard handler can set "Deprecation", "Sunset", and
747+
"Link" headers based on https://datatracker.ietf.org/doc/html/rfc9745[RFC 9745] and
748+
https://datatracker.ietf.org/doc/html/rfc8594[RFC 8594].
738749

739750
Once API versioning is configured, you can begin to map requests to
740751
xref:web/webflux/controller/ann-requestmapping.adoc#webflux-ann-requestmapping-version[controller methods]

framework-docs/modules/ROOT/pages/web/webmvc-versioning.adoc

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ related to versioning. It does the following:
3030
- Resolves versions from the requests via xref:#mvc-versioning-resolver[ApiVersionResolver]
3131
- Parses raw version values into `Comparable<?>` with an xref:#mvc-versioning-parser[ApiVersionParser]
3232
- xref:#mvc-versioning-validation[Validates] request versions
33+
- Sends deprecation hints in the responses
3334

3435
`ApiVersionStrategy` helps to map requests to `@RequestMapping` controller methods,
3536
and is initialized by the MVC config. Typically, applications do not interact
@@ -40,7 +41,7 @@ directly with it.
4041

4142
[[mvc-versioning-resolver]]
4243
== ApiVersionResolver
43-
[.small]#xref:web/webmvc-versioning.adoc#mvc-versioning-resolver[See equivalent in the Reactive stack]#
44+
[.small]#xref:web/webflux-versioning.adoc#webflux-versioning-resolver[See equivalent in the Reactive stack]#
4445

4546
This strategy resolves the API version from a request. The MVC config provides built-in
4647
options to resolve from a header, from a request parameter, or from the URL path.
@@ -78,6 +79,20 @@ You can also specify a default version to use.
7879

7980

8081

82+
[[mvc-versioning-deprecation-handler]]
83+
== ApiVersionDeprecationHandler
84+
[.small]#xref:web/webflux-versioning.adoc#webflux-versioning-deprecation-handler[See equivalent in the Reactive stack]#
85+
86+
This strategy can be configured to send hints and information about deprecated versions to
87+
clients via response headers. The built-in `StandardApiVersionDeprecationHandler`
88+
can set the "Deprecation" "Sunset" headers and "Link" headers as defined in
89+
https://datatracker.ietf.org/doc/html/rfc9745[RFC 9745] and
90+
https://datatracker.ietf.org/doc/html/rfc8594[RFC 8594]. You can also configure a custom
91+
handler for different headers.
92+
93+
94+
95+
8196
[[mvc-versioning-mapping]]
8297
== Request Mapping
8398
[.small]#xref:web/webflux-versioning.adoc#webflux-versioning-mapping[See equivalent in the Reactive stack]#

framework-docs/modules/ROOT/pages/web/webmvc/mvc-config/api-version.adoc

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,34 @@
33

44
[.small]#xref:web/webflux/config.adoc#webflux-config-api-version[See equivalent in the Reactive stack]#
55

6-
To enable API versioning with a request header, use the following:
6+
To enable API versioning, use the `ApiVersionConfigurer` callback of `WebMvcConfigurer`:
77

88
include-code::./WebConfiguration[tag=snippet,indent=0]
99

10-
Alternatively, the version can be resolved from a request parameter, from a path segment,
11-
or through a custom `ApiVersionResolver`.
10+
You can resolve the version through one of the built-in options listed below, or
11+
alternatively use a custom `ApiVersionResolver`:
12+
13+
- Request header
14+
- Request parameter
15+
- Path segment
16+
- Media type parameter
1217

1318
TIP: When using a path segment, consider configuring a shared path prefix externally
1419
in xref:web/webmvc/mvc-config/path-matching.adoc[Path Matching] options.
1520

16-
Raw version values are parsed with `SemanticVersionParser` by default, but you can use
21+
By default, the version is parsed with `SemanticVersionParser`, but you can also configure
1722
a custom xref:web/webmvc-versioning.adoc#mvc-versioning-parser[ApiVersionParser].
1823

19-
"Supported" versions are transparently detected from versions declared in request mappings
20-
for convenience, but you can turn that off through a flag in the MVC config, and use only
21-
the versions configured explicitly in the config. Requests with a version that is not
22-
supported are rejected with `InvalidApiVersionException` resulting in a 400 response.
24+
Supported versions are transparently detected from versions declared in request mappings
25+
for convenience, but you can turn that off through a flag in the MVC config, and
26+
consider only the versions configured explicitly in the config as supported.
27+
Requests with a version that is not supported are rejected with
28+
`InvalidApiVersionException` resulting in a 400 response.
29+
30+
You can set an `ApiVersionDeprecationHandler` to send information about deprecated
31+
versions to clients. The built-in standard handler can set "Deprecation", "Sunset", and
32+
"Link" headers based on https://datatracker.ietf.org/doc/html/rfc9745[RFC 9745] and
33+
https://datatracker.ietf.org/doc/html/rfc8594[RFC 8594].
2334

2435
Once API versioning is configured, you can begin to map requests to
2536
xref:web/webmvc/mvc-controller/ann-requestmapping.adoc#mvc-ann-requestmapping-version[controller methods]

spring-webflux/src/main/java/org/springframework/web/reactive/config/ApiVersionConfigurer.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ public class ApiVersionConfigurer {
5353

5454
private @Nullable String defaultVersion;
5555

56-
private @Nullable ApiVersionDeprecationHandler deprecationHandler;
57-
5856
private final Set<String> supportedVersions = new LinkedHashSet<>();
5957

6058
private boolean detectSupportedVersions = true;
6159

60+
private @Nullable ApiVersionDeprecationHandler deprecationHandler;
61+
6262

6363
/**
6464
* Add a resolver that extracts the API version from a request header.
@@ -145,18 +145,6 @@ public ApiVersionConfigurer setDefaultVersion(@Nullable String defaultVersion) {
145145
return this;
146146
}
147147

148-
/**
149-
* Configure a handler to add handling for requests with a deprecated API
150-
* version. Typically, this involves sending hints and information about
151-
* the deprecation in response headers.
152-
* @param handler the handler to use
153-
* @see StandardApiVersionDeprecationHandler
154-
*/
155-
public ApiVersionConfigurer setDeprecationHandler(ApiVersionDeprecationHandler handler) {
156-
this.deprecationHandler = handler;
157-
return this;
158-
}
159-
160148
/**
161149
* Add to the list of supported versions to check against before raising
162150
* {@link InvalidApiVersionException} for unknown versions.
@@ -187,6 +175,18 @@ public ApiVersionConfigurer detectSupportedVersions(boolean detect) {
187175
return this;
188176
}
189177

178+
/**
179+
* Configure a handler to add handling for requests with a deprecated API
180+
* version. Typically, this involves sending hints and information about
181+
* the deprecation in response headers.
182+
* @param handler the handler to use
183+
* @see StandardApiVersionDeprecationHandler
184+
*/
185+
public ApiVersionConfigurer setDeprecationHandler(ApiVersionDeprecationHandler handler) {
186+
this.deprecationHandler = handler;
187+
return this;
188+
}
189+
190190
protected @Nullable ApiVersionStrategy getApiVersionStrategy() {
191191
if (this.versionResolvers.isEmpty()) {
192192
return null;

spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ApiVersionConfigurer.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ public class ApiVersionConfigurer {
5353

5454
private @Nullable String defaultVersion;
5555

56-
private @Nullable ApiVersionDeprecationHandler deprecationHandler;
57-
5856
private final Set<String> supportedVersions = new LinkedHashSet<>();
5957

6058
private boolean detectSupportedVersions = true;
6159

60+
private @Nullable ApiVersionDeprecationHandler deprecationHandler;
61+
6262

6363
/**
6464
* Add resolver to extract the version from a request header.
@@ -145,18 +145,6 @@ public ApiVersionConfigurer setDefaultVersion(@Nullable String defaultVersion) {
145145
return this;
146146
}
147147

148-
/**
149-
* Configure a handler to add handling for requests with a deprecated API
150-
* version. Typically, this involves sending hints and information about
151-
* the deprecation in response headers.
152-
* @param handler the handler to use
153-
* @see StandardApiVersionDeprecationHandler
154-
*/
155-
public ApiVersionConfigurer setDeprecationHandler(ApiVersionDeprecationHandler handler) {
156-
this.deprecationHandler = handler;
157-
return this;
158-
}
159-
160148
/**
161149
* Add to the list of supported versions to check against before raising
162150
* {@link InvalidApiVersionException} for unknown versions.
@@ -187,6 +175,18 @@ public ApiVersionConfigurer detectSupportedVersions(boolean detect) {
187175
return this;
188176
}
189177

178+
/**
179+
* Configure a handler to add handling for requests with a deprecated API
180+
* version. Typically, this involves sending hints and information about
181+
* the deprecation in response headers.
182+
* @param handler the handler to use
183+
* @see StandardApiVersionDeprecationHandler
184+
*/
185+
public ApiVersionConfigurer setDeprecationHandler(ApiVersionDeprecationHandler handler) {
186+
this.deprecationHandler = handler;
187+
return this;
188+
}
189+
190190
protected @Nullable ApiVersionStrategy getApiVersionStrategy() {
191191
if (this.versionResolvers.isEmpty()) {
192192
return null;

0 commit comments

Comments
 (0)