Skip to content

Commit 3702031

Browse files
committed
Improve docs on versioning by path segment
Closes gh-35421
1 parent 15c5cf4 commit 3702031

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -718,8 +718,12 @@ alternatively use a custom `ApiVersionResolver`:
718718
- Path segment
719719
- Media type parameter
720720

721-
TIP: When using a path segment, consider configuring a shared path prefix externally
722-
in xref:web/webmvc/mvc-config/path-matching.adoc[Path Matching] options.
721+
To resolve from a path segment, you need to specify the index of the path segment expected
722+
to contain the version. The path segment must be declared as a URI variable, e.g.
723+
"/\{version}", "/api/\{version}", etc. where the actual name is not important.
724+
As the version is typically at the start of the path, consider configuring it externally
725+
as a common path prefix for all handlers through the
726+
xref:web/webflux/config.adoc#webflux-config-path-matching[Path Matching] options.
723727

724728
By default, the version is parsed with `SemanticVersionParser`, but you can also configure
725729
a custom xref:web/webflux-versioning.adoc#webflux-versioning-parser[ApiVersionParser].

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@ alternatively use a custom `ApiVersionResolver`:
1515
- Path segment
1616
- Media type parameter
1717

18-
TIP: When using a path segment, consider configuring a shared path prefix externally
19-
in xref:web/webmvc/mvc-config/path-matching.adoc[Path Matching] options.
18+
To resolve from a path segment, you need to specify the index of the path segment expected
19+
to contain the version. The path segment must be declared as a URI variable, e.g.
20+
"/\{version}", "/api/\{version}", etc. where the actual name is not important.
21+
As the version is typically at the start of the path, consider configuring it externally
22+
as a common path prefix for all handlers through the
23+
xref:web/webmvc/mvc-config/path-matching.adoc[Path Matching] options.
2024

2125
By default, the version is parsed with `SemanticVersionParser`, but you can also configure
2226
a custom xref:web/webmvc-versioning.adoc#mvc-versioning-parser[ApiVersionParser].

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public ApiVersionConfigurer useMediaTypeParameter(MediaType compatibleMediaType,
9999
* <p>Note that this resolver never returns {@code null}, and therefore
100100
* cannot yield to other resolvers, see {@link org.springframework.web.accept.PathApiVersionResolver}.
101101
* @param index the index of the path segment to check; e.g. for URL's like
102-
* "/{version}/..." use index 0, for "/api/{version}/..." index 1.
102+
* {@code "/{version}/..."} use index 0, for {@code "/api/{version}/..."} index 1.
103103
*/
104104
public ApiVersionConfigurer usePathSegment(int index) {
105105
this.versionResolvers.add(new PathApiVersionResolver(index));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public ApiVersionConfigurer useMediaTypeParameter(MediaType compatibleMediaType,
100100
* <p>Note that this resolver never returns {@code null}, and therefore
101101
* cannot yield to other resolvers, see {@link PathApiVersionResolver}.
102102
* @param index the index of the path segment to check; e.g. for URL's like
103-
* "/{version}/..." use index 0, for "/api/{version}/..." index 1.
103+
* {@code "/{version}/..."} use index 0, for {@code "/api/{version}/..."} index 1.
104104
*/
105105
public ApiVersionConfigurer usePathSegment(int index) {
106106
this.versionResolvers.add(new PathApiVersionResolver(index));

0 commit comments

Comments
 (0)