From d154983c30434b5117028031ef995260bd09afb9 Mon Sep 17 00:00:00 2001 From: Wenming Liu Date: Wed, 25 Sep 2024 16:34:05 +0800 Subject: [PATCH] Enable-WriteCore-feature-for-resourcegraph (#46251) --- .../CHANGELOG.md | 1 + ...rceManager.ResourceGraph.netstandard2.0.cs | 12 +++++++ .../assets.json | 2 +- .../Models/DateTimeInterval.Serialization.cs | 11 +++++-- .../Generated/Models/Facet.Serialization.cs | 11 +++++-- .../Models/FacetError.Serialization.cs | 31 ++++++------------- .../Models/FacetErrorDetails.Serialization.cs | 11 +++++-- .../Models/FacetRequest.Serialization.cs | 11 +++++-- .../FacetRequestOptions.Serialization.cs | 11 +++++-- .../Models/FacetResult.Serialization.cs | 31 ++++++------------- .../ResourceQueryContent.Serialization.cs | 11 +++++-- ...sourceQueryRequestOptions.Serialization.cs | 11 +++++-- .../ResourceQueryResult.Serialization.cs | 11 +++++-- .../ResourcesHistoryContent.Serialization.cs | 11 +++++-- ...rcesHistoryRequestOptions.Serialization.cs | 11 +++++-- .../Models/UnknownFacet.Serialization.cs | 31 ++++++------------- .../src/autorest.md | 1 + 17 files changed, 135 insertions(+), 84 deletions(-) diff --git a/sdk/resourcegraph/Azure.ResourceManager.ResourceGraph/CHANGELOG.md b/sdk/resourcegraph/Azure.ResourceManager.ResourceGraph/CHANGELOG.md index 1e6d2ed080128..e420a7db014df 100644 --- a/sdk/resourcegraph/Azure.ResourceManager.ResourceGraph/CHANGELOG.md +++ b/sdk/resourcegraph/Azure.ResourceManager.ResourceGraph/CHANGELOG.md @@ -5,6 +5,7 @@ ### Features Added - Enable the new model serialization by using the System.ClientModel, refer this [document](https://aka.ms/azsdk/net/mrw) for more details. +- Exposed `JsonModelWriteCore` for model serialization procedure. ### Breaking Changes diff --git a/sdk/resourcegraph/Azure.ResourceManager.ResourceGraph/api/Azure.ResourceManager.ResourceGraph.netstandard2.0.cs b/sdk/resourcegraph/Azure.ResourceManager.ResourceGraph/api/Azure.ResourceManager.ResourceGraph.netstandard2.0.cs index 64ac7ec1ce0ad..a134014cfee5c 100644 --- a/sdk/resourcegraph/Azure.ResourceManager.ResourceGraph/api/Azure.ResourceManager.ResourceGraph.netstandard2.0.cs +++ b/sdk/resourcegraph/Azure.ResourceManager.ResourceGraph/api/Azure.ResourceManager.ResourceGraph.netstandard2.0.cs @@ -43,6 +43,7 @@ public partial class DateTimeInterval : System.ClientModel.Primitives.IJsonModel public DateTimeInterval(System.DateTimeOffset startOn, System.DateTimeOffset endOn) { } public System.DateTimeOffset EndOn { get { throw null; } } public System.DateTimeOffset StartOn { get { throw null; } } + protected virtual void JsonModelWriteCore(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } Azure.ResourceManager.ResourceGraph.Models.DateTimeInterval System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } Azure.ResourceManager.ResourceGraph.Models.DateTimeInterval System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } @@ -53,6 +54,7 @@ public abstract partial class Facet : System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } Azure.ResourceManager.ResourceGraph.Models.Facet System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } @@ -63,6 +65,7 @@ public partial class FacetError : Azure.ResourceManager.ResourceGraph.Models.Fac { internal FacetError() : base (default(string)) { } public System.Collections.Generic.IReadOnlyList Errors { get { throw null; } } + protected override void JsonModelWriteCore(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } Azure.ResourceManager.ResourceGraph.Models.FacetError System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } Azure.ResourceManager.ResourceGraph.Models.FacetError System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } @@ -75,6 +78,7 @@ internal FacetErrorDetails() { } public System.Collections.Generic.IReadOnlyDictionary AdditionalProperties { get { throw null; } } public string Code { get { throw null; } } public string Message { get { throw null; } } + protected virtual void JsonModelWriteCore(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } Azure.ResourceManager.ResourceGraph.Models.FacetErrorDetails System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } Azure.ResourceManager.ResourceGraph.Models.FacetErrorDetails System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } @@ -86,6 +90,7 @@ public partial class FacetRequest : System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } Azure.ResourceManager.ResourceGraph.Models.FacetRequest System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } @@ -99,6 +104,7 @@ public FacetRequestOptions() { } public string SortBy { get { throw null; } set { } } public Azure.ResourceManager.ResourceGraph.Models.FacetSortOrder? SortOrder { get { throw null; } set { } } public int? Top { get { throw null; } set { } } + protected virtual void JsonModelWriteCore(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } Azure.ResourceManager.ResourceGraph.Models.FacetRequestOptions System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } Azure.ResourceManager.ResourceGraph.Models.FacetRequestOptions System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } @@ -111,6 +117,7 @@ internal FacetResult() : base (default(string)) { } public int Count { get { throw null; } } public System.BinaryData Data { get { throw null; } } public long TotalRecords { get { throw null; } } + protected override void JsonModelWriteCore(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } Azure.ResourceManager.ResourceGraph.Models.FacetResult System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } Azure.ResourceManager.ResourceGraph.Models.FacetResult System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } @@ -130,6 +137,7 @@ public ResourceQueryContent(string query) { } public Azure.ResourceManager.ResourceGraph.Models.ResourceQueryRequestOptions Options { get { throw null; } set { } } public string Query { get { throw null; } } public System.Collections.Generic.IList Subscriptions { get { throw null; } } + protected virtual void JsonModelWriteCore(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } Azure.ResourceManager.ResourceGraph.Models.ResourceQueryContent System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } Azure.ResourceManager.ResourceGraph.Models.ResourceQueryContent System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } @@ -145,6 +153,7 @@ public ResourceQueryRequestOptions() { } public int? Skip { get { throw null; } set { } } public string SkipToken { get { throw null; } set { } } public int? Top { get { throw null; } set { } } + protected virtual void JsonModelWriteCore(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } Azure.ResourceManager.ResourceGraph.Models.ResourceQueryRequestOptions System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } Azure.ResourceManager.ResourceGraph.Models.ResourceQueryRequestOptions System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } @@ -160,6 +169,7 @@ internal ResourceQueryResult() { } public Azure.ResourceManager.ResourceGraph.Models.ResultTruncated ResultTruncated { get { throw null; } } public string SkipToken { get { throw null; } } public long TotalRecords { get { throw null; } } + protected virtual void JsonModelWriteCore(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } Azure.ResourceManager.ResourceGraph.Models.ResourceQueryResult System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } Azure.ResourceManager.ResourceGraph.Models.ResourceQueryResult System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } @@ -173,6 +183,7 @@ public ResourcesHistoryContent() { } public Azure.ResourceManager.ResourceGraph.Models.ResourcesHistoryRequestOptions Options { get { throw null; } set { } } public string Query { get { throw null; } set { } } public System.Collections.Generic.IList Subscriptions { get { throw null; } } + protected virtual void JsonModelWriteCore(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } Azure.ResourceManager.ResourceGraph.Models.ResourcesHistoryContent System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } Azure.ResourceManager.ResourceGraph.Models.ResourcesHistoryContent System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } @@ -187,6 +198,7 @@ public ResourcesHistoryRequestOptions() { } public int? Skip { get { throw null; } set { } } public string SkipToken { get { throw null; } set { } } public int? Top { get { throw null; } set { } } + protected virtual void JsonModelWriteCore(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } Azure.ResourceManager.ResourceGraph.Models.ResourcesHistoryRequestOptions System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } Azure.ResourceManager.ResourceGraph.Models.ResourcesHistoryRequestOptions System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } diff --git a/sdk/resourcegraph/Azure.ResourceManager.ResourceGraph/assets.json b/sdk/resourcegraph/Azure.ResourceManager.ResourceGraph/assets.json index 9d3bd032128a4..332f3550432b6 100644 --- a/sdk/resourcegraph/Azure.ResourceManager.ResourceGraph/assets.json +++ b/sdk/resourcegraph/Azure.ResourceManager.ResourceGraph/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "net", "TagPrefix": "net/resourcegraph/Azure.ResourceManager.ResourceGraph", - "Tag": "net/resourcegraph/Azure.ResourceManager.ResourceGraph_a6ab52c4a7" + "Tag": "net/resourcegraph/Azure.ResourceManager.ResourceGraph_95b462d107" } diff --git a/sdk/resourcegraph/Azure.ResourceManager.ResourceGraph/src/Generated/Models/DateTimeInterval.Serialization.cs b/sdk/resourcegraph/Azure.ResourceManager.ResourceGraph/src/Generated/Models/DateTimeInterval.Serialization.cs index cf7dab1ff839c..1939721cdee46 100644 --- a/sdk/resourcegraph/Azure.ResourceManager.ResourceGraph/src/Generated/Models/DateTimeInterval.Serialization.cs +++ b/sdk/resourcegraph/Azure.ResourceManager.ResourceGraph/src/Generated/Models/DateTimeInterval.Serialization.cs @@ -18,6 +18,15 @@ public partial class DateTimeInterval : IUtf8JsonSerializable, IJsonModel ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") @@ -25,7 +34,6 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriter throw new FormatException($"The model {nameof(DateTimeInterval)} does not support writing '{format}' format."); } - writer.WriteStartObject(); writer.WritePropertyName("start"u8); writer.WriteStringValue(StartOn, "O"); writer.WritePropertyName("end"u8); @@ -45,7 +53,6 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriter #endif } } - writer.WriteEndObject(); } DateTimeInterval IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) diff --git a/sdk/resourcegraph/Azure.ResourceManager.ResourceGraph/src/Generated/Models/Facet.Serialization.cs b/sdk/resourcegraph/Azure.ResourceManager.ResourceGraph/src/Generated/Models/Facet.Serialization.cs index ad3bf327be628..3257ee2b36962 100644 --- a/sdk/resourcegraph/Azure.ResourceManager.ResourceGraph/src/Generated/Models/Facet.Serialization.cs +++ b/sdk/resourcegraph/Azure.ResourceManager.ResourceGraph/src/Generated/Models/Facet.Serialization.cs @@ -18,6 +18,15 @@ public partial class Facet : IUtf8JsonSerializable, IJsonModel void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") @@ -25,7 +34,6 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions opt throw new FormatException($"The model {nameof(Facet)} does not support writing '{format}' format."); } - writer.WriteStartObject(); writer.WritePropertyName("expression"u8); writer.WriteStringValue(Expression); writer.WritePropertyName("resultType"u8); @@ -45,7 +53,6 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions opt #endif } } - writer.WriteEndObject(); } Facet IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) diff --git a/sdk/resourcegraph/Azure.ResourceManager.ResourceGraph/src/Generated/Models/FacetError.Serialization.cs b/sdk/resourcegraph/Azure.ResourceManager.ResourceGraph/src/Generated/Models/FacetError.Serialization.cs index d89caf441b632..7cd9a391b1e56 100644 --- a/sdk/resourcegraph/Azure.ResourceManager.ResourceGraph/src/Generated/Models/FacetError.Serialization.cs +++ b/sdk/resourcegraph/Azure.ResourceManager.ResourceGraph/src/Generated/Models/FacetError.Serialization.cs @@ -18,6 +18,15 @@ public partial class FacetError : IUtf8JsonSerializable, IJsonModel void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") @@ -25,7 +34,7 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOption throw new FormatException($"The model {nameof(FacetError)} does not support writing '{format}' format."); } - writer.WriteStartObject(); + base.JsonModelWriteCore(writer, options); writer.WritePropertyName("errors"u8); writer.WriteStartArray(); foreach (var item in Errors) @@ -33,26 +42,6 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOption writer.WriteObjectValue(item, options); } writer.WriteEndArray(); - writer.WritePropertyName("expression"u8); - writer.WriteStringValue(Expression); - writer.WritePropertyName("resultType"u8); - writer.WriteStringValue(ResultType); - 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(); } FacetError IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) diff --git a/sdk/resourcegraph/Azure.ResourceManager.ResourceGraph/src/Generated/Models/FacetErrorDetails.Serialization.cs b/sdk/resourcegraph/Azure.ResourceManager.ResourceGraph/src/Generated/Models/FacetErrorDetails.Serialization.cs index 54dfb5b3a8e20..e56966b0a40aa 100644 --- a/sdk/resourcegraph/Azure.ResourceManager.ResourceGraph/src/Generated/Models/FacetErrorDetails.Serialization.cs +++ b/sdk/resourcegraph/Azure.ResourceManager.ResourceGraph/src/Generated/Models/FacetErrorDetails.Serialization.cs @@ -18,6 +18,15 @@ public partial class FacetErrorDetails : IUtf8JsonSerializable, IJsonModel ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") @@ -25,7 +34,6 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWrite throw new FormatException($"The model {nameof(FacetErrorDetails)} does not support writing '{format}' format."); } - writer.WriteStartObject(); writer.WritePropertyName("code"u8); writer.WriteStringValue(Code); writer.WritePropertyName("message"u8); @@ -42,7 +50,6 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWrite } #endif } - writer.WriteEndObject(); } FacetErrorDetails IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) diff --git a/sdk/resourcegraph/Azure.ResourceManager.ResourceGraph/src/Generated/Models/FacetRequest.Serialization.cs b/sdk/resourcegraph/Azure.ResourceManager.ResourceGraph/src/Generated/Models/FacetRequest.Serialization.cs index 4f82deb9f9d72..ffdb0441a4b44 100644 --- a/sdk/resourcegraph/Azure.ResourceManager.ResourceGraph/src/Generated/Models/FacetRequest.Serialization.cs +++ b/sdk/resourcegraph/Azure.ResourceManager.ResourceGraph/src/Generated/Models/FacetRequest.Serialization.cs @@ -18,6 +18,15 @@ public partial class FacetRequest : IUtf8JsonSerializable, IJsonModel ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") @@ -25,7 +34,6 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOpti throw new FormatException($"The model {nameof(FacetRequest)} does not support writing '{format}' format."); } - writer.WriteStartObject(); writer.WritePropertyName("expression"u8); writer.WriteStringValue(Expression); if (Optional.IsDefined(Options)) @@ -48,7 +56,6 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOpti #endif } } - writer.WriteEndObject(); } FacetRequest IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) diff --git a/sdk/resourcegraph/Azure.ResourceManager.ResourceGraph/src/Generated/Models/FacetRequestOptions.Serialization.cs b/sdk/resourcegraph/Azure.ResourceManager.ResourceGraph/src/Generated/Models/FacetRequestOptions.Serialization.cs index f58d64bca733e..396092322c72d 100644 --- a/sdk/resourcegraph/Azure.ResourceManager.ResourceGraph/src/Generated/Models/FacetRequestOptions.Serialization.cs +++ b/sdk/resourcegraph/Azure.ResourceManager.ResourceGraph/src/Generated/Models/FacetRequestOptions.Serialization.cs @@ -18,6 +18,15 @@ public partial class FacetRequestOptions : IUtf8JsonSerializable, IJsonModel ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") @@ -25,7 +34,6 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWri throw new FormatException($"The model {nameof(FacetRequestOptions)} does not support writing '{format}' format."); } - writer.WriteStartObject(); if (Optional.IsDefined(SortBy)) { writer.WritePropertyName("sortBy"u8); @@ -61,7 +69,6 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWri #endif } } - writer.WriteEndObject(); } FacetRequestOptions IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) diff --git a/sdk/resourcegraph/Azure.ResourceManager.ResourceGraph/src/Generated/Models/FacetResult.Serialization.cs b/sdk/resourcegraph/Azure.ResourceManager.ResourceGraph/src/Generated/Models/FacetResult.Serialization.cs index 3c1686f444d70..c17bede7e5993 100644 --- a/sdk/resourcegraph/Azure.ResourceManager.ResourceGraph/src/Generated/Models/FacetResult.Serialization.cs +++ b/sdk/resourcegraph/Azure.ResourceManager.ResourceGraph/src/Generated/Models/FacetResult.Serialization.cs @@ -18,6 +18,15 @@ public partial class FacetResult : IUtf8JsonSerializable, IJsonModel ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") @@ -25,7 +34,7 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptio throw new FormatException($"The model {nameof(FacetResult)} does not support writing '{format}' format."); } - writer.WriteStartObject(); + base.JsonModelWriteCore(writer, options); writer.WritePropertyName("totalRecords"u8); writer.WriteNumberValue(TotalRecords); writer.WritePropertyName("count"u8); @@ -39,26 +48,6 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptio JsonSerializer.Serialize(writer, document.RootElement); } #endif - writer.WritePropertyName("expression"u8); - writer.WriteStringValue(Expression); - writer.WritePropertyName("resultType"u8); - writer.WriteStringValue(ResultType); - 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(); } FacetResult IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) diff --git a/sdk/resourcegraph/Azure.ResourceManager.ResourceGraph/src/Generated/Models/ResourceQueryContent.Serialization.cs b/sdk/resourcegraph/Azure.ResourceManager.ResourceGraph/src/Generated/Models/ResourceQueryContent.Serialization.cs index d0da762659d3a..3f1830134ba99 100644 --- a/sdk/resourcegraph/Azure.ResourceManager.ResourceGraph/src/Generated/Models/ResourceQueryContent.Serialization.cs +++ b/sdk/resourcegraph/Azure.ResourceManager.ResourceGraph/src/Generated/Models/ResourceQueryContent.Serialization.cs @@ -18,6 +18,15 @@ public partial class ResourceQueryContent : IUtf8JsonSerializable, IJsonModel ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") @@ -25,7 +34,6 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWr throw new FormatException($"The model {nameof(ResourceQueryContent)} does not support writing '{format}' format."); } - writer.WriteStartObject(); if (Optional.IsCollectionDefined(Subscriptions)) { writer.WritePropertyName("subscriptions"u8); @@ -78,7 +86,6 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWr #endif } } - writer.WriteEndObject(); } ResourceQueryContent IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) diff --git a/sdk/resourcegraph/Azure.ResourceManager.ResourceGraph/src/Generated/Models/ResourceQueryRequestOptions.Serialization.cs b/sdk/resourcegraph/Azure.ResourceManager.ResourceGraph/src/Generated/Models/ResourceQueryRequestOptions.Serialization.cs index ca2d509719a44..a7c722ccbf1a4 100644 --- a/sdk/resourcegraph/Azure.ResourceManager.ResourceGraph/src/Generated/Models/ResourceQueryRequestOptions.Serialization.cs +++ b/sdk/resourcegraph/Azure.ResourceManager.ResourceGraph/src/Generated/Models/ResourceQueryRequestOptions.Serialization.cs @@ -18,6 +18,15 @@ public partial class ResourceQueryRequestOptions : IUtf8JsonSerializable, IJsonM void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") @@ -25,7 +34,6 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelR throw new FormatException($"The model {nameof(ResourceQueryRequestOptions)} does not support writing '{format}' format."); } - writer.WriteStartObject(); if (Optional.IsDefined(SkipToken)) { writer.WritePropertyName("$skipToken"u8); @@ -71,7 +79,6 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelR #endif } } - writer.WriteEndObject(); } ResourceQueryRequestOptions IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) diff --git a/sdk/resourcegraph/Azure.ResourceManager.ResourceGraph/src/Generated/Models/ResourceQueryResult.Serialization.cs b/sdk/resourcegraph/Azure.ResourceManager.ResourceGraph/src/Generated/Models/ResourceQueryResult.Serialization.cs index 484f6ad2b1a00..0ce7ed245d9ae 100644 --- a/sdk/resourcegraph/Azure.ResourceManager.ResourceGraph/src/Generated/Models/ResourceQueryResult.Serialization.cs +++ b/sdk/resourcegraph/Azure.ResourceManager.ResourceGraph/src/Generated/Models/ResourceQueryResult.Serialization.cs @@ -18,6 +18,15 @@ public partial class ResourceQueryResult : IUtf8JsonSerializable, IJsonModel ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") @@ -25,7 +34,6 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWri throw new FormatException($"The model {nameof(ResourceQueryResult)} does not support writing '{format}' format."); } - writer.WriteStartObject(); writer.WritePropertyName("totalRecords"u8); writer.WriteNumberValue(TotalRecords); writer.WritePropertyName("count"u8); @@ -71,7 +79,6 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWri #endif } } - writer.WriteEndObject(); } ResourceQueryResult IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) diff --git a/sdk/resourcegraph/Azure.ResourceManager.ResourceGraph/src/Generated/Models/ResourcesHistoryContent.Serialization.cs b/sdk/resourcegraph/Azure.ResourceManager.ResourceGraph/src/Generated/Models/ResourcesHistoryContent.Serialization.cs index dfc080c5329ff..66b319f468243 100644 --- a/sdk/resourcegraph/Azure.ResourceManager.ResourceGraph/src/Generated/Models/ResourcesHistoryContent.Serialization.cs +++ b/sdk/resourcegraph/Azure.ResourceManager.ResourceGraph/src/Generated/Models/ResourcesHistoryContent.Serialization.cs @@ -18,6 +18,15 @@ public partial class ResourcesHistoryContent : IUtf8JsonSerializable, IJsonModel void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") @@ -25,7 +34,6 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReade throw new FormatException($"The model {nameof(ResourcesHistoryContent)} does not support writing '{format}' format."); } - writer.WriteStartObject(); if (Optional.IsCollectionDefined(Subscriptions)) { writer.WritePropertyName("subscriptions"u8); @@ -71,7 +79,6 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReade #endif } } - writer.WriteEndObject(); } ResourcesHistoryContent IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) diff --git a/sdk/resourcegraph/Azure.ResourceManager.ResourceGraph/src/Generated/Models/ResourcesHistoryRequestOptions.Serialization.cs b/sdk/resourcegraph/Azure.ResourceManager.ResourceGraph/src/Generated/Models/ResourcesHistoryRequestOptions.Serialization.cs index 21d8ea2a93ca6..9bc4ea66a7c62 100644 --- a/sdk/resourcegraph/Azure.ResourceManager.ResourceGraph/src/Generated/Models/ResourcesHistoryRequestOptions.Serialization.cs +++ b/sdk/resourcegraph/Azure.ResourceManager.ResourceGraph/src/Generated/Models/ResourcesHistoryRequestOptions.Serialization.cs @@ -18,6 +18,15 @@ public partial class ResourcesHistoryRequestOptions : IUtf8JsonSerializable, IJs void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") @@ -25,7 +34,6 @@ void IJsonModel.Write(Utf8JsonWriter writer, Mod throw new FormatException($"The model {nameof(ResourcesHistoryRequestOptions)} does not support writing '{format}' format."); } - writer.WriteStartObject(); if (Optional.IsDefined(Interval)) { writer.WritePropertyName("interval"u8); @@ -66,7 +74,6 @@ void IJsonModel.Write(Utf8JsonWriter writer, Mod #endif } } - writer.WriteEndObject(); } ResourcesHistoryRequestOptions IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) diff --git a/sdk/resourcegraph/Azure.ResourceManager.ResourceGraph/src/Generated/Models/UnknownFacet.Serialization.cs b/sdk/resourcegraph/Azure.ResourceManager.ResourceGraph/src/Generated/Models/UnknownFacet.Serialization.cs index f49e42f763013..a48f38aa37ec7 100644 --- a/sdk/resourcegraph/Azure.ResourceManager.ResourceGraph/src/Generated/Models/UnknownFacet.Serialization.cs +++ b/sdk/resourcegraph/Azure.ResourceManager.ResourceGraph/src/Generated/Models/UnknownFacet.Serialization.cs @@ -18,6 +18,15 @@ internal partial class UnknownFacet : IUtf8JsonSerializable, IJsonModel void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") @@ -25,27 +34,7 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions opt throw new FormatException($"The model {nameof(Facet)} does not support writing '{format}' format."); } - writer.WriteStartObject(); - writer.WritePropertyName("expression"u8); - writer.WriteStringValue(Expression); - writer.WritePropertyName("resultType"u8); - writer.WriteStringValue(ResultType); - 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(); + base.JsonModelWriteCore(writer, options); } Facet IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) diff --git a/sdk/resourcegraph/Azure.ResourceManager.ResourceGraph/src/autorest.md b/sdk/resourcegraph/Azure.ResourceManager.ResourceGraph/src/autorest.md index 5208d131a9579..1f2dc52afef83 100644 --- a/sdk/resourcegraph/Azure.ResourceManager.ResourceGraph/src/autorest.md +++ b/sdk/resourcegraph/Azure.ResourceManager.ResourceGraph/src/autorest.md @@ -19,6 +19,7 @@ skip-csproj: true modelerfour: flatten-payloads: false use-model-reader-writer: true +use-write-core: true rename-mapping: ErrorDetails: FacetErrorDetails