Skip to content

Commit aaa5760

Browse files
ellismgchamons
andauthored
[Low Level Client] Spike of a TextAnalytics client (Azure#18746)
* [Core.Experimental] Spike to add `JsonData` As part of the low level client effort, we wanted to experiment with a slightly different API design for our type which represents mutable JSON Data. This spike adds an initial implementation. This is very similar to `DynamicJson` but I decided to create another type because I did not want to impact current uses of `DynamicJson` and we expect that the shape of these APIs will continue to evolve as we do our user studies. There are still some untested methods but we have pretty good coverage (and we'll push to improve it as we lock the design). An initial pass at API documentation was also done, as we want to have some level of documentation for users during our user study. A more in depth pass will be done as we lock the design. * [Core.Experimental] Use `JsonData` in `DynamicRequest` * [Low Level Client] Spike TextAnalytics prototype This code was hand authored, but with an eye towards generating it automatically. The API documentation is pulled verbatim from the REST API documentation, as that's what we expect we would be able to do in an autogenerated fashion. * [Core.Experimental] Use dynamic instead of JsonData in Request/Response * [Core.Experimental] Expose as both JsonData and dynamic * [Low Level Client] Include README.md template * [Core.Experimental] Respond to Krzysztof's Feedback * [Core.Experimental] Remove DynamicJson in favor of JsonData * [Low Level Client] Include README.md template * [Core.Experimental] Update API Listing * [Low Level Client] Implement User Study tasks Co-authored-by: Chris Hamons <chris.hamons@microsoft.com>
1 parent 080dda4 commit aaa5760

24 files changed

+2728
-784
lines changed

eng/Packages.Data.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
<PackageReference Update="System.Text.Json" Version="4.6.0" />
7171
<PackageReference Update="System.ValueTuple" Version="4.5.0" />
7272
<PackageReference Update="Microsoft.Bcl.AsyncInterfaces" Version="1.0.0" />
73+
<PackageReference Update="Microsoft.CSharp" Version="4.5.0" />
7374

7475
<!-- Azure SDK packages -->
7576
<PackageReference Update="Azure.Core" Version="1.9.0" />

sdk/core/Azure.Core.Experimental/api/Azure.Core.Experimental.netstandard2.0.cs

Lines changed: 83 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -4,75 +4,20 @@ namespace Azure.Core
44
public partial class DynamicContent : Azure.Core.RequestContent
55
{
66
internal DynamicContent() { }
7+
public static Azure.Core.RequestContent Create(Azure.Core.JsonData body) { throw null; }
78
public override void Dispose() { }
89
public override bool TryComputeLength(out long length) { throw null; }
910
public override void WriteTo(System.IO.Stream stream, System.Threading.CancellationToken cancellation) { }
1011
public override System.Threading.Tasks.Task WriteToAsync(System.IO.Stream stream, System.Threading.CancellationToken cancellation) { throw null; }
1112
}
12-
public partial class DynamicJson : System.Dynamic.IDynamicMetaObjectProvider
13-
{
14-
public DynamicJson() { }
15-
public DynamicJson(string json) { }
16-
public DynamicJson(System.Text.Json.JsonElement element) { }
17-
public Azure.Core.DynamicJson this[int arrayIndex] { get { throw null; } set { } }
18-
public Azure.Core.DynamicJson this[string propertyName] { get { throw null; } set { } }
19-
public static Azure.Core.DynamicJson Array() { throw null; }
20-
public static Azure.Core.DynamicJson Array(params Azure.Core.DynamicJson[] values) { throw null; }
21-
public static Azure.Core.DynamicJson Array(System.Collections.Generic.IEnumerable<Azure.Core.DynamicJson> values) { throw null; }
22-
public static Azure.Core.DynamicJson Create(System.Text.Json.JsonElement element) { throw null; }
23-
public System.Threading.Tasks.Task<T?> DeserializeAsync<T>(Azure.Core.Serialization.ObjectSerializer serializer, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
24-
public T? Deserialize<T>(Azure.Core.Serialization.ObjectSerializer serializer, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
25-
public T Deserialize<T>(System.Text.Json.JsonSerializerOptions? options = null) { throw null; }
26-
public System.Collections.Generic.IEnumerable<Azure.Core.DynamicJson> EnumerateArray() { throw null; }
27-
public System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, Azure.Core.DynamicJson>> EnumerateObject() { throw null; }
28-
public int GetArrayLength() { throw null; }
29-
public bool GetBoolean() { throw null; }
30-
public double GetDouble() { throw null; }
31-
public float GetFloat() { throw null; }
32-
public int GetIn32() { throw null; }
33-
public long GetLong() { throw null; }
34-
public Azure.Core.DynamicJson GetProperty(string name) { throw null; }
35-
public string? GetString() { throw null; }
36-
public static Azure.Core.DynamicJson Object() { throw null; }
37-
public static Azure.Core.DynamicJson Object(System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, Azure.Core.DynamicJson>> values) { throw null; }
38-
public static explicit operator bool (Azure.Core.DynamicJson json) { throw null; }
39-
public static explicit operator double (Azure.Core.DynamicJson json) { throw null; }
40-
public static explicit operator int (Azure.Core.DynamicJson json) { throw null; }
41-
public static explicit operator long (Azure.Core.DynamicJson json) { throw null; }
42-
public static explicit operator bool? (Azure.Core.DynamicJson json) { throw null; }
43-
public static explicit operator double? (Azure.Core.DynamicJson json) { throw null; }
44-
public static explicit operator int? (Azure.Core.DynamicJson json) { throw null; }
45-
public static explicit operator long? (Azure.Core.DynamicJson json) { throw null; }
46-
public static explicit operator float? (Azure.Core.DynamicJson json) { throw null; }
47-
public static explicit operator float (Azure.Core.DynamicJson json) { throw null; }
48-
public static explicit operator string (Azure.Core.DynamicJson json) { throw null; }
49-
public static implicit operator Azure.Core.DynamicJson (bool value) { throw null; }
50-
public static implicit operator Azure.Core.DynamicJson (double value) { throw null; }
51-
public static implicit operator Azure.Core.DynamicJson (int value) { throw null; }
52-
public static implicit operator Azure.Core.DynamicJson (long value) { throw null; }
53-
public static implicit operator Azure.Core.DynamicJson (bool? value) { throw null; }
54-
public static implicit operator Azure.Core.DynamicJson (double? value) { throw null; }
55-
public static implicit operator Azure.Core.DynamicJson (int? value) { throw null; }
56-
public static implicit operator Azure.Core.DynamicJson (long? value) { throw null; }
57-
public static implicit operator Azure.Core.DynamicJson (float? value) { throw null; }
58-
public static implicit operator Azure.Core.DynamicJson (float value) { throw null; }
59-
public static implicit operator Azure.Core.DynamicJson (string? value) { throw null; }
60-
public static Azure.Core.DynamicJson Parse(string json) { throw null; }
61-
public static System.Threading.Tasks.Task<Azure.Core.DynamicJson> SerializeAsync<T>(T value, Azure.Core.Serialization.ObjectSerializer serializer, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
62-
public static Azure.Core.DynamicJson Serialize<T>(T value, Azure.Core.Serialization.ObjectSerializer serializer, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
63-
public static Azure.Core.DynamicJson Serialize<T>(T value, System.Text.Json.JsonSerializerOptions? options = null) { throw null; }
64-
System.Dynamic.DynamicMetaObject System.Dynamic.IDynamicMetaObjectProvider.GetMetaObject(System.Linq.Expressions.Expression parameter) { throw null; }
65-
public System.Text.Json.JsonElement ToJsonElement() { throw null; }
66-
public override string ToString() { throw null; }
67-
public void WriteTo(System.Text.Json.Utf8JsonWriter writer) { }
68-
}
6913
[System.Diagnostics.DebuggerDisplayAttribute("Body: {Body}")]
7014
public partial class DynamicRequest : Azure.Core.Request
7115
{
7216
public DynamicRequest(Azure.Core.Request request, Azure.Core.Pipeline.HttpPipeline pipeline) { }
73-
public Azure.Core.DynamicJson Body { get { throw null; } set { } }
17+
public Azure.Core.JsonData Body { get { throw null; } set { } }
7418
public override string ClientRequestId { get { throw null; } set { } }
7519
public override Azure.Core.RequestContent? Content { get { throw null; } set { } }
20+
public dynamic DynamicBody { get { throw null; } }
7621
protected override void AddHeader(string name, string value) { }
7722
protected override bool ContainsHeader(string name) { throw null; }
7823
public override void Dispose() { }
@@ -87,10 +32,11 @@ protected virtual void Dispose(bool disposing) { }
8732
[System.Diagnostics.DebuggerDisplayAttribute("Status: {Response.Status}, Value: {Value}")]
8833
public partial class DynamicResponse : Azure.Response
8934
{
90-
public DynamicResponse(Azure.Response response, Azure.Core.DynamicJson? body) { }
91-
public Azure.Core.DynamicJson? Body { get { throw null; } }
35+
public DynamicResponse(Azure.Response response, Azure.Core.JsonData? body) { }
36+
public Azure.Core.JsonData? Body { get { throw null; } }
9237
public override string ClientRequestId { get { throw null; } set { } }
9338
public override System.IO.Stream? ContentStream { get { throw null; } set { } }
39+
public dynamic? DynamicBody { get { throw null; } }
9440
public override string ReasonPhrase { get { throw null; } }
9541
public override int Status { get { throw null; } }
9642
protected override bool ContainsHeader(string name) { throw null; }
@@ -100,6 +46,83 @@ protected virtual void Dispose(bool disposing) { }
10046
protected override bool TryGetHeader(string name, out string? value) { throw null; }
10147
protected override bool TryGetHeaderValues(string name, out System.Collections.Generic.IEnumerable<string>? values) { throw null; }
10248
}
49+
[System.Diagnostics.DebuggerDisplayAttribute("{DebuggerDisplay,nq}")]
50+
public partial class JsonData : System.Dynamic.IDynamicMetaObjectProvider
51+
{
52+
public JsonData() { }
53+
public JsonData(object? value) { }
54+
public JsonData(object? value, System.Text.Json.JsonSerializerOptions options, System.Type? type = null) { }
55+
public JsonData(System.Text.Json.JsonDocument jsonDocument) { }
56+
public Azure.Core.JsonData this[int arrayIndex] { get { throw null; } set { } }
57+
public Azure.Core.JsonData this[string propertyName] { get { throw null; } set { } }
58+
public System.Collections.Generic.IEnumerable<Azure.Core.JsonData> Items { get { throw null; } }
59+
public System.Text.Json.JsonValueKind Kind { get { throw null; } }
60+
public int Length { get { throw null; } }
61+
public System.Collections.Generic.IEnumerable<string> Properties { get { throw null; } }
62+
public void Add(bool value) { }
63+
public void Add(double value) { }
64+
public void Add(int value) { }
65+
public void Add(long value) { }
66+
public Azure.Core.JsonData Add(object? serializable) { throw null; }
67+
public Azure.Core.JsonData Add(object? serializable, System.Text.Json.JsonSerializerOptions options) { throw null; }
68+
public void Add(float value) { }
69+
public void Add(string? value) { }
70+
public Azure.Core.JsonData AddEmptyArray() { throw null; }
71+
public Azure.Core.JsonData AddEmptyObjet() { throw null; }
72+
public Azure.Core.JsonData Add<T>(T[] serializable) { throw null; }
73+
public Azure.Core.JsonData Add<T>(T[] serializable, System.Text.Json.JsonSerializerOptions options) { throw null; }
74+
public static Azure.Core.JsonData EmptyArray() { throw null; }
75+
public static Azure.Core.JsonData EmptyObject() { throw null; }
76+
public static Azure.Core.JsonData FromBytes(byte[] utf8Json) { throw null; }
77+
public static Azure.Core.JsonData FromBytes(System.ReadOnlyMemory<byte> utf8Json) { throw null; }
78+
public static Azure.Core.JsonData FromObject<T>(T value, System.Text.Json.JsonSerializerOptions? options = null) { throw null; }
79+
public static Azure.Core.JsonData FromStream(System.IO.Stream utf8Json) { throw null; }
80+
public static System.Threading.Tasks.Task<Azure.Core.JsonData> FromStreamAsync(System.IO.Stream utf8JsonStream, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
81+
public static Azure.Core.JsonData FromString(string json) { throw null; }
82+
public Azure.Core.JsonData? Get(string propertyName) { throw null; }
83+
public T Get<T>(string propertyName) { throw null; }
84+
public T Get<T>(string propertyName, System.Text.Json.JsonSerializerOptions options) { throw null; }
85+
public static explicit operator bool (Azure.Core.JsonData json) { throw null; }
86+
public static explicit operator double (Azure.Core.JsonData json) { throw null; }
87+
public static explicit operator int (Azure.Core.JsonData json) { throw null; }
88+
public static explicit operator long (Azure.Core.JsonData json) { throw null; }
89+
public static explicit operator bool? (Azure.Core.JsonData json) { throw null; }
90+
public static explicit operator double? (Azure.Core.JsonData json) { throw null; }
91+
public static explicit operator int? (Azure.Core.JsonData json) { throw null; }
92+
public static explicit operator long? (Azure.Core.JsonData json) { throw null; }
93+
public static explicit operator float? (Azure.Core.JsonData json) { throw null; }
94+
public static explicit operator float (Azure.Core.JsonData json) { throw null; }
95+
public static explicit operator string (Azure.Core.JsonData json) { throw null; }
96+
public static implicit operator Azure.Core.JsonData (bool value) { throw null; }
97+
public static implicit operator Azure.Core.JsonData (double value) { throw null; }
98+
public static implicit operator Azure.Core.JsonData (int value) { throw null; }
99+
public static implicit operator Azure.Core.JsonData (long value) { throw null; }
100+
public static implicit operator Azure.Core.JsonData (bool? value) { throw null; }
101+
public static implicit operator Azure.Core.JsonData (double? value) { throw null; }
102+
public static implicit operator Azure.Core.JsonData (int? value) { throw null; }
103+
public static implicit operator Azure.Core.JsonData (long? value) { throw null; }
104+
public static implicit operator Azure.Core.JsonData (float? value) { throw null; }
105+
public static implicit operator Azure.Core.JsonData (float value) { throw null; }
106+
public static implicit operator Azure.Core.JsonData (string? value) { throw null; }
107+
public void Set(string propertyName, bool value) { }
108+
public void Set(string propertyName, double value) { }
109+
public void Set(string propertyName, int value) { }
110+
public void Set(string propertyName, long value) { }
111+
public Azure.Core.JsonData Set(string propertyName, object? serializable) { throw null; }
112+
public Azure.Core.JsonData Set(string propertyName, object? serializable, System.Text.Json.JsonSerializerOptions options) { throw null; }
113+
public void Set(string propertyName, float value) { }
114+
public void Set(string propertyName, string? value) { }
115+
public Azure.Core.JsonData SetEmptyArray(string propertyName) { throw null; }
116+
public Azure.Core.JsonData SetEmptyObject(string propertyName) { throw null; }
117+
public Azure.Core.JsonData Set<T>(string propertyName, T[] serializable) { throw null; }
118+
public Azure.Core.JsonData Set<T>(string propertyName, T[] serializable, System.Text.Json.JsonSerializerOptions options) { throw null; }
119+
System.Dynamic.DynamicMetaObject System.Dynamic.IDynamicMetaObjectProvider.GetMetaObject(System.Linq.Expressions.Expression parameter) { throw null; }
120+
public override string ToString() { throw null; }
121+
public T To<T>() { throw null; }
122+
public T To<T>(System.Text.Json.JsonSerializerOptions options) { throw null; }
123+
public long WriteTo(System.IO.Stream stream) { throw null; }
124+
public System.Threading.Tasks.Task<long> WriteToAsync(System.IO.Stream stream, System.Threading.CancellationToken cancellationToken) { throw null; }
125+
}
103126
public partial class ProtocolClientOptions : Azure.Core.ClientOptions
104127
{
105128
public ProtocolClientOptions() { }

sdk/core/Azure.Core.Experimental/src/Azure.Core.Experimental.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
<ItemGroup>
1313
<PackageReference Include="Azure.Core" />
14+
<PackageReference Include="Microsoft.CSharp" />
1415
</ItemGroup>
1516

1617
<ItemGroup>

sdk/core/Azure.Core.Experimental/src/DynamicContent.cs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,36 @@
1212
namespace Azure.Core
1313
{
1414
/// <summary>
15-
/// Represents the <see cref="DynamicJson"/> sent as part of the Azure.Core.Request.
15+
/// Represents the <see cref="JsonData"/> sent as part of the Azure.Core.Request.
1616
/// </summary>
1717
[DebuggerDisplay("Content: {_body}")]
1818
public class DynamicContent : RequestContent
1919
{
20-
private readonly DynamicJson _body;
20+
private readonly JsonData _body;
2121

22-
internal DynamicContent(DynamicJson body)
22+
internal DynamicContent(JsonData body)
2323
{
2424
_body = body;
2525
}
2626

27-
internal static RequestContent Create(DynamicJson body) => new DynamicContent(body);
27+
// TODO(matell): When this moves to Azure.Core, this static method should be exposed from the abstract RequestContent class.
28+
/// <summary>
29+
/// Creates a RequestConent for a given JSON object.
30+
/// </summary>
31+
/// <param name="body">The JSON object the request content represents</param>
32+
/// <returns>A RequestContent which is the UTF-8 encoding of the underlying DynamicJson</returns>
33+
public static RequestContent Create(JsonData body) => new DynamicContent(body);
2834

2935
/// <inheritdoc />
3036
public override async Task WriteToAsync(Stream stream, CancellationToken cancellation)
3137
{
32-
using Utf8JsonWriter writer = new Utf8JsonWriter(stream);
33-
_body.WriteTo(writer);
34-
await writer.FlushAsync(cancellation).ConfigureAwait(false);
38+
await _body.WriteToAsync(stream, cancellation).ConfigureAwait(false);
3539
}
3640

3741
/// <inheritdoc />
3842
public override void WriteTo(Stream stream, CancellationToken cancellation)
3943
{
40-
using Utf8JsonWriter writer = new Utf8JsonWriter(stream);
41-
_body.WriteTo(writer);
42-
writer.Flush();
44+
_body.WriteTo(stream);
4345
}
4446

4547
/// <inheritdoc />

0 commit comments

Comments
 (0)