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

Response abstraction #4438

Merged
merged 45 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
40ecf45
init
live1206 Sep 13, 2024
7da2225
Merge branch 'main' into response-abstraction
live1206 Sep 13, 2024
d170d95
cleanup
live1206 Sep 13, 2024
88a4620
clean up
live1206 Sep 13, 2024
0c8c172
Merge branch 'main' into response-abstraction
live1206 Sep 14, 2024
634c06a
wip
live1206 Sep 18, 2024
5bbcd8a
update FromValue expression
live1206 Sep 18, 2024
93932af
rename
live1206 Sep 19, 2024
f1a9a3d
restructure
live1206 Sep 19, 2024
1169baf
revert type change
live1206 Sep 19, 2024
9752376
Merge branch 'main' into response-abstraction
live1206 Sep 19, 2024
f062d77
make static methods abstract
live1206 Sep 23, 2024
d1889c2
Merge branch 'response-abstraction' of https://github.com/live1206/ty…
live1206 Sep 23, 2024
9eb3b66
update Type to CSharpType
live1206 Sep 23, 2024
56e0f8a
make ErrorResultDefinition public
live1206 Sep 25, 2024
8f6e642
update
live1206 Sep 26, 2024
47a6427
Merge branch 'main' into response-abstraction
live1206 Sep 26, 2024
4a94206
Add more abstraction to make Azure plugin work
live1206 Sep 30, 2024
37295c0
regen tests
live1206 Sep 30, 2024
49ee47d
Merge branch 'main' into response-abstraction
live1206 Sep 30, 2024
eb32597
fix typo
live1206 Sep 30, 2024
c29e8c0
update
live1206 Sep 30, 2024
eb98948
Merge branch 'main' into response-abstraction
live1206 Oct 8, 2024
fcf7ee5
add interfaces
live1206 Oct 9, 2024
109e93e
revert changes for serialization
live1206 Oct 9, 2024
f8c7bbb
revert test change
live1206 Oct 9, 2024
b0d4fca
Merge branch 'main' into response-abstraction
live1206 Oct 9, 2024
a038db4
fix
live1206 Oct 9, 2024
f83dd0b
cleanup
live1206 Oct 9, 2024
a5a379f
make test pass
live1206 Oct 9, 2024
aa27a8d
Merge branch 'main' into response-abstraction
live1206 Oct 10, 2024
100328f
minor
live1206 Oct 10, 2024
14f87d0
Merge branch 'main' into response-abstraction
live1206 Oct 10, 2024
48449f4
Merge branch 'main' into response-abstraction
live1206 Oct 11, 2024
456f13a
resolve comments
live1206 Oct 11, 2024
71bf272
Merge branch 'main' into response-abstraction
live1206 Oct 11, 2024
0cfe54f
Add IExpressionApi<T>
live1206 Oct 14, 2024
1189b18
add constraint
live1206 Oct 14, 2024
cb6c50e
Add ParameterName to IHttpRequestOptionsApi
live1206 Oct 16, 2024
486104c
Add tests for abstraction and simplify the implementation
live1206 Oct 17, 2024
aba79be
Merge branch 'main' into response-abstraction
live1206 Oct 17, 2024
c8a8735
fix typo
live1206 Oct 17, 2024
e3c067a
more typo
live1206 Oct 17, 2024
55637ee
fix typo in test data file name
live1206 Oct 17, 2024
5f192fb
Merge branch 'main' into response-abstraction
live1206 Oct 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the MIT License.

using System;
using System.ClientModel;
using System.ClientModel.Primitives;
using System.Text.Json;
using System.Xml;
Expand Down Expand Up @@ -32,8 +31,8 @@ public static ParameterProvider ClientOptions(CSharpType clientOptionsType)
=> new("options", $"The options for configuring the client.", clientOptionsType.WithNullable(true), initializationValue: New.Instance(clientOptionsType.WithNullable(true)));
public static readonly ParameterProvider KeyAuth = new("keyCredential", $"The token credential to copy", ClientModelPlugin.Instance.TypeFactory.KeyCredentialType);
public static readonly ParameterProvider MatchConditionsParameter = new("matchConditions", $"The content to send as the request conditions of the request.", ClientModelPlugin.Instance.TypeFactory.MatchConditionsType, DefaultOf(ClientModelPlugin.Instance.TypeFactory.MatchConditionsType));
public static readonly ParameterProvider RequestOptions = new("options", $"The request options, which can override default behaviors of the client pipeline on a per-call basis.", typeof(RequestOptions));
public static readonly ParameterProvider BinaryContent = new("content", $"The content to send as the body of the request.", typeof(BinaryContent), location: ParameterLocation.Body) { Validation = ParameterValidationType.AssertNotNull };
public static readonly ParameterProvider RequestOptions = new("options", $"The request options, which can override default behaviors of the client pipeline on a per-call basis.", ClientModelPlugin.Instance.TypeFactory.HttpRequestOptionsApi.HttpRequestOptionsType);
public static readonly ParameterProvider RequestContent = new("content", $"The content to send as the body of the request.", ClientModelPlugin.Instance.TypeFactory.RequestContentApi.RequestContentType, location: ParameterLocation.Body) { Validation = ParameterValidationType.AssertNotNull };

// Known header parameters
public static readonly ParameterProvider RepeatabilityRequestId = new("repeatabilityRequestId", FormattableStringHelpers.Empty, typeof(Guid))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using Microsoft.Generator.CSharp.Expressions;
using Microsoft.Generator.CSharp.Primitives;
using Microsoft.Generator.CSharp.Snippets;

namespace Microsoft.Generator.CSharp.ClientModel.Providers
{
public abstract record ClientPipelineApi : ScopedApi, IClientPipelineApi
{
public abstract CSharpType ClientPipelineType { get; }
public abstract CSharpType ClientPipelineOptionsType { get; }
public abstract CSharpType PipelinePolicyType { get; }

protected ClientPipelineApi(Type type, ValueExpression original) : base(type, original)
{
}

public abstract HttpMessageApi CreateMessage();

public abstract ValueExpression CreateMessage(HttpRequestOptionsApi requestOptions, ValueExpression responseClassifier);

public abstract InvokeMethodExpression Send(HttpMessageApi message);

public abstract InvokeMethodExpression SendAsync(HttpMessageApi message);

public abstract ValueExpression Create(ValueExpression options, ValueExpression perRetryPolicies);

public abstract ValueExpression PerRetryPolicy(params ValueExpression[] arguments);
public abstract ClientPipelineApi FromExpression(ValueExpression expression);
public abstract ClientPipelineApi ToExpression();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using Microsoft.Generator.CSharp.Expressions;
using Microsoft.Generator.CSharp.Primitives;
using Microsoft.Generator.CSharp.Snippets;

namespace Microsoft.Generator.CSharp.ClientModel.Providers
{
public abstract record ClientResponseApi : ScopedApi, IClientResponseApi
{
protected ClientResponseApi(Type type, ValueExpression original) : base(type, original)
{
}

public abstract HttpResponseApi GetRawResponse();

public abstract ValueExpression FromValue(ValueExpression valueExpression, HttpResponseApi response);

public abstract ValueExpression FromValue<ValueType>(ValueExpression valueExpression, HttpResponseApi response);

public abstract ValueExpression FromResponse(ValueExpression valueExpression);

public abstract ValueExpression CreateAsync(HttpResponseApi response);

public abstract ClientResponseApi FromExpression(ValueExpression original);

public abstract ClientResponseApi ToExpression();

public abstract CSharpType ClientResponseType { get; }

public abstract CSharpType ClientResponseOfTType { get; }

public abstract CSharpType ClientResponseExceptionType { get; }
}
}
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 System;
using Microsoft.Generator.CSharp.Expressions;
using Microsoft.Generator.CSharp.Primitives;
using Microsoft.Generator.CSharp.Snippets;
using Microsoft.Generator.CSharp.Statements;

namespace Microsoft.Generator.CSharp.ClientModel.Providers
{
public abstract record HttpMessageApi : ScopedApi, IHttpMessageApi
{
protected HttpMessageApi(Type type, ValueExpression original) : base(type, original)
{
}

public abstract HttpRequestApi Request();
live1206 marked this conversation as resolved.
Show resolved Hide resolved

public abstract HttpResponseApi Response();

public abstract ValueExpression BufferResponse();

public abstract ValueExpression ResponseClassifier();

public abstract MethodBodyStatement Apply(ValueExpression options);

public abstract MethodBodyStatement[] ExtractResponse();

public abstract HttpMessageApi FromExpression(ValueExpression original);

public abstract HttpMessageApi ToExpression();

public abstract CSharpType HttpMessageType { get; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Collections.Generic;
using Microsoft.Generator.CSharp.Expressions;
using Microsoft.Generator.CSharp.Primitives;
using Microsoft.Generator.CSharp.Snippets;

namespace Microsoft.Generator.CSharp.ClientModel.Providers
{
public abstract record HttpRequestApi : ScopedApi, IHttpRequestApi
{
protected HttpRequestApi(CSharpType type, ValueExpression original) : base(type, original)
{
}

public abstract AssignmentExpression SetMethod(string httpMethod);

public abstract AssignmentExpression SetUri(ValueExpression uri);

public abstract InvokeMethodExpression SetHeaders(IReadOnlyList<ValueExpression> arguments);

public abstract ValueExpression Content();
public abstract HttpRequestApi FromExpression(ValueExpression original);
public abstract HttpRequestApi ToExpression();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Microsoft.Generator.CSharp.Expressions;
using Microsoft.Generator.CSharp.Primitives;
using Microsoft.Generator.CSharp.Snippets;

namespace Microsoft.Generator.CSharp.ClientModel.Providers
{
public abstract record HttpRequestOptionsApi : ScopedApi, IHttpRequestOptionsApi
{
public HttpRequestOptionsApi(CSharpType type, ValueExpression original) : base(type, original)
{
}

public abstract ValueExpression ErrorOptions();

public abstract HttpRequestOptionsApi FromExpression(ValueExpression original);

public abstract ValueExpression NoThrow();

public abstract HttpRequestOptionsApi ToExpression();

public abstract CSharpType HttpRequestOptionsType { get; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.IO;
using Microsoft.Generator.CSharp.Expressions;
using Microsoft.Generator.CSharp.Primitives;
using Microsoft.Generator.CSharp.Snippets;

namespace Microsoft.Generator.CSharp.ClientModel.Providers
{
public abstract record HttpResponseApi : ScopedApi, IHttpResponseApi
{
protected HttpResponseApi(Type type, ValueExpression original) : base(type, original)
{
}

public abstract ScopedApi<Stream> ContentStream();

public abstract ScopedApi<BinaryData> Content();

public abstract ScopedApi<bool> IsError();

public abstract CSharpType HttpResponseType { get; }

public abstract HttpResponseApi FromExpression(ValueExpression original);

public abstract HttpResponseApi ToExpression();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Microsoft.Generator.CSharp.Expressions;
using Microsoft.Generator.CSharp.Primitives;

namespace Microsoft.Generator.CSharp.ClientModel.Providers
{
public interface IClientPipelineApi
{
CSharpType ClientPipelineType { get; }
CSharpType ClientPipelineOptionsType { get; }
CSharpType PipelinePolicyType { get; }
ClientPipelineApi FromExpression(ValueExpression expression);
ClientPipelineApi ToExpression();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Microsoft.Generator.CSharp.Expressions;
using Microsoft.Generator.CSharp.Primitives;

namespace Microsoft.Generator.CSharp.ClientModel.Providers
{
public interface IClientResponseApi
{
CSharpType ClientResponseExceptionType { get; }

CSharpType ClientResponseType { get; }

CSharpType ClientResponseOfTType { get; }

ClientResponseApi FromExpression(ValueExpression original);

ClientResponseApi ToExpression();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Microsoft.Generator.CSharp.Expressions;
using Microsoft.Generator.CSharp.Primitives;

namespace Microsoft.Generator.CSharp.ClientModel.Providers
{
public interface IHttpMessageApi
{
CSharpType HttpMessageType { get; }
HttpMessageApi FromExpression(ValueExpression original);
HttpMessageApi ToExpression();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Microsoft.Generator.CSharp.Expressions;

namespace Microsoft.Generator.CSharp.ClientModel.Providers
{
public interface IHttpRequestApi
{
HttpRequestApi FromExpression(ValueExpression original);
HttpRequestApi ToExpression();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Microsoft.Generator.CSharp.Expressions;
using Microsoft.Generator.CSharp.Primitives;

namespace Microsoft.Generator.CSharp.ClientModel.Providers
{
public interface IHttpRequestOptionsApi
{
CSharpType HttpRequestOptionsType { get; }
live1206 marked this conversation as resolved.
Show resolved Hide resolved
HttpRequestOptionsApi FromExpression(ValueExpression original);
HttpRequestOptionsApi ToExpression();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Microsoft.Generator.CSharp.Expressions;
using Microsoft.Generator.CSharp.Primitives;

namespace Microsoft.Generator.CSharp.ClientModel.Providers
{
public interface IHttpResponseApi
{
CSharpType HttpResponseType { get; }

HttpResponseApi FromExpression(ValueExpression original);

HttpResponseApi ToExpression();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Microsoft.Generator.CSharp.Expressions;
using Microsoft.Generator.CSharp.Primitives;

namespace Microsoft.Generator.CSharp.ClientModel.Providers
{
public interface IRequestContentApi
{
CSharpType RequestContentType { get; }
RequestContentApi FromExpression(ValueExpression original);
live1206 marked this conversation as resolved.
Show resolved Hide resolved
RequestContentApi ToExpression();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Microsoft.Generator.CSharp.Expressions;
using Microsoft.Generator.CSharp.Primitives;

namespace Microsoft.Generator.CSharp.ClientModel.Providers
{
public interface IStatusCodeClassifierApi
{
CSharpType ResponseClassifierType { get; }
StatusCodeClassifierApi FromExpression(ValueExpression original);
StatusCodeClassifierApi ToExpression();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using Microsoft.Generator.CSharp.Expressions;
using Microsoft.Generator.CSharp.Primitives;
using Microsoft.Generator.CSharp.Snippets;
using Microsoft.Generator.CSharp.Statements;

namespace Microsoft.Generator.CSharp.ClientModel.Providers
{
public abstract record RequestContentApi : ScopedApi, IRequestContentApi
{
protected RequestContentApi(Type type, ValueExpression original) : base(type, original)
{
}

public abstract CSharpType RequestContentType { get; }

public abstract RequestContentApi FromExpression(ValueExpression original);
public abstract RequestContentApi ToExpression();
public abstract MethodBodyStatement[] Create(ValueExpression argument);
}
}
Loading
Loading