Skip to content

Commit 3cb8a83

Browse files
committed
Polishing API versioning ref docs
1 parent 785aab8 commit 3cb8a83

File tree

6 files changed

+83
-76
lines changed

6 files changed

+83
-76
lines changed

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

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ and underlying strategies.
99

1010
Please, see also related content in:
1111

12-
- Use xref:web/webflux/controller/ann-requestmapping.adoc#webflux-ann-requestmapping-version[API Versions]
13-
to map requests to annotated controller methods
14-
- Configure API versioning in xref:web/webflux/config.adoc#webflux-config-api-version[WebFlux Config]
12+
- Configure xref:web/webflux/config.adoc#webflux-config-api-version[API versioning]
13+
in the WebFlux Config
14+
- xref:web/webflux/controller/ann-requestmapping.adoc#webflux-ann-requestmapping-version[Map requests]
15+
to annotated controller methods with an API version
1516

16-
TIP: API versioning is also supported on the client side in `RestClient`, `WebClient`, and
17+
Client support for API versioning is available also in `RestClient`, `WebClient`, and
1718
xref:integration/rest-clients.adoc#rest-http-interface[HTTP Service] clients, as well as
18-
for testing with `WebTestClient`.
19+
for testing in `WebTestClient`.
1920

2021

2122

@@ -24,14 +25,16 @@ for testing with `WebTestClient`.
2425
== ApiVersionStrategy
2526
[.small]#xref:web/webmvc-versioning.adoc#mvc-versioning-strategy[See equivalent in the Servlet stack]#
2627

27-
This strategy holds all application preferences about how to manage versioning.
28-
It delegates to xref:#webflux-versioning-resolver[ApiVersionResolver] to resolve versions
29-
from requests, and to xref:#webflux-versioning-parser[ApiVersionParser] to parse raw version
30-
values into `Comparable<?>`. It also helps to xref:#webflux-versioning-validation[validate]
31-
request versions.
28+
This is the central strategy for API versioning that holds all configured preferences
29+
related to versioning. It does the following:
3230

33-
NOTE: `ApiVersionStrategy` helps to map requests to `@RequestMapping` controller methods,
34-
and is initialized by the WebFlux config. Typically, applications do not interact directly with it.
31+
- Resolves versions from the requests via xref:#webflux-versioning-resolver[ApiVersionResolver]
32+
- Parses raw version values into `Comparable<?>` with xref:#webflux-versioning-parser[ApiVersionParser]
33+
- xref:#webflux-versioning-validation[Validates] request versions
34+
35+
`ApiVersionStrategy` helps to map requests to `@RequestMapping` controller methods,
36+
and is initialized by the WebFlux config. Typically, applications do not interact
37+
directly with it.
3538

3639

3740

@@ -53,7 +56,7 @@ You can also use a custom `ApiVersionResolver`.
5356

5457
This strategy helps to parse raw version values into `Comparable<?>`, which helps to
5558
compare, sort, and select versions. By default, the built-in `SemanticApiVersionParser`
56-
parses a version into `major`, `minor`, and `patch` integer values. Minor and patch
59+
parses a version into `major`, `minor`, and `patWebFluxch` integer values. Minor and patch
5760
values are set to 0 if not present.
5861

5962

@@ -65,13 +68,13 @@ values are set to 0 if not present.
6568

6669
If a request version is not supported, `InvalidApiVersionException` is raised resulting
6770
in a 400 response. By default, the list of supported versions is initialized from declared
68-
versions in annotated controller mappings. You can add to that list, or set it explicitly
69-
to a fixed set of versions (i.e. ignoring declared ones) through the MVC config.
71+
versions in annotated controller mappings, but you can turn that off through a flag in the
72+
WebFlux config, and use only the versions configured explicitly in the config.
7073

71-
By default, a version is required when API versioning is enabled, but you can turn that
72-
off in which case the highest available version is used. You can also specify a default
73-
version. `MissingApiVersionException` is raised resulting in a 400 response when a
74-
version is required but not present.
74+
By default, a version is required when API versioning is enabled, and
75+
`MissingApiVersionException` is raised resulting in a 400 response if not present.
76+
You can make it optional in which case the most recent version is used.
77+
You can also specify a default version to use.
7578

7679

7780

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -725,16 +725,16 @@ Kotlin::
725725
Alternatively, the version can be resolved from a request parameter, from a path segment,
726726
or through a custom `ApiVersionResolver`.
727727

728-
TIP: When resolving from a path segment, consider configuring a path prefix once in
729-
xref:web/webmvc/mvc-config/path-matching.adoc[Path Matching] options.
728+
TIP: When using a path segment, consider configuring a shared path prefix externally
729+
in xref:web/webmvc/mvc-config/path-matching.adoc[Path Matching] options.
730730

731731
Raw version values are parsed with `SemanticVersionParser` by default, but you can use
732732
a custom xref:web/webflux-versioning.adoc#webflux-versioning-parser[ApiVersionParser].
733733

734734
"Supported" versions are transparently detected from versions declared in request mappings
735-
for convenience, but you can also set the list of supported versions explicitly, and
736-
ignore declared ones. Requests with a version that is not supported are rejected with an
737-
`InvalidApiVersionException` resulting in a 400 response.
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.
738738

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

framework-docs/modules/ROOT/pages/web/webflux/controller/ann-requestmapping.adoc

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -412,24 +412,24 @@ Kotlin::
412412
== API Version
413413
[.small]#xref:web/webmvc/mvc-controller/ann-requestmapping.adoc#mvc-ann-requestmapping-version[See equivalent in the Servlet stack]#
414414

415-
There is no standard way to specify an API version, so you need to configure that first
416-
through the xref:web/webflux/config.adoc#webflux-config-api-version[WebFlux Config] along with other
417-
config options. This results in the creation of an
418-
xref:web/webflux-versioning.adoc#webflux-versioning-strategy[ApiVersionStrategy] that in
419-
supports request mapping.
415+
There is no standard way to specify an API version, so when you enable API versioning
416+
in the xref:web/webflux/config.adoc#webflux-config-api-version[WebFlux Config] you need
417+
to specify how to resolve the version. The WebFlux Config creates an
418+
xref:web/webflux-versioning.adoc#webflux-versioning-strategy[ApiVersionStrategy] that in turn
419+
is used to map requests.
420420

421421
Once API versioning is enabled, you can begin to map requests with versions.
422-
The `@RequestMapping` version attribute supports the following:
422+
The `@RequestMapping` `version` attribute supports the following:
423423

424-
- No value -- match any version
425-
- Fixed version ("1.2") -- match the given version only
426-
- Baseline version ("1.2+") -- match the given version and above
424+
- No value -- matches any version
425+
- Fixed version ("1.2") -- matches the given version only
426+
- Baseline version ("1.2+") -- matches the given version and above
427427

428428
If multiple controller methods have a version less than or equal to the request version,
429-
the one closest to the request version is considered for mapping purposes,
429+
the highest of those, and closest to the request version, is the one considered,
430430
in effect superseding the rest.
431431

432-
To illustrate this, consider the following controller mappings:
432+
To illustrate this, consider the following mappings:
433433

434434
[tabs]
435435
======
@@ -479,11 +479,12 @@ For request with version `"1.5"`:
479479
- (4) matches and is *chosen* as the highest match
480480

481481
A request with version `"1.6"` does not have a match. (1) and (3) do match, but are
482-
superseded by (4), which does not match. In this scenario, `NotAcceptableApiVersionException`
483-
is raised resulting in a 400 response.
482+
superseded by (4), which allows only a strict match, and therefore does not match.
483+
In this scenario, a `NotAcceptableApiVersionException` results in a 400 response.
484484

485-
NOTE: The above assumes the request version is a "supported" versions. If not it would
486-
fail xref:web/webflux-versioning.adoc#webflux-versioning-validation[Validation].
485+
NOTE: The above assumes the request version is a
486+
xref:web/webmvc/mvc-config/api-version.adoc["supported" version], or otherwise it
487+
would fail xref:web/webflux-versioning.adoc#webflux-versioning-validation[Validation].
487488

488489

489490

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

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ and underlying strategies.
99

1010
Please, see also related content in:
1111

12-
- Use xref:web/webmvc/mvc-controller/ann-requestmapping.adoc#mvc-ann-requestmapping-version[API Version]
13-
to map requests to annotated controller methods
14-
- Configure API versioning in xref:web/webmvc/mvc-config/api-version.adoc[MVC Config]
12+
- Configure xref:web/webmvc/mvc-config/api-version.adoc[API versioning] in the MVC Config
13+
- xref:web/webmvc/mvc-controller/ann-requestmapping.adoc#mvc-ann-requestmapping-version[Map requests]
14+
to annotated controller methods with an API version
1515

16-
TIP: API versioning is also supported on the client side in `RestClient`, `WebClient`, and
16+
Client support for API versioning is available also in `RestClient`, `WebClient`, and
1717
xref:integration/rest-clients.adoc#rest-http-interface[HTTP Service] clients, as well as
18-
for testing with `WebTestClient`.
18+
for testing in MockMvc and `WebTestClient`.
1919

2020

2121

@@ -24,14 +24,16 @@ for testing with `WebTestClient`.
2424
== ApiVersionStrategy
2525
[.small]#xref:web/webflux-versioning.adoc#webflux-versioning-strategy[See equivalent in the Reactive stack]#
2626

27-
This strategy holds all application preferences about how to manage versioning.
28-
It delegates to xref:#mvc-versioning-resolver[ApiVersionResolver] to resolve versions
29-
from requests, and to xref:#mvc-versioning-parser[ApiVersionParser] to parse raw version
30-
values into `Comparable<?>`. It also helps to xref:#mvc-versioning-validation[validate]
31-
request versions.
27+
This is the central strategy for API versioning that holds all configured preferences
28+
related to versioning. It does the following:
3229

33-
NOTE: `ApiVersionStrategy` helps to map requests to `@RequestMapping` controller methods,
34-
and is initialized by the MVC config. Typically, applications do not interact directly with it.
30+
- Resolves versions from the requests via xref:#mvc-versioning-resolver[ApiVersionResolver]
31+
- Parses raw version values into `Comparable<?>` with an xref:#mvc-versioning-parser[ApiVersionParser]
32+
- xref:#mvc-versioning-validation[Validates] request versions
33+
34+
`ApiVersionStrategy` helps to map requests to `@RequestMapping` controller methods,
35+
and is initialized by the MVC config. Typically, applications do not interact
36+
directly with it.
3537

3638

3739

@@ -65,13 +67,13 @@ values are set to 0 if not present.
6567

6668
If a request version is not supported, `InvalidApiVersionException` is raised resulting
6769
in a 400 response. By default, the list of supported versions is initialized from declared
68-
versions in annotated controller mappings. You can add to that list, or set it explicitly
69-
to a fixed set of versions (i.e. ignoring declared ones) through the MVC config.
70+
versions in annotated controller mappings, but you can turn that off through a flag in the
71+
MVC config, and use only the versions configured explicitly in the config.
7072

71-
By default, a version is required when API versioning is enabled, but you can turn that
72-
off in which case the highest available version is used. You can also specify a default
73-
version. `MissingApiVersionException` is raised resulting in a 400 response when a
74-
version is required but not present.
73+
By default, a version is required when API versioning is enabled, and
74+
`MissingApiVersionException` is raised resulting in a 400 response if not present.
75+
You can make it optional in which case the most recent version is used.
76+
You can also specify a default version to use.
7577

7678

7779

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ include-code::./WebConfiguration[tag=snippet,indent=0]
1010
Alternatively, the version can be resolved from a request parameter, from a path segment,
1111
or through a custom `ApiVersionResolver`.
1212

13-
TIP: When resolving from a path segment, consider configuring a path prefix once in
14-
xref:web/webmvc/mvc-config/path-matching.adoc[Path Matching] options.
13+
TIP: When using a path segment, consider configuring a shared path prefix externally
14+
in xref:web/webmvc/mvc-config/path-matching.adoc[Path Matching] options.
1515

1616
Raw version values are parsed with `SemanticVersionParser` by default, but you can use
1717
a custom xref:web/webmvc-versioning.adoc#mvc-versioning-parser[ApiVersionParser].
1818

1919
"Supported" versions are transparently detected from versions declared in request mappings
20-
for convenience, but you can also set the list of supported versions explicitly, and
21-
ignore declared ones. Requests with a version that is not supported are rejected with an
22-
`InvalidApiVersionException` resulting in a 400 response.
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.
2323

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

framework-docs/modules/ROOT/pages/web/webmvc/mvc-controller/ann-requestmapping.adoc

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -433,24 +433,24 @@ instead.
433433
== API Version
434434
[.small]#xref:web/webflux/controller/ann-requestmapping.adoc#webflux-ann-requestmapping-version[See equivalent in the Reactive stack]#
435435

436-
There is no standard way to specify an API version, so you need to configure that first
437-
through the xref:web/webmvc/mvc-config/api-version.adoc[MVC Config] along with other
438-
config options. This results in the creation of an
436+
There is no standard way to specify an API version, so when you enable API versioning
437+
in the xref:web/webmvc/mvc-config/api-version.adoc[MVC Config] you need
438+
to specify how to resolve the version. The MVC Config creates an
439439
xref:web/webmvc-versioning.adoc#mvc-versioning-strategy[ApiVersionStrategy] that in turn
440-
supports request mapping.
440+
is used to map requests.
441441

442442
Once API versioning is enabled, you can begin to map requests with versions.
443-
The `@RequestMapping` version attribute supports the following:
443+
The `@RequestMapping` `version` attribute supports the following:
444444

445-
- No value -- match any version
446-
- Fixed version ("1.2") -- match the given version only
447-
- Baseline version ("1.2+") -- match the given version and above
445+
- No value -- matches any version
446+
- Fixed version ("1.2") -- matches the given version only
447+
- Baseline version ("1.2+") -- matches the given version and above
448448

449449
If multiple controller methods have a version less than or equal to the request version,
450-
the one closest to the request version is considered for mapping purposes,
450+
the highest of those, and closest to the request version, is the one considered,
451451
in effect superseding the rest.
452452

453-
To illustrate this, consider the following controller mappings:
453+
To illustrate this, consider the following mappings:
454454

455455
[tabs]
456456
======
@@ -500,11 +500,12 @@ For request with version `"1.5"`:
500500
- (4) matches and is *chosen* as the highest match
501501

502502
A request with version `"1.6"` does not have a match. (1) and (3) do match, but are
503-
superseded by (4), which does not match. In this scenario, `NotAcceptableApiVersionException`
504-
is raised resulting in a 400 response.
503+
superseded by (4), which allows only a strict match, and therefore does not match.
504+
In this scenario, a `NotAcceptableApiVersionException` results in a 400 response.
505505

506-
NOTE: The above assumes the request version is a "supported" versions. If not it would
507-
fail xref:web/webmvc-versioning.adoc#mvc-versioning-validation[Validation].
506+
NOTE: The above assumes the request version is a
507+
xref:web/webmvc/mvc-config/api-version.adoc["supported" version], or otherwise it
508+
would fail xref:web/webmvc-versioning.adoc#mvc-versioning-validation[Validation].
508509

509510

510511

0 commit comments

Comments
 (0)