-
Notifications
You must be signed in to change notification settings - Fork 83
feat(typespec-go): support paging with a relative nextLink #5079
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| changeKind: feature | ||
| packages: | ||
| - "@azure-tools/typespec-go" | ||
| --- | ||
|
|
||
| Support paging with a relative nextLink. Pagers now resolve a next link that's relative to the client endpoint before fetching the next page; absolute next links are unchanged. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -102,7 +102,15 @@ func (client *PageableLROsClient) BeginListPrivateEndPoints(ctx context.Context, | |
| return page.NextLink != nil && len(*page.NextLink) > 0 | ||
| }, | ||
| Fetcher: func(ctx context.Context, page *PageableLROsClientListPrivateEndPointsResponse) (PageableLROsClientListPrivateEndPointsResponse, error) { | ||
| resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), *page.NextLink, func(ctx context.Context) (*policy.Request, error) { | ||
| nextLink := *page.NextLink | ||
| // the service can return a next link that's relative to the endpoint, however | ||
| // runtime.FetcherForNextLink requires an absolute URL, so resolve it here. | ||
| if nextLink != "" { | ||
| if u, err := url.Parse(nextLink); err == nil && !u.IsAbs() { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A few problems here.
Do we know at codegen time if the path is relative?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, we could not know that. It's kind of a runtime behavior. I remembered that you said we already support it in swagger cases. But I could not find the related code. Current implementation will change all the generated code, which I do not prefer. Any suggestions?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The swagger case was different than I remembered :(. e.g. here. It uses a swagger-defined operation for constructing the request for the next link. It might be best to update |
||
| nextLink = runtime.JoinPaths(client.internal.Endpoint(), nextLink) | ||
| } | ||
| } | ||
| resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) { | ||
| return client.listPrivateEndPointsCreateRequest(ctx, apiVersion, resourceGroupName, resourceName, options) | ||
| }, nil) | ||
| if err != nil { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't be emitting comments.