-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(dpg): duplicated result retrieval methods when polling operation …
…is referenced multiple times (#5116) - when writing result retrieval methods, avoid duplicated instances - add test case which should be added into cadl-ranch later fix #5113
- Loading branch information
Showing
12 changed files
with
2,264 additions
and
545 deletions.
There are no files selected for viewing
This file contains 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 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
113 changes: 113 additions & 0 deletions
113
test/TestProjects/FirstTest-TypeSpec/src/Generated/Docs/VersioningOp.xml
This file contains 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,113 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<doc> | ||
<members> | ||
<member name="ExportAsync(WaitUntil,string,string,RequestContext)"> | ||
<example> | ||
This sample shows how to call ExportAsync and parse the result. | ||
<code><![CDATA[ | ||
Uri endpoint = new Uri("<https://my-service.azure.com>"); | ||
VersioningOp client = new FirstTestTypeSpecClient(endpoint).GetVersioningOpClient(apiVersion: "2022-05-15-preview"); | ||
Operation<BinaryData> operation = await client.ExportAsync(WaitUntil.Completed, "<name>", null, null); | ||
BinaryData responseData = operation.Value; | ||
JsonElement result = JsonDocument.Parse(responseData.ToStream()).RootElement; | ||
Console.WriteLine(result.GetProperty("id").ToString()); | ||
Console.WriteLine(result.GetProperty("name").ToString()); | ||
]]></code> | ||
This sample shows how to call ExportAsync with all parameters and parse the result. | ||
<code><![CDATA[ | ||
Uri endpoint = new Uri("<https://my-service.azure.com>"); | ||
VersioningOp client = new FirstTestTypeSpecClient(endpoint).GetVersioningOpClient(apiVersion: "2022-05-15-preview"); | ||
Operation<BinaryData> operation = await client.ExportAsync(WaitUntil.Completed, "<name>", "<projectFileVersion>", null); | ||
BinaryData responseData = operation.Value; | ||
JsonElement result = JsonDocument.Parse(responseData.ToStream()).RootElement; | ||
Console.WriteLine(result.GetProperty("id").ToString()); | ||
Console.WriteLine(result.GetProperty("name").ToString()); | ||
]]></code></example> | ||
</member> | ||
<member name="Export(WaitUntil,string,string,RequestContext)"> | ||
<example> | ||
This sample shows how to call Export and parse the result. | ||
<code><![CDATA[ | ||
Uri endpoint = new Uri("<https://my-service.azure.com>"); | ||
VersioningOp client = new FirstTestTypeSpecClient(endpoint).GetVersioningOpClient(apiVersion: "2022-05-15-preview"); | ||
Operation<BinaryData> operation = client.Export(WaitUntil.Completed, "<name>", null, null); | ||
BinaryData responseData = operation.Value; | ||
JsonElement result = JsonDocument.Parse(responseData.ToStream()).RootElement; | ||
Console.WriteLine(result.GetProperty("id").ToString()); | ||
Console.WriteLine(result.GetProperty("name").ToString()); | ||
]]></code> | ||
This sample shows how to call Export with all parameters and parse the result. | ||
<code><![CDATA[ | ||
Uri endpoint = new Uri("<https://my-service.azure.com>"); | ||
VersioningOp client = new FirstTestTypeSpecClient(endpoint).GetVersioningOpClient(apiVersion: "2022-05-15-preview"); | ||
Operation<BinaryData> operation = client.Export(WaitUntil.Completed, "<name>", "<projectFileVersion>", null); | ||
BinaryData responseData = operation.Value; | ||
JsonElement result = JsonDocument.Parse(responseData.ToStream()).RootElement; | ||
Console.WriteLine(result.GetProperty("id").ToString()); | ||
Console.WriteLine(result.GetProperty("name").ToString()); | ||
]]></code></example> | ||
</member> | ||
<member name="ExportWAsync(WaitUntil,string,string,RequestContext)"> | ||
<example> | ||
This sample shows how to call ExportWAsync and parse the result. | ||
<code><![CDATA[ | ||
Uri endpoint = new Uri("<https://my-service.azure.com>"); | ||
VersioningOp client = new FirstTestTypeSpecClient(endpoint).GetVersioningOpClient(apiVersion: "2022-05-15-preview"); | ||
Operation<BinaryData> operation = await client.ExportWAsync(WaitUntil.Completed, "<name>", null, null); | ||
BinaryData responseData = operation.Value; | ||
JsonElement result = JsonDocument.Parse(responseData.ToStream()).RootElement; | ||
Console.WriteLine(result.GetProperty("id").ToString()); | ||
Console.WriteLine(result.GetProperty("name").ToString()); | ||
]]></code> | ||
This sample shows how to call ExportWAsync with all parameters and parse the result. | ||
<code><![CDATA[ | ||
Uri endpoint = new Uri("<https://my-service.azure.com>"); | ||
VersioningOp client = new FirstTestTypeSpecClient(endpoint).GetVersioningOpClient(apiVersion: "2022-05-15-preview"); | ||
Operation<BinaryData> operation = await client.ExportWAsync(WaitUntil.Completed, "<name>", "<projectFileVersion>", null); | ||
BinaryData responseData = operation.Value; | ||
JsonElement result = JsonDocument.Parse(responseData.ToStream()).RootElement; | ||
Console.WriteLine(result.GetProperty("id").ToString()); | ||
Console.WriteLine(result.GetProperty("name").ToString()); | ||
]]></code></example> | ||
</member> | ||
<member name="ExportW(WaitUntil,string,string,RequestContext)"> | ||
<example> | ||
This sample shows how to call ExportW and parse the result. | ||
<code><![CDATA[ | ||
Uri endpoint = new Uri("<https://my-service.azure.com>"); | ||
VersioningOp client = new FirstTestTypeSpecClient(endpoint).GetVersioningOpClient(apiVersion: "2022-05-15-preview"); | ||
Operation<BinaryData> operation = client.ExportW(WaitUntil.Completed, "<name>", null, null); | ||
BinaryData responseData = operation.Value; | ||
JsonElement result = JsonDocument.Parse(responseData.ToStream()).RootElement; | ||
Console.WriteLine(result.GetProperty("id").ToString()); | ||
Console.WriteLine(result.GetProperty("name").ToString()); | ||
]]></code> | ||
This sample shows how to call ExportW with all parameters and parse the result. | ||
<code><![CDATA[ | ||
Uri endpoint = new Uri("<https://my-service.azure.com>"); | ||
VersioningOp client = new FirstTestTypeSpecClient(endpoint).GetVersioningOpClient(apiVersion: "2022-05-15-preview"); | ||
Operation<BinaryData> operation = client.ExportW(WaitUntil.Completed, "<name>", "<projectFileVersion>", null); | ||
BinaryData responseData = operation.Value; | ||
JsonElement result = JsonDocument.Parse(responseData.ToStream()).RootElement; | ||
Console.WriteLine(result.GetProperty("id").ToString()); | ||
Console.WriteLine(result.GetProperty("name").ToString()); | ||
]]></code></example> | ||
</member> | ||
</members> | ||
</doc> |
17 changes: 17 additions & 0 deletions
17
test/TestProjects/FirstTest-TypeSpec/src/Generated/FirstTestTypeSpecClient.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
test/TestProjects/FirstTest-TypeSpec/src/Generated/FirstTestTypeSpecModelFactory.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
144 changes: 144 additions & 0 deletions
144
test/TestProjects/FirstTest-TypeSpec/src/Generated/Models/ExportedResource.Serialization.cs
This file contains 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,144 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
// <auto-generated/> | ||
|
||
#nullable disable | ||
|
||
using System; | ||
using System.ClientModel.Primitives; | ||
using System.Collections.Generic; | ||
using System.Text.Json; | ||
using Azure; | ||
using Azure.Core; | ||
|
||
namespace FirstTestTypeSpec.Models | ||
{ | ||
internal partial class ExportedResource : IUtf8JsonSerializable, IJsonModel<ExportedResource> | ||
{ | ||
void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel<ExportedResource>)this).Write(writer, ModelSerializationExtensions.WireOptions); | ||
|
||
void IJsonModel<ExportedResource>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) | ||
{ | ||
var format = options.Format == "W" ? ((IPersistableModel<ExportedResource>)this).GetFormatFromOptions(options) : options.Format; | ||
if (format != "J") | ||
{ | ||
throw new FormatException($"The model {nameof(ExportedResource)} does not support writing '{format}' format."); | ||
} | ||
|
||
writer.WriteStartObject(); | ||
writer.WritePropertyName("id"u8); | ||
writer.WriteStringValue(Id); | ||
writer.WritePropertyName("name"u8); | ||
writer.WriteStringValue(Name); | ||
if (options.Format != "W" && _serializedAdditionalRawData != null) | ||
{ | ||
foreach (var item in _serializedAdditionalRawData) | ||
{ | ||
writer.WritePropertyName(item.Key); | ||
#if NET6_0_OR_GREATER | ||
writer.WriteRawValue(item.Value); | ||
#else | ||
using (JsonDocument document = JsonDocument.Parse(item.Value)) | ||
{ | ||
JsonSerializer.Serialize(writer, document.RootElement); | ||
} | ||
#endif | ||
} | ||
} | ||
writer.WriteEndObject(); | ||
} | ||
|
||
ExportedResource IJsonModel<ExportedResource>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) | ||
{ | ||
var format = options.Format == "W" ? ((IPersistableModel<ExportedResource>)this).GetFormatFromOptions(options) : options.Format; | ||
if (format != "J") | ||
{ | ||
throw new FormatException($"The model {nameof(ExportedResource)} does not support reading '{format}' format."); | ||
} | ||
|
||
using JsonDocument document = JsonDocument.ParseValue(ref reader); | ||
return DeserializeExportedResource(document.RootElement, options); | ||
} | ||
|
||
internal static ExportedResource DeserializeExportedResource(JsonElement element, ModelReaderWriterOptions options = null) | ||
{ | ||
options ??= ModelSerializationExtensions.WireOptions; | ||
|
||
if (element.ValueKind == JsonValueKind.Null) | ||
{ | ||
return null; | ||
} | ||
string id = default; | ||
string name = default; | ||
IDictionary<string, BinaryData> serializedAdditionalRawData = default; | ||
Dictionary<string, BinaryData> rawDataDictionary = new Dictionary<string, BinaryData>(); | ||
foreach (var property in element.EnumerateObject()) | ||
{ | ||
if (property.NameEquals("id"u8)) | ||
{ | ||
id = property.Value.GetString(); | ||
continue; | ||
} | ||
if (property.NameEquals("name"u8)) | ||
{ | ||
name = property.Value.GetString(); | ||
continue; | ||
} | ||
if (options.Format != "W") | ||
{ | ||
rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); | ||
} | ||
} | ||
serializedAdditionalRawData = rawDataDictionary; | ||
return new ExportedResource(id, name, serializedAdditionalRawData); | ||
} | ||
|
||
BinaryData IPersistableModel<ExportedResource>.Write(ModelReaderWriterOptions options) | ||
{ | ||
var format = options.Format == "W" ? ((IPersistableModel<ExportedResource>)this).GetFormatFromOptions(options) : options.Format; | ||
|
||
switch (format) | ||
{ | ||
case "J": | ||
return ModelReaderWriter.Write(this, options); | ||
default: | ||
throw new FormatException($"The model {nameof(ExportedResource)} does not support writing '{options.Format}' format."); | ||
} | ||
} | ||
|
||
ExportedResource IPersistableModel<ExportedResource>.Create(BinaryData data, ModelReaderWriterOptions options) | ||
{ | ||
var format = options.Format == "W" ? ((IPersistableModel<ExportedResource>)this).GetFormatFromOptions(options) : options.Format; | ||
|
||
switch (format) | ||
{ | ||
case "J": | ||
{ | ||
using JsonDocument document = JsonDocument.Parse(data); | ||
return DeserializeExportedResource(document.RootElement, options); | ||
} | ||
default: | ||
throw new FormatException($"The model {nameof(ExportedResource)} does not support reading '{options.Format}' format."); | ||
} | ||
} | ||
|
||
string IPersistableModel<ExportedResource>.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; | ||
|
||
/// <summary> Deserializes the model from a raw response. </summary> | ||
/// <param name="response"> The response to deserialize the model from. </param> | ||
internal static ExportedResource FromResponse(Response response) | ||
{ | ||
using var document = JsonDocument.Parse(response.Content); | ||
return DeserializeExportedResource(document.RootElement); | ||
} | ||
|
||
/// <summary> Convert into a <see cref="RequestContent"/>. </summary> | ||
internal virtual RequestContent ToRequestContent() | ||
{ | ||
var content = new Utf8JsonRequestContent(); | ||
content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); | ||
return content; | ||
} | ||
} | ||
} |
Oops, something went wrong.