diff --git a/sdk/compute/Azure.ResourceManager.Compute/src/Customize/Models/ComputeResourceSkuLocationInfo.Serialization.cs b/sdk/compute/Azure.ResourceManager.Compute/src/Customize/Models/ComputeResourceSkuLocationInfo.Serialization.cs deleted file mode 100644 index 1fce3da43d56..000000000000 --- a/sdk/compute/Azure.ResourceManager.Compute/src/Customize/Models/ComputeResourceSkuLocationInfo.Serialization.cs +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#nullable disable - -using System.Collections.Generic; -using System.Text.Json; -using Azure.Core; - -namespace Azure.ResourceManager.Compute.Models -{ - // TEMPORARY: this piece of customized code replaces the ExtendedLocationType with the one in resourcemanager - public partial class ComputeResourceSkuLocationInfo - { - internal static ComputeResourceSkuLocationInfo DeserializeComputeResourceSkuLocationInfo(JsonElement element) - { - Optional location = default; - Optional> zones = default; - Optional> zoneDetails = default; - Optional> extendedLocations = default; - Optional type = default; - foreach (var property in element.EnumerateObject()) - { - if (property.NameEquals("location")) - { - if (property.Value.ValueKind == JsonValueKind.Null) - { - property.ThrowNonNullablePropertyIsNull(); - continue; - } - location = new AzureLocation(property.Value.GetString()); - continue; - } - if (property.NameEquals("zones")) - { - if (property.Value.ValueKind == JsonValueKind.Null) - { - property.ThrowNonNullablePropertyIsNull(); - continue; - } - List array = new List(); - foreach (var item in property.Value.EnumerateArray()) - { - array.Add(item.GetString()); - } - zones = array; - continue; - } - if (property.NameEquals("zoneDetails")) - { - if (property.Value.ValueKind == JsonValueKind.Null) - { - property.ThrowNonNullablePropertyIsNull(); - continue; - } - List array = new List(); - foreach (var item in property.Value.EnumerateArray()) - { - array.Add(ComputeResourceSkuZoneDetails.DeserializeComputeResourceSkuZoneDetails(item)); - } - zoneDetails = array; - continue; - } - if (property.NameEquals("extendedLocations")) - { - if (property.Value.ValueKind == JsonValueKind.Null) - { - property.ThrowNonNullablePropertyIsNull(); - continue; - } - List array = new List(); - foreach (var item in property.Value.EnumerateArray()) - { - array.Add(item.GetString()); - } - extendedLocations = array; - continue; - } - if (property.NameEquals("type")) - { - if (property.Value.ValueKind == JsonValueKind.Null) - { - property.ThrowNonNullablePropertyIsNull(); - continue; - } - type = new Azure.ResourceManager.Resources.Models.ExtendedLocationType(property.Value.GetString()); - continue; - } - } - return new ComputeResourceSkuLocationInfo(Optional.ToNullable(location), Optional.ToList(zones), Optional.ToList(zoneDetails), Optional.ToList(extendedLocations), Optional.ToNullable(type)); - } - } -} diff --git a/sdk/compute/Azure.ResourceManager.Compute/src/Customize/Models/ComputeResourceSkuLocationInfo.cs b/sdk/compute/Azure.ResourceManager.Compute/src/Customize/Models/ComputeResourceSkuLocationInfo.cs index fec30010aada..685b845d2b56 100644 --- a/sdk/compute/Azure.ResourceManager.Compute/src/Customize/Models/ComputeResourceSkuLocationInfo.cs +++ b/sdk/compute/Azure.ResourceManager.Compute/src/Customize/Models/ComputeResourceSkuLocationInfo.cs @@ -3,6 +3,8 @@ #nullable disable +using System.Runtime.CompilerServices; +using System.Text.Json; using Azure.Core; namespace Azure.ResourceManager.Compute.Models @@ -12,6 +14,23 @@ public partial class ComputeResourceSkuLocationInfo { /// The type of the extended location. [CodeGenMember("ExtendedLocationType")] + [CodeGenMemberSerializationHooks(SerializationValueHook = nameof(WriteExtendedLocationType), DeserializationValueHook = nameof(ReadExtendedLocationType))] public Azure.ResourceManager.Resources.Models.ExtendedLocationType? ExtendedLocationType { get; } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + internal void WriteExtendedLocationType(Utf8JsonWriter writer) + { + writer.WriteStringValue(ExtendedLocationType.Value.ToString()); + } + + // deserialization hook for required property + [MethodImpl(MethodImplOptions.AggressiveInlining)] + internal static void ReadExtendedLocationType(JsonProperty property, ref Optional type) + { + if (property.Value.ValueKind == JsonValueKind.Null) + return; + + type = new Azure.ResourceManager.Resources.Models.ExtendedLocationType(property.Value.GetString()); + } } } diff --git a/sdk/compute/Azure.ResourceManager.Compute/src/Generated/Models/ComputeResourceSkuLocationInfo.Serialization.cs b/sdk/compute/Azure.ResourceManager.Compute/src/Generated/Models/ComputeResourceSkuLocationInfo.Serialization.cs index 82840436e246..1bded1918fd7 100644 --- a/sdk/compute/Azure.ResourceManager.Compute/src/Generated/Models/ComputeResourceSkuLocationInfo.Serialization.cs +++ b/sdk/compute/Azure.ResourceManager.Compute/src/Generated/Models/ComputeResourceSkuLocationInfo.Serialization.cs @@ -5,9 +5,86 @@ #nullable disable +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; +using Azure.ResourceManager.Resources.Models; + namespace Azure.ResourceManager.Compute.Models { public partial class ComputeResourceSkuLocationInfo { + internal static ComputeResourceSkuLocationInfo DeserializeComputeResourceSkuLocationInfo(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + Optional location = default; + Optional> zones = default; + Optional> zoneDetails = default; + Optional> extendedLocations = default; + Optional type = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("location"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + location = new AzureLocation(property.Value.GetString()); + continue; + } + if (property.NameEquals("zones"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(item.GetString()); + } + zones = array; + continue; + } + if (property.NameEquals("zoneDetails"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(ComputeResourceSkuZoneDetails.DeserializeComputeResourceSkuZoneDetails(item)); + } + zoneDetails = array; + continue; + } + if (property.NameEquals("extendedLocations"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(item.GetString()); + } + extendedLocations = array; + continue; + } + if (property.NameEquals("type"u8)) + { + ReadExtendedLocationType(property, ref type); + continue; + } + } + return new ComputeResourceSkuLocationInfo(Optional.ToNullable(location), Optional.ToList(zones), Optional.ToList(zoneDetails), Optional.ToList(extendedLocations), Optional.ToNullable(type)); + } } } diff --git a/sdk/databox/Azure.ResourceManager.DataBox/src/Custom/Models/MitigateJobContent.Serialization.cs b/sdk/databox/Azure.ResourceManager.DataBox/src/Custom/Models/MitigateJobContent.Serialization.cs deleted file mode 100644 index 62c27795c0ec..000000000000 --- a/sdk/databox/Azure.ResourceManager.DataBox/src/Custom/Models/MitigateJobContent.Serialization.cs +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#nullable disable - -using System.Text.Json; -using Azure.Core; - -namespace Azure.ResourceManager.DataBox.Models -{ - public partial class MitigateJobContent : IUtf8JsonSerializable - { - void global::Azure.Core.IUtf8JsonSerializable.Write(Utf8JsonWriter writer) - { - writer.WriteStartObject(); - if (Optional.IsDefined(_customerResolutionCode)) - { - writer.WritePropertyName("customerResolutionCode"u8); - writer.WriteStringValue(_customerResolutionCode.Value.ToSerialString()); - } - writer.WritePropertyName("customerResolutionCode"u8); - - writer.WriteStringValue(CustomerResolutionCode.ToSerialString()); - if (Optional.IsCollectionDefined(SerialNumberCustomerResolutionMap)) - { - writer.WritePropertyName("serialNumberCustomerResolutionMap"u8); - writer.WriteStartObject(); - foreach (var item in SerialNumberCustomerResolutionMap) - { - writer.WritePropertyName(item.Key); - writer.WriteStringValue(item.Value.ToSerialString()); - } - writer.WriteEndObject(); - } - writer.WriteEndObject(); - } - } -} diff --git a/sdk/databox/Azure.ResourceManager.DataBox/src/Custom/Models/MitigateJobContent.cs b/sdk/databox/Azure.ResourceManager.DataBox/src/Custom/Models/MitigateJobContent.cs index babb4807d43c..067babb91a04 100644 --- a/sdk/databox/Azure.ResourceManager.DataBox/src/Custom/Models/MitigateJobContent.cs +++ b/sdk/databox/Azure.ResourceManager.DataBox/src/Custom/Models/MitigateJobContent.cs @@ -1,14 +1,16 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +using System.Runtime.CompilerServices; +using System.Text.Json; using Azure.Core; namespace Azure.ResourceManager.DataBox.Models { public partial class MitigateJobContent { - // This is used to represent default null for breaking change of CustomerResolutionCode changed from requried to optional - internal CustomerResolutionCode? _customerResolutionCode; + // This is used to represent default null for breaking change of CustomerResolutionCode changed from required to optional + private CustomerResolutionCode? _customerResolutionCode; /// Initializes a new instance of MitigateJobContent. public MitigateJobContent() @@ -20,10 +22,20 @@ public MitigateJobContent() /// Resolution code for the job. public MitigateJobContent(CustomerResolutionCode customerResolutionCode) : this() { - _customerResolutionCode = customerResolutionCode; + CustomerResolutionCode = customerResolutionCode; } /// Resolution code for the job. - public CustomerResolutionCode CustomerResolutionCode => _customerResolutionCode ?? default; + public CustomerResolutionCode CustomerResolutionCode + { + get + { + return _customerResolutionCode ?? default; + } + private set + { + _customerResolutionCode = value; + } + } } } diff --git a/sdk/databox/Azure.ResourceManager.DataBox/src/Generated/Models/MitigateJobContent.Serialization.cs b/sdk/databox/Azure.ResourceManager.DataBox/src/Generated/Models/MitigateJobContent.Serialization.cs index deef8980f82a..2c37aed9bf3c 100644 --- a/sdk/databox/Azure.ResourceManager.DataBox/src/Generated/Models/MitigateJobContent.Serialization.cs +++ b/sdk/databox/Azure.ResourceManager.DataBox/src/Generated/Models/MitigateJobContent.Serialization.cs @@ -12,5 +12,23 @@ namespace Azure.ResourceManager.DataBox.Models { public partial class MitigateJobContent : IUtf8JsonSerializable { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + { + writer.WriteStartObject(); + writer.WritePropertyName("customerResolutionCode"u8); + writer.WriteStringValue(CustomerResolutionCode.ToSerialString()); + if (Optional.IsCollectionDefined(SerialNumberCustomerResolutionMap)) + { + writer.WritePropertyName("serialNumberCustomerResolutionMap"u8); + writer.WriteStartObject(); + foreach (var item in SerialNumberCustomerResolutionMap) + { + writer.WritePropertyName(item.Key); + writer.WriteStringValue(item.Value.ToSerialString()); + } + writer.WriteEndObject(); + } + writer.WriteEndObject(); + } } } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Custom/ImageGenerations.cs b/sdk/openai/Azure.AI.OpenAI/src/Custom/ImageGenerations.cs index 214865a4044c..451260d7d443 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Custom/ImageGenerations.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Custom/ImageGenerations.cs @@ -17,14 +17,25 @@ public partial class ImageGenerations /// /// Gets a list of generated image items in the format specified for the request. /// - [CodeGenMemberSerializationHooks(DeserializationValueHook = nameof(DeserializeDataProperty))] + [CodeGenMemberSerializationHooks(SerializationValueHook = nameof(SerializeDataProperty), DeserializationValueHook = nameof(DeserializeDataProperty))] public IReadOnlyList Data { get; } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + internal void SerializeDataProperty(Utf8JsonWriter writer) + { + // CUSTOM CODE NOTE: we always need to specify the serialization code explicitly when we change the type of a property + writer.WriteStartArray(); + foreach (var item in Data) + { + writer.WriteObjectValue(item); + } + writer.WriteEndArray(); + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static void DeserializeDataProperty(JsonProperty property, ref IReadOnlyList data) { - // CUSTOM CODE NOTE: this hook for Data is needed pending improved codegen support for union types; it - // otherwise generates with "property.Value.()" + // CUSTOM CODE NOTE: we always need to specify the serialization code explicitly when we change the type of a property List array = new List(); foreach (var item in property.Value.EnumerateArray()) { diff --git a/sdk/resourcemanager/Azure.ResourceManager/api/Azure.ResourceManager.netstandard2.0.cs b/sdk/resourcemanager/Azure.ResourceManager/api/Azure.ResourceManager.netstandard2.0.cs index 22f2d2c0cee5..5bdaf6935736 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/api/Azure.ResourceManager.netstandard2.0.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/api/Azure.ResourceManager.netstandard2.0.cs @@ -472,6 +472,7 @@ public static partial class ResourceManagerModelFactory public static Azure.ResourceManager.Resources.GenericResourceData GenericResourceData(Azure.Core.ResourceIdentifier id = null, string name = null, Azure.Core.ResourceType resourceType = default(Azure.Core.ResourceType), Azure.ResourceManager.Models.SystemData systemData = null, System.Collections.Generic.IDictionary tags = null, Azure.Core.AzureLocation location = default(Azure.Core.AzureLocation), Azure.ResourceManager.Resources.Models.ExtendedLocation extendedLocation = null, Azure.ResourceManager.Models.ArmPlan plan = null, System.BinaryData properties = null, string kind = null, string managedBy = null, Azure.ResourceManager.Resources.Models.ResourcesSku sku = null, Azure.ResourceManager.Models.ManagedServiceIdentity identity = null, System.DateTimeOffset? createdOn = default(System.DateTimeOffset?), System.DateTimeOffset? changedOn = default(System.DateTimeOffset?), string provisioningState = null) { throw null; } public static Azure.ResourceManager.Resources.Models.LocationExpanded LocationExpanded(string id, string subscriptionId, string name, Azure.ResourceManager.Resources.Models.LocationType? locationType, string displayName, string regionalDisplayName, Azure.ResourceManager.Resources.Models.LocationMetadata metadata) { throw null; } public static Azure.ResourceManager.Resources.Models.LocationExpanded LocationExpanded(string id = null, string subscriptionId = null, string name = null, Azure.ResourceManager.Resources.Models.LocationType? locationType = default(Azure.ResourceManager.Resources.Models.LocationType?), string displayName = null, string regionalDisplayName = null, Azure.ResourceManager.Resources.Models.LocationMetadata metadata = null, System.Collections.Generic.IEnumerable availabilityZoneMappings = null) { throw null; } + public static Azure.ResourceManager.Resources.Models.LocationMetadata LocationMetadata(Azure.ResourceManager.Resources.Models.RegionType? regionType = default(Azure.ResourceManager.Resources.Models.RegionType?), Azure.ResourceManager.Resources.Models.RegionCategory? regionCategory = default(Azure.ResourceManager.Resources.Models.RegionCategory?), string geography = null, string geographyGroup = null, double? longitude = default(double?), double? latitude = default(double?), string physicalLocation = null, System.Collections.Generic.IEnumerable pairedRegions = null, string homeLocation = null) { throw null; } public static Azure.ResourceManager.Resources.Models.ManagedByTenant ManagedByTenant(System.Guid? tenantId = default(System.Guid?)) { throw null; } public static Azure.ResourceManager.ManagementGroups.Models.ManagementGroupChildInfo ManagementGroupChildInfo(Azure.ResourceManager.ManagementGroups.Models.ManagementGroupChildType? childType = default(Azure.ResourceManager.ManagementGroups.Models.ManagementGroupChildType?), string id = null, string name = null, string displayName = null, System.Collections.Generic.IEnumerable children = null) { throw null; } public static Azure.ResourceManager.ManagementGroups.ManagementGroupData ManagementGroupData(Azure.Core.ResourceIdentifier id = null, string name = null, Azure.Core.ResourceType resourceType = default(Azure.Core.ResourceType), Azure.ResourceManager.Models.SystemData systemData = null, System.Guid? tenantId = default(System.Guid?), string displayName = null, Azure.ResourceManager.ManagementGroups.Models.ManagementGroupInfo details = null, System.Collections.Generic.IEnumerable children = null) { throw null; } @@ -1375,6 +1376,7 @@ internal LocationExpanded() { } public partial class LocationMetadata { internal LocationMetadata() { } + public string Geography { get { throw null; } } public string GeographyGroup { get { throw null; } } public string HomeLocation { get { throw null; } } public double? Latitude { get { throw null; } } diff --git a/sdk/resourcemanager/Azure.ResourceManager/src/Common/Custom/Models/ManagedServiceIdentity.Serialization.cs b/sdk/resourcemanager/Azure.ResourceManager/src/Common/Custom/Models/ManagedServiceIdentity.Serialization.cs index cb5895995f7b..dd040159001a 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/src/Common/Custom/Models/ManagedServiceIdentity.Serialization.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/src/Common/Custom/Models/ManagedServiceIdentity.Serialization.cs @@ -15,15 +15,16 @@ namespace Azure.ResourceManager.Models [JsonConverter(typeof(ManagedServiceIdentityConverter))] public partial class ManagedServiceIdentity { - internal static void Write(Utf8JsonWriter writer, ManagedServiceIdentity model, JsonSerializerOptions options = default) + internal void Write(Utf8JsonWriter writer, JsonSerializerOptions options = default) { writer.WriteStartObject(); - JsonSerializer.Serialize(writer, model.ManagedServiceIdentityType, options); - if (Optional.IsCollectionDefined(model.UserAssignedIdentities)) + writer.WritePropertyName("type"); + JsonSerializer.Serialize(writer, ManagedServiceIdentityType, options); + if (Optional.IsCollectionDefined(UserAssignedIdentities)) { writer.WritePropertyName("userAssignedIdentities"u8); writer.WriteStartObject(); - foreach (var item in model.UserAssignedIdentities) + foreach (var item in UserAssignedIdentities) { writer.WritePropertyName(item.Key); if (item.Value == null) @@ -70,7 +71,7 @@ internal static ManagedServiceIdentity DeserializeManagedServiceIdentity(JsonEle } if (property.NameEquals("type"u8)) { - type = JsonSerializer.Deserialize("{"+property.ToString()+"}", options); + type = JsonSerializer.Deserialize(property.Value.GetRawText(), options); continue; } if (property.NameEquals("userAssignedIdentities"u8)) @@ -96,7 +97,7 @@ internal partial class ManagedServiceIdentityConverter : JsonConverter Managed service identity (system assigned and/or user assigned identities). - [PropertyReferenceType(new string[]{"UserAssignedIdentities"})] + [PropertyReferenceType(new string[] { "UserAssignedIdentities" })] public partial class ManagedServiceIdentity { /// Initializes a new instance of ManagedServiceIdentity. diff --git a/sdk/resourcemanager/Azure.ResourceManager/src/Common/Custom/Models/ManagedServiceIdentityType.cs b/sdk/resourcemanager/Azure.ResourceManager/src/Common/Custom/Models/ManagedServiceIdentityType.cs index 3035631a0300..eb2d645e5b4c 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/src/Common/Custom/Models/ManagedServiceIdentityType.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/src/Common/Custom/Models/ManagedServiceIdentityType.cs @@ -17,17 +17,12 @@ internal partial class ManagedServiceIdentityTypeConverter : JsonConverter - #nullable disable -using System.Collections.Generic; +using System.Runtime.CompilerServices; +using System.Text.Json; using Azure.Core; -[assembly: CodeGenSuppressType("LocationMetadata")] namespace Azure.ResourceManager.Resources.Models { - /// Location metadata information. public partial class LocationMetadata { - /// Initializes a new instance of LocationMetadata. - internal LocationMetadata() + /// The longitude of the location. + [CodeGenMemberSerializationHooks(SerializationValueHook = nameof(WriteLongitude), DeserializationValueHook = nameof(ReadLongitude))] + public double? Longitude { get; } + /// The latitude of the location. + [CodeGenMemberSerializationHooks(SerializationValueHook = nameof(WriteLatitude), DeserializationValueHook = nameof(ReadLatitude))] + public double? Latitude { get; } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + internal void WriteLongitude(Utf8JsonWriter writer) { - PairedRegions = new ChangeTrackingList(); + if (Longitude != null) + writer.WriteStringValue(Longitude.ToString()); } - /// Initializes a new instance of LocationMetadata. - /// The type of the region. - /// The category of the region. - /// The geography group of the location. - /// The longitude of the location. - /// The latitude of the location. - /// The physical location of the Azure location. - /// The regions paired to this region. - /// The home location of an edge zone. - internal LocationMetadata(RegionType? regionType, RegionCategory? regionCategory, string geographyGroup, double? longitude, double? latitude, string physicalLocation, IReadOnlyList pairedRegions, string homeLocation) + [MethodImpl(MethodImplOptions.AggressiveInlining)] + internal static void ReadLongitude(JsonProperty property, ref Optional longitude) { - RegionType = regionType; - RegionCategory = regionCategory; - GeographyGroup = geographyGroup; - Longitude = longitude; - Latitude = latitude; - PhysicalLocation = physicalLocation; - PairedRegions = pairedRegions; - HomeLocation = homeLocation; + if (property.Value.ValueKind == JsonValueKind.Null) + return; + + longitude = double.Parse(property.Value.GetString()); } - /// The type of the region. - public RegionType? RegionType { get; } - /// The category of the region. - public RegionCategory? RegionCategory { get; } - /// The geography group of the location. - public string GeographyGroup { get; } - /// The longitude of the location. - public double? Longitude { get; } - /// The latitude of the location. - public double? Latitude { get; } - /// The physical location of the Azure location. - public string PhysicalLocation { get; } - /// The regions paired to this region. - public IReadOnlyList PairedRegions { get; } - /// The home location of an edge zone. - public string HomeLocation { get; } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + internal void WriteLatitude(Utf8JsonWriter writer) + { + if (Latitude != null) + writer.WriteStringValue(Latitude.ToString()); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + internal static void ReadLatitude(JsonProperty property, ref Optional latitude) + { + if (property.Value.ValueKind == JsonValueKind.Null) + return; + + latitude = double.Parse(property.Value.GetString()); + } } } diff --git a/sdk/resourcemanager/Azure.ResourceManager/src/Resources/Custom/Models/LocationMetadata.Serialization.cs b/sdk/resourcemanager/Azure.ResourceManager/src/Resources/Generated/Models/LocationMetadata.Serialization.cs similarity index 64% rename from sdk/resourcemanager/Azure.ResourceManager/src/Resources/Custom/Models/LocationMetadata.Serialization.cs rename to sdk/resourcemanager/Azure.ResourceManager/src/Resources/Generated/Models/LocationMetadata.Serialization.cs index 05cd264c2000..6f4342cc7435 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/src/Resources/Custom/Models/LocationMetadata.Serialization.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/src/Resources/Generated/Models/LocationMetadata.Serialization.cs @@ -15,78 +15,85 @@ public partial class LocationMetadata { internal static LocationMetadata DeserializeLocationMetadata(JsonElement element) { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } Optional regionType = default; Optional regionCategory = default; + Optional geography = default; Optional geographyGroup = default; Optional longitude = default; Optional latitude = default; Optional physicalLocation = default; - Optional> pairedRegions = default; + Optional> pairedRegion = default; Optional homeLocation = default; foreach (var property in element.EnumerateObject()) { - if (property.NameEquals("regionType")) + if (property.NameEquals("regionType"u8)) { if (property.Value.ValueKind == JsonValueKind.Null) { - property.ThrowNonNullablePropertyIsNull(); continue; } regionType = new RegionType(property.Value.GetString()); continue; } - if (property.NameEquals("regionCategory")) + if (property.NameEquals("regionCategory"u8)) { if (property.Value.ValueKind == JsonValueKind.Null) { - property.ThrowNonNullablePropertyIsNull(); continue; } regionCategory = new RegionCategory(property.Value.GetString()); continue; } - if (property.NameEquals("geographyGroup")) + if (property.NameEquals("geography"u8)) + { + geography = property.Value.GetString(); + continue; + } + if (property.NameEquals("geographyGroup"u8)) { geographyGroup = property.Value.GetString(); continue; } - if (property.NameEquals("longitude")) + if (property.NameEquals("longitude"u8)) { - longitude = double.Parse(property.Value.GetString()); + ReadLongitude(property, ref longitude); continue; } - if (property.NameEquals("latitude")) + if (property.NameEquals("latitude"u8)) { - latitude = double.Parse(property.Value.GetString()); + ReadLatitude(property, ref latitude); continue; } - if (property.NameEquals("physicalLocation")) + if (property.NameEquals("physicalLocation"u8)) { physicalLocation = property.Value.GetString(); continue; } - if (property.NameEquals("pairedRegion")) + if (property.NameEquals("pairedRegion"u8)) { if (property.Value.ValueKind == JsonValueKind.Null) { - property.ThrowNonNullablePropertyIsNull(); continue; } List array = new List(); foreach (var item in property.Value.EnumerateArray()) { - array.Add(Models.PairedRegion.DeserializePairedRegion(item)); + array.Add(PairedRegion.DeserializePairedRegion(item)); } - pairedRegions = array; + pairedRegion = array; continue; } - if (property.NameEquals("homeLocation")) + if (property.NameEquals("homeLocation"u8)) { homeLocation = property.Value.GetString(); continue; } } - return new LocationMetadata(Optional.ToNullable(regionType), Optional.ToNullable(regionCategory), geographyGroup.Value, longitude.Value, latitude.Value, physicalLocation.Value, Optional.ToList(pairedRegions), homeLocation.Value); + return new LocationMetadata(Optional.ToNullable(regionType), Optional.ToNullable(regionCategory), geography.Value, geographyGroup.Value, Optional.ToNullable(longitude), Optional.ToNullable(latitude), physicalLocation.Value, Optional.ToList(pairedRegion), homeLocation.Value); } } } diff --git a/sdk/resourcemanager/Azure.ResourceManager/src/Resources/Generated/Models/LocationMetadata.cs b/sdk/resourcemanager/Azure.ResourceManager/src/Resources/Generated/Models/LocationMetadata.cs new file mode 100644 index 000000000000..84adba4a4067 --- /dev/null +++ b/sdk/resourcemanager/Azure.ResourceManager/src/Resources/Generated/Models/LocationMetadata.cs @@ -0,0 +1,60 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Collections.Generic; +using Azure.Core; + +namespace Azure.ResourceManager.Resources.Models +{ + /// Location metadata information. + public partial class LocationMetadata + { + /// Initializes a new instance of LocationMetadata. + internal LocationMetadata() + { + PairedRegions = new ChangeTrackingList(); + } + + /// Initializes a new instance of LocationMetadata. + /// The type of the region. + /// The category of the region. + /// The geography of the location. + /// The geography group of the location. + /// The longitude of the location. + /// The latitude of the location. + /// The physical location of the Azure location. + /// The regions paired to this region. + /// The home location of an edge zone. + internal LocationMetadata(RegionType? regionType, RegionCategory? regionCategory, string geography, string geographyGroup, double? longitude, double? latitude, string physicalLocation, IReadOnlyList pairedRegions, string homeLocation) + { + RegionType = regionType; + RegionCategory = regionCategory; + Geography = geography; + GeographyGroup = geographyGroup; + Longitude = longitude; + Latitude = latitude; + PhysicalLocation = physicalLocation; + PairedRegions = pairedRegions; + HomeLocation = homeLocation; + } + + /// The type of the region. + public RegionType? RegionType { get; } + /// The category of the region. + public RegionCategory? RegionCategory { get; } + /// The geography of the location. + public string Geography { get; } + /// The geography group of the location. + public string GeographyGroup { get; } + /// The physical location of the Azure location. + public string PhysicalLocation { get; } + /// The regions paired to this region. + public IReadOnlyList PairedRegions { get; } + /// The home location of an edge zone. + public string HomeLocation { get; } + } +} diff --git a/sdk/resourcemanager/Azure.ResourceManager/src/Resources/Generated/ResourceManagerModelFactory.cs b/sdk/resourcemanager/Azure.ResourceManager/src/Resources/Generated/ResourceManagerModelFactory.cs index 4ef7b0fc4595..5e4e8aabdb76 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/src/Resources/Generated/ResourceManagerModelFactory.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/src/Resources/Generated/ResourceManagerModelFactory.cs @@ -467,6 +467,24 @@ public static LocationExpanded LocationExpanded(string id = null, string subscri return new LocationExpanded(id, subscriptionId, name, locationType, displayName, regionalDisplayName, metadata, availabilityZoneMappings?.ToList()); } + /// Initializes a new instance of LocationMetadata. + /// The type of the region. + /// The category of the region. + /// The geography of the location. + /// The geography group of the location. + /// The longitude of the location. + /// The latitude of the location. + /// The physical location of the Azure location. + /// The regions paired to this region. + /// The home location of an edge zone. + /// A new instance for mocking. + public static LocationMetadata LocationMetadata(RegionType? regionType = null, RegionCategory? regionCategory = null, string geography = null, string geographyGroup = null, double? longitude = null, double? latitude = null, string physicalLocation = null, IEnumerable pairedRegions = null, string homeLocation = null) + { + pairedRegions ??= new List(); + + return new LocationMetadata(regionType, regionCategory, geography, geographyGroup, longitude, latitude, physicalLocation, pairedRegions?.ToList(), homeLocation); + } + /// Initializes a new instance of PairedRegion. /// The name of the paired region. /// The fully qualified ID of the location. For example, /subscriptions/8d65815f-a5b6-402f-9298-045155da7d74/locations/westus. diff --git a/sdk/resourcemanager/Azure.ResourceManager/src/Shared/ManagedServiceIdentityTypeV3Converter.cs b/sdk/resourcemanager/Azure.ResourceManager/src/Shared/ManagedServiceIdentityTypeV3Converter.cs index b33c186e195a..676f72aa6e65 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/src/Shared/ManagedServiceIdentityTypeV3Converter.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/src/Shared/ManagedServiceIdentityTypeV3Converter.cs @@ -20,7 +20,6 @@ internal class ManagedServiceIdentityTypeV3Converter : JsonConverter The options for JsonSerializer. public override void Write(Utf8JsonWriter writer, ManagedServiceIdentityType model, JsonSerializerOptions options) { - writer.WritePropertyName("type"); if (model == ManagedServiceIdentityType.SystemAssignedUserAssigned) { writer.WriteStringValue(SystemAssignedUserAssignedV3Value); @@ -38,16 +37,12 @@ public override void Write(Utf8JsonWriter writer, ManagedServiceIdentityType mod public override ManagedServiceIdentityType Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { using var document = JsonDocument.ParseValue(ref reader); - foreach (var property in document.RootElement.EnumerateObject()) + var typeValue = document.RootElement.GetString(); + if (typeValue.Equals(SystemAssignedUserAssignedV3Value, StringComparison.OrdinalIgnoreCase)) { - var typeValue = property.Value.GetString(); - if (typeValue.Equals(SystemAssignedUserAssignedV3Value, StringComparison.OrdinalIgnoreCase)) - { - return ManagedServiceIdentityType.SystemAssignedUserAssigned; - } - return new ManagedServiceIdentityType(typeValue); + return ManagedServiceIdentityType.SystemAssignedUserAssigned; } - return null; + return new ManagedServiceIdentityType(typeValue); } } } diff --git a/sdk/resourcemanager/Azure.ResourceManager/src/autorest.md b/sdk/resourcemanager/Azure.ResourceManager/src/autorest.md index 4574c84d1c4d..5677613a0862 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/src/autorest.md +++ b/sdk/resourcemanager/Azure.ResourceManager/src/autorest.md @@ -291,6 +291,7 @@ rename-mapping: SelectorKind: ResourceSelectorKind Location: LocationExpanded ResourcesMoveContent.targetResourceGroup: targetResourceGroupId|arm-id + LocationMetadata.pairedRegion: PairedRegions directive: # These methods can be replaced by using other methods in the same operation group, remove for Preview.