Skip to content
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

Implement Response abstraction for Azure #46530

Merged
merged 18 commits into from
Oct 23, 2024

Conversation

live1206
Copy link
Member

Resolves #45705

@live1206
Copy link
Member Author

For now, we can't consume NuGet package from MGC due to microsoft/typespec#4507.

@live1206 live1206 added the CodeGen Issues that relate to code generation label Oct 10, 2024
@live1206 live1206 changed the title Response abstraction Implement Response abstraction for Azure Oct 10, 2024
@live1206
Copy link
Member Author

Will create a new PR to upgrade MGC version to reduce the changes in this PR.

@jsquire
Copy link
Member

jsquire commented Oct 10, 2024

It would be super helpful for these to see an example of what the generated code looks like.

@live1206 live1206 merged commit 47f3c9b into Azure:main Oct 23, 2024
40 checks passed
@live1206 live1206 deleted the response-abstraction branch October 23, 2024 08:54
@@ -50,11 +52,11 @@ public BasicTypeSpecClient(Uri endpoint, ApiKeyCredential keyCredential, BasicTy

_endpoint = endpoint;
_keyCredential = keyCredential;
Pipeline = ClientPipeline.Create(options, Array.Empty<PipelinePolicy>(), new PipelinePolicy[] { ApiKeyAuthenticationPolicy.CreateHeaderApiKeyPolicy(_keyCredential, AuthorizationHeader) }, Array.Empty<PipelinePolicy>());
Pipeline = HttpPipelineBuilder.Build(options, new HttpPipelinePolicy[] { });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this have an authentication policy?

PipelineRequest request = message.Request;
request.Method = "GET";
Request request = message.Request;
request.Method = new RequestMethod("GET");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RequestMethod.Get will prevent making an allocation here.

request.Headers.Set("Accept", "application/json");
message.Apply(options);
request.Uri = uri;
request.Headers.Add("head-parameter", headParameter);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why Add and not Set?

PipelineRequest request = message.Request;
request.Method = "GET";
Request request = message.Request;
request.Method = new RequestMethod("GET");
ClientUriBuilder uri = new ClientUriBuilder();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does Azure.Core have ClientUriBuilder? I believe Azure clients can set the URI in the request directly.


namespace BasicTypeSpec
{
/// <summary> Client options for <see cref="BasicTypeSpecClient"/>. </summary>
public partial class BasicTypeSpecClientOptions : ClientPipelineOptions
public partial class BasicTypeSpecClientOptions : ClientOptions
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These will be more different going forward ... just a heads up that more will need to differ here.

{
await pipeline.SendAsync(message).ConfigureAwait(false);
await pipeline.SendAsync(message, default).ConfigureAwait(false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should pass the CancellationToken through to pipeline.Send from RequestContext.

}

PipelineResponse response = message.BufferResponse ? message.Response : message.ExtractResponse();
Response response = message.BufferResponse ? message.Response : ExtractResponseContent(message);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should sync on ExtractResponseContent ... this may not be the right pattern for Azure clients.


namespace BasicTypeSpec
{
internal partial class ErrorResult<T> : ClientResult<T>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should remove this from unbranded clients. SCM-based clients should never throw from a property.

@live1206
Copy link
Member Author

live1206 commented Oct 24, 2024

@annelo-msft Thanks a lot for reviewing the generated SDK for Azure Plugin!
The idea is not to have everything in place in this PR. The Azure plugin is still working in progress.
#46800 created to track comments in this PR and will have follow-up PRs to mitigate the remaining issues.

@annelo-msft
Copy link
Member

Sounds great. Many thanks, @live1206!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CodeGen Issues that relate to code generation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update ClientResult to Azure.Core.Response for Azure plugin
5 participants