-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Implement Response abstraction for Azure #46530
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
Merged
Merged
Changes from 8 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
14b1a0b
wip
live1206 9eb7b36
Merge branch 'main' into response-abstraction
live1206 bffd020
wip
live1206 8696e52
Merge branch 'main' into response-abstraction
live1206 e169d91
minor
live1206 56e642f
implement abstraction for Azure
live1206 2b71d74
Merge branch 'main' into response-abstraction
live1206 7645250
update MGC version
live1206 a0db58a
update
live1206 e77c9fe
Merge branch 'main' into response-abstraction
live1206 d4cd170
fix parameter name
live1206 e4a6a3b
Merge remote-tracking branch 'origin/main' into response-abstraction
live1206 d69064e
update to use pacakge reference of MGC
live1206 58d5f6a
update version and fix format
live1206 1af2172
update MGC to package from main
live1206 e2f69e7
Merge branch 'main' into response-abstraction
live1206 db7e9fe
Add tests for SDK generation
live1206 5019091
fix test
live1206 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...csharp/generator/Azure.Generator/src/Providers/Abstraction/AzureClientResponseProvider.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using Microsoft.Generator.CSharp.ClientModel.Providers; | ||
| using Microsoft.Generator.CSharp.Expressions; | ||
| using Microsoft.Generator.CSharp.Primitives; | ||
| using Microsoft.Generator.CSharp.Snippets; | ||
| using static Microsoft.Generator.CSharp.Snippets.Snippet; | ||
|
|
||
| namespace Azure.Generator.Providers | ||
| { | ||
| internal record AzureClientResponseProvider : ClientResponseApi | ||
| { | ||
| private static IClientResponseApi? _instance; | ||
| internal static IClientResponseApi Instance => _instance ??= new AzureClientResponseProvider(); | ||
| private AzureClientResponseProvider() : base(typeof(Response), Empty) | ||
| { | ||
| } | ||
|
|
||
| public AzureClientResponseProvider(ValueExpression original) : base(typeof(Response), original) | ||
| { | ||
| } | ||
|
|
||
| public override CSharpType ClientResponseType => typeof(Response); | ||
|
|
||
| public override CSharpType ClientResponseOfTType => typeof(Response<>); | ||
|
|
||
| public override CSharpType ClientResponseExceptionType => typeof(RequestFailedException); | ||
|
|
||
| public override ValueExpression CreateAsync(HttpResponseApi response) | ||
| => New.Instance(ClientResponseExceptionType, [response]); | ||
|
|
||
| public override ClientResponseApi FromExpression(ValueExpression original) | ||
| => new AzureClientResponseProvider(original); | ||
|
|
||
| public override ValueExpression FromResponse(ValueExpression valueExpression) => valueExpression; | ||
|
|
||
| public override ValueExpression FromValue(ValueExpression valueExpression, HttpResponseApi response) | ||
| => Static(ClientResponseType).Invoke(nameof(FromValue), [valueExpression, response]); | ||
|
|
||
| public override ValueExpression FromValue<ValueType>(ValueExpression valueExpression, HttpResponseApi response) | ||
| => Static(ClientResponseType).Invoke(nameof(FromValue), [valueExpression, response], [typeof(ValueType)], false); | ||
|
|
||
| public override HttpResponseApi GetRawResponse() | ||
| => new AzureResponseProvider(GetRawResponseExpression()); | ||
|
|
||
| public override ClientResponseApi ToExpression() => this; | ||
|
|
||
| private ScopedApi<Response> GetRawResponseExpression() => Original.As<Response>(); | ||
| } | ||
| } |
41 changes: 41 additions & 0 deletions
41
...lient-csharp/generator/Azure.Generator/src/Providers/Abstraction/AzureResponseProvider.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using Microsoft.Generator.CSharp.ClientModel.Providers; | ||
| using Microsoft.Generator.CSharp.Expressions; | ||
| using Microsoft.Generator.CSharp.Primitives; | ||
| using Microsoft.Generator.CSharp.Snippets; | ||
| using System; | ||
| using System.IO; | ||
|
|
||
| namespace Azure.Generator.Providers | ||
| { | ||
| internal record AzureResponseProvider : HttpResponseApi | ||
| { | ||
| private static IHttpResponseApi? _instance; | ||
| internal static IHttpResponseApi Instance => _instance ??= new AzureResponseProvider(); | ||
| private AzureResponseProvider() : base(typeof(Response), Empty) | ||
| { | ||
| } | ||
|
|
||
| public AzureResponseProvider(ValueExpression original) : base(typeof(Response), original) | ||
| { | ||
| } | ||
|
|
||
| public override CSharpType HttpResponseType => typeof(Response); | ||
|
|
||
| public override ScopedApi<BinaryData> Content() | ||
| => Original.Property(nameof(Response.Content)).As<BinaryData>(); | ||
|
|
||
| public override ScopedApi<Stream> ContentStream() | ||
| => Original.Property(nameof(Response.ContentStream)).As<Stream>(); | ||
|
|
||
| public override HttpResponseApi FromExpression(ValueExpression original) | ||
| => new AzureResponseProvider(original); | ||
|
|
||
| public override ScopedApi<bool> IsError() | ||
| => Original.Property(nameof(Response.IsError)).As<bool>(); | ||
|
|
||
| public override HttpResponseApi ToExpression() => this; | ||
| } | ||
| } |
50 changes: 50 additions & 0 deletions
50
...-client-csharp/generator/Azure.Generator/src/Providers/Abstraction/HttpMessageProvider.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using Azure.Core; | ||
| using Microsoft.Generator.CSharp.ClientModel.Providers; | ||
| using Microsoft.Generator.CSharp.Expressions; | ||
| using Microsoft.Generator.CSharp.Primitives; | ||
| using Microsoft.Generator.CSharp.Statements; | ||
| using static Microsoft.Generator.CSharp.Snippets.Snippet; | ||
|
|
||
| namespace Azure.Generator.Providers | ||
| { | ||
| internal record HttpMessageProvider : HttpMessageApi | ||
| { | ||
| private static IHttpMessageApi? _instance; | ||
| internal static IHttpMessageApi Instance => _instance ??= new HttpMessageProvider(); | ||
| private HttpMessageProvider() : base(typeof(HttpMessage), Empty) | ||
| { | ||
| } | ||
|
|
||
| public HttpMessageProvider(ValueExpression original) : base(typeof(HttpMessage), original) | ||
| { | ||
| } | ||
|
|
||
| public override CSharpType HttpMessageType => typeof(HttpMessage); | ||
|
|
||
| public override MethodBodyStatement Apply(ValueExpression options) | ||
| => MethodBodyStatement.Empty; | ||
|
|
||
| public override ValueExpression BufferResponse() | ||
| => Original.Property(nameof(HttpMessage.BufferResponse)); | ||
|
|
||
| public override MethodBodyStatement[] ExtractResponse() | ||
| => [Original.Invoke(nameof(HttpMessage.ExtractResponseContent)).Terminate(), Return(Original.Property(nameof(HttpMessage.Response)))]; | ||
|
|
||
| public override HttpMessageApi FromExpression(ValueExpression original) | ||
| => new HttpMessageProvider(original); | ||
|
|
||
| public override HttpRequestApi Request() | ||
| => new HttpRequestProvider(Original.Property(nameof(HttpMessage.Request))); | ||
|
|
||
| public override HttpResponseApi Response() | ||
| => new AzureResponseProvider(Original.Property(nameof(HttpMessage.Response))); | ||
|
|
||
| public override ValueExpression ResponseClassifier() | ||
| => Original.Property(nameof(HttpMessage.ResponseClassifier)); | ||
|
|
||
| public override HttpMessageApi ToExpression() => this; | ||
| } | ||
| } |
54 changes: 54 additions & 0 deletions
54
...client-csharp/generator/Azure.Generator/src/Providers/Abstraction/HttpPipelineProvider.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using Azure.Core; | ||
| using Azure.Core.Pipeline; | ||
| using Microsoft.Generator.CSharp.ClientModel.Providers; | ||
| using Microsoft.Generator.CSharp.Expressions; | ||
| using Microsoft.Generator.CSharp.Primitives; | ||
| using static Microsoft.Generator.CSharp.Snippets.Snippet; | ||
|
|
||
| namespace Azure.Generator.Providers.Abstraction | ||
| { | ||
| internal record HttpPipelineProvider : ClientPipelineApi | ||
| { | ||
| private static IClientPipelineApi? _instance; | ||
| internal static IClientPipelineApi Instance => _instance ??= new HttpPipelineProvider(); | ||
| private HttpPipelineProvider() : base(typeof(HttpPipeline), Empty) | ||
| { | ||
| } | ||
|
|
||
| public HttpPipelineProvider(ValueExpression original) : base(typeof(HttpPipeline), original) | ||
| { | ||
| } | ||
|
|
||
| public override CSharpType ClientPipelineType => typeof(HttpPipeline); | ||
|
|
||
| public override CSharpType ClientPipelineOptionsType => typeof(ClientOptions); | ||
|
|
||
| public override CSharpType PipelinePolicyType => typeof(HttpPipelinePolicy); | ||
|
|
||
| public override ValueExpression Create(ValueExpression options, ValueExpression perRetryPolicies) | ||
| => Static(typeof(HttpPipelineBuilder)).Invoke(nameof(HttpPipelineBuilder.Build), [options, perRetryPolicies]); | ||
|
|
||
| public override HttpMessageApi CreateMessage() | ||
| => new HttpMessageProvider(Original.Invoke(nameof(HttpPipeline.CreateMessage))); | ||
|
|
||
| public override ValueExpression CreateMessage(HttpRequestOptionsApi requestOptions, ValueExpression responseClassifier) | ||
| => Original.Invoke(nameof(HttpPipeline.CreateMessage), requestOptions, responseClassifier).As<HttpMessage>(); | ||
|
|
||
| public override ClientPipelineApi FromExpression(ValueExpression expression) | ||
| => new HttpPipelineProvider(expression); | ||
|
|
||
| public override ValueExpression PerRetryPolicy(params ValueExpression[] arguments) | ||
| => Empty; // TODO: implement with default retry policy for Azure | ||
|
|
||
| public override InvokeMethodExpression Send(HttpMessageApi message) | ||
| => Original.Invoke(nameof(HttpPipeline.Send), [message, Default]); | ||
|
|
||
| public override InvokeMethodExpression SendAsync(HttpMessageApi message) | ||
| => Original.Invoke(nameof(HttpPipeline.SendAsync), [message, Default], true); | ||
|
|
||
| public override ClientPipelineApi ToExpression() => this; | ||
| } | ||
| } |
36 changes: 36 additions & 0 deletions
36
...-csharp/generator/Azure.Generator/src/Providers/Abstraction/HttpRequestOptionsProvider.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using Microsoft.Generator.CSharp.ClientModel.Providers; | ||
| using Microsoft.Generator.CSharp.Expressions; | ||
| using Microsoft.Generator.CSharp.Primitives; | ||
| using static Microsoft.Generator.CSharp.Snippets.Snippet; | ||
|
|
||
| namespace Azure.Generator.Providers.Abstraction | ||
| { | ||
| internal record HttpRequestOptionsProvider : HttpRequestOptionsApi | ||
| { | ||
| private static IHttpRequestOptionsApi? _instance; | ||
| internal static IHttpRequestOptionsApi Instance => _instance ??= new HttpRequestOptionsProvider(); | ||
| private HttpRequestOptionsProvider() : base(typeof(RequestContext), Empty) | ||
| { | ||
| } | ||
|
|
||
| public HttpRequestOptionsProvider(ValueExpression original) : base(typeof(RequestContext), original) | ||
| { | ||
| } | ||
|
|
||
| public override CSharpType HttpRequestOptionsType => typeof(RequestContext); | ||
|
|
||
| public override ValueExpression ErrorOptions() | ||
| => Original.NullConditional().Property(nameof(RequestContext.ErrorOptions)); | ||
|
|
||
| public override HttpRequestOptionsApi FromExpression(ValueExpression original) | ||
| => new HttpRequestOptionsProvider(original); | ||
|
|
||
| public override ValueExpression NoThrow() | ||
| => FrameworkEnumValue(Azure.ErrorOptions.NoThrow); | ||
|
|
||
| public override HttpRequestOptionsApi ToExpression() => this; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.