Skip to content

Commit aae2fb7

Browse files
authored
Update API version policy to handle path params (#24996)
For an API version in a path segment, it is assumed that the client has replaced the applicable path segment with the API version. In this case, the pipeline policy is a no-op.
1 parent e1505f7 commit aae2fb7

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

sdk/azcore/CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
# Release History
22

3-
## 1.18.3-beta.1 (Unreleased)
3+
## 1.19.0 (Unreleased)
44

55
### Features Added
66

7+
* Added `runtime.APIVersionLocationPath` to be set by clients that set the API version in the path.
8+
79
### Breaking Changes
810

911
### Bugs Fixed

sdk/azcore/internal/shared/constants.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,5 @@ const (
4040
Module = "azcore"
4141

4242
// Version is the semantic version (see http://semver.org) of this module.
43-
Version = "v1.18.3-beta.1"
43+
Version = "v1.19.0"
4444
)

sdk/azcore/runtime/policy_api_version.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ import (
1616

1717
// APIVersionOptions contains options for API versions
1818
type APIVersionOptions struct {
19-
// Location indicates where to set the version on a request, for example in a header or query param
19+
// Location indicates where to set the version on a request, for example in a header or query param.
2020
Location APIVersionLocation
21-
// Name is the name of the header or query parameter, for example "api-version"
21+
// Name is the name of the header or query parameter, for example "api-version".
22+
// For [APIVersionLocationPath] the value is not used.
2223
Name string
2324
}
2425

@@ -30,6 +31,8 @@ const (
3031
APIVersionLocationQueryParam = 0
3132
// APIVersionLocationHeader indicates a header
3233
APIVersionLocationHeader = 1
34+
// APIVersionLocationPath indicates a path segment
35+
APIVersionLocationPath = 2
3336
)
3437

3538
// newAPIVersionPolicy constructs an APIVersionPolicy. If version is "", Do will be a no-op. If version
@@ -55,7 +58,10 @@ type apiVersionPolicy struct {
5558

5659
// Do sets the request's API version, if the policy is configured to do so, replacing any prior value.
5760
func (a *apiVersionPolicy) Do(req *policy.Request) (*http.Response, error) {
58-
if a.version != "" {
61+
// for API versions in the path, the client is responsible for
62+
// setting the correct path segment with the version. so, if the
63+
// location is path the policy is effectively a no-op.
64+
if a.location != APIVersionLocationPath && a.version != "" {
5965
if a.name == "" {
6066
// user set ClientOptions.APIVersion but the client ctor didn't set PipelineOptions.APIVersionOptions
6167
return nil, errors.New("this client doesn't support overriding its API version")

sdk/azcore/runtime/policy_api_version_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@ func TestAPIVersionPolicy(t *testing.T) {
8080
// ctor via NewPipeline(). The policy should return an error when the user specifies a version
8181
// the policy can't set because the service client didn't identify the header/query param.
8282
{version: version, err: true},
83-
{location: 2, version: version, err: true},
83+
{location: 3, version: version, err: true},
84+
85+
// for APIVersionLocationPath the policy does nothing
86+
{location: APIVersionLocationPath},
8487
} {
8588
t.Run("no-op", func(t *testing.T) {
8689
p := newAPIVersionPolicy(test.version, &APIVersionOptions{Location: test.location, Name: test.name})

0 commit comments

Comments
 (0)