From edd5f38df4748272695b24523a48a5be253b9886 Mon Sep 17 00:00:00 2001 From: jolov Date: Tue, 13 Feb 2024 13:07:59 -0800 Subject: [PATCH] Generate Storage RM --- ...AccountImmutabilityPolicy.Serialization.cs | 99 +++ .../Models/BlobContainerData.Serialization.cs | 436 ++++++++++ ...ntainerImmutabilityPolicy.Serialization.cs | 154 ++++ .../BlobInventoryPolicyData.Serialization.cs | 138 ++++ ...InventoryPolicyDefinition.Serialization.cs | 148 ++++ ...BlobInventoryPolicyFilter.Serialization.cs | 207 +++++ .../BlobInventoryPolicyRule.Serialization.cs | 129 +++ ...BlobInventoryPolicySchema.Serialization.cs | 116 +++ .../BlobRestoreContent.Serialization.cs | 94 +++ .../Models/BlobRestoreRange.Serialization.cs | 100 +++ .../Models/BlobRestoreStatus.Serialization.cs | 128 +++ .../BlobServiceChangeFeed.Serialization.cs | 85 ++ .../Models/BlobServiceData.Serialization.cs | 259 ++++++ .../Models/BlobServiceItems.Serialization.cs | 79 ++ .../Models/DateAfterCreation.Serialization.cs | 84 ++ .../DateAfterModification.Serialization.cs | 112 +++ .../DeleteRetentionPolicy.Serialization.cs | 100 +++ .../DeletedAccountData.Serialization.cs | 189 +++++ .../DeletedAccountListResult.Serialization.cs | 101 +++ .../EncryptionScopeData.Serialization.cs | 196 +++++ ...onScopeKeyVaultProperties.Serialization.cs | 107 +++ ...EncryptionScopeListResult.Serialization.cs | 101 +++ .../Models/FileServiceData.Serialization.cs | 165 ++++ .../Models/FileServiceItems.Serialization.cs | 79 ++ .../Models/FileShareData.Serialization.cs | 427 ++++++++++ .../Models/FileShareItems.Serialization.cs | 101 +++ ...entityBasedAuthentication.Serialization.cs | 98 +++ .../GeoReplicationStatistics.Serialization.cs | 100 +++ .../GetAccountSasResult.Serialization.cs | 78 ++ .../GetServiceSasResult.Serialization.cs | 78 ++ .../ImmutabilityPolicyData.Serialization.cs | 181 +++++ .../ImmutableStorageAccount.Serialization.cs | 85 ++ ...ableStorageWithVersioning.Serialization.cs | 100 +++ ...tAccessTimeTrackingPolicy.Serialization.cs | 135 +++ .../LeaseContainerResponse.Serialization.cs | 100 +++ .../LeaseShareResponse.Serialization.cs | 100 +++ .../Models/LegalHold.Serialization.cs | 122 +++ .../LegalHoldProperties.Serialization.cs | 108 +++ .../Models/LegalHoldTag.Serialization.cs | 151 ++++ .../ListBlobInventoryPolicy.Serialization.cs | 79 ++ .../ListContainerItems.Serialization.cs | 101 +++ .../Models/ListQueueResource.Serialization.cs | 101 +++ .../Models/ListQueueServices.Serialization.cs | 79 ++ .../Models/ListTableResource.Serialization.cs | 101 +++ .../Models/ListTableServices.Serialization.cs | 79 ++ .../Models/LocalUserKeys.Serialization.cs | 101 +++ ...rRegeneratePasswordResult.Serialization.cs | 78 ++ .../Models/LocalUsers.Serialization.cs | 79 ++ .../ManagementPolicyAction.Serialization.cs | 98 +++ .../ManagementPolicyBaseBlob.Serialization.cs | 141 ++++ ...anagementPolicyDefinition.Serialization.cs | 84 ++ .../ManagementPolicyFilter.Serialization.cs | 149 ++++ .../ManagementPolicyRule.Serialization.cs | 107 +++ .../ManagementPolicySchema.Serialization.cs | 79 ++ .../ManagementPolicySnapShot.Serialization.cs | 126 +++ ...ManagementPolicyTagFilter.Serialization.cs | 122 +++ .../ManagementPolicyVersion.Serialization.cs | 126 +++ .../Models/Multichannel.Serialization.cs | 71 ++ ...ObjectReplicationPolicies.Serialization.cs | 79 ++ ...jectReplicationPolicyData.Serialization.cs | 213 +++++ ...ctReplicationPolicyFilter.Serialization.cs | 114 +++ ...jectReplicationPolicyRule.Serialization.cs | 136 ++++ ...tectedAppendWritesHistory.Serialization.cs | 86 ++ .../Models/ProtocolSettings.Serialization.cs | 70 ++ .../Models/QueueServiceData.Serialization.cs | 123 +++ .../Models/RestorePolicy.Serialization.cs | 115 +++ .../Models/SmbSetting.Serialization.cs | 158 ++++ .../StorageAccountData.Serialization.cs | 768 ++++++++++++++++++ .../StorageAccountEncryption.Serialization.cs | 127 +++ ...AccountEncryptionIdentity.Serialization.cs | 100 +++ ...AccountEncryptionServices.Serialization.cs | 112 +++ .../StorageAccountEndpoints.Serialization.cs | 168 ++++ ...orageAccountGetKeysResult.Serialization.cs | 79 ++ .../StorageAccountIPRule.Serialization.cs | 92 +++ ...eAccountInternetEndpoints.Serialization.cs | 112 +++ .../Models/StorageAccountKey.Serialization.cs | 129 +++ ...ageAccountKeyCreationTime.Serialization.cs | 86 ++ .../StorageAccountKeyPolicy.Serialization.cs | 70 ++ ...AccountKeyVaultProperties.Serialization.cs | 166 ++++ .../StorageAccountListResult.Serialization.cs | 101 +++ ...orageAccountLocalUserData.Serialization.cs | 243 ++++++ ...countManagementPolicyData.Serialization.cs | 138 ++++ ...AccountMicrosoftEndpoints.Serialization.cs | 140 ++++ ...untNameAvailabilityResult.Serialization.cs | 107 +++ ...rageAccountNetworkRuleSet.Serialization.cs | 151 ++++ ...AccountResourceAccessRule.Serialization.cs | 84 ++ .../StorageAccountSasPolicy.Serialization.cs | 92 +++ ...ccountSkuConversionStatus.Serialization.cs | 114 +++ ...AccountVirtualNetworkRule.Serialization.cs | 98 +++ ...ActiveDirectoryProperties.Serialization.cs | 216 +++++ .../Models/StorageCorsRule.Serialization.cs | 198 +++++ .../Models/StorageCorsRules.Serialization.cs | 79 ++ .../StorageCustomDomain.Serialization.cs | 93 +++ .../StorageEncryptionService.Serialization.cs | 100 +++ .../StoragePermissionScope.Serialization.cs | 122 +++ ...ateEndpointConnectionData.Serialization.cs | 151 ++++ ...pointConnectionListResult.Serialization.cs | 79 ++ ...gePrivateLinkResourceData.Serialization.cs | 194 +++++ ...ateLinkResourceListResult.Serialization.cs | 79 ++ ...inkServiceConnectionState.Serialization.cs | 114 +++ .../Models/StorageQueueData.Serialization.cs | 160 ++++ .../StorageRoutingPreference.Serialization.cs | 100 +++ ...torageServiceAccessPolicy.Serialization.cs | 108 +++ .../StorageSignedIdentifier.Serialization.cs | 92 +++ .../Models/StorageSku.Serialization.cs | 84 ++ .../StorageSkuCapability.Serialization.cs | 100 +++ .../StorageSkuInformation.Serialization.cs | 200 +++++ .../StorageSkuListResult.Serialization.cs | 79 ++ .../StorageSkuRestriction.Serialization.cs | 106 +++ .../StorageSshPublicKey.Serialization.cs | 100 +++ .../StorageTableAccessPolicy.Serialization.cs | 108 +++ ...rageTableSignedIdentifier.Serialization.cs | 92 +++ .../Models/StorageUsage.Serialization.cs | 112 +++ .../Models/StorageUsageName.Serialization.cs | 100 +++ .../Models/TableData.Serialization.cs | 154 ++++ .../Models/TableServiceData.Serialization.cs | 123 +++ .../UpdateHistoryEntry.Serialization.cs | 187 +++++ .../Models/UsageListResult.Serialization.cs | 79 ++ .../src/autorest.md | 1 + 119 files changed, 15152 insertions(+) diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/AccountImmutabilityPolicy.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/AccountImmutabilityPolicy.Serialization.cs index 918955cd94e72..69137e5a4d7ce 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/AccountImmutabilityPolicy.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/AccountImmutabilityPolicy.Serialization.cs @@ -8,8 +8,10 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -122,6 +124,99 @@ internal static AccountImmutabilityPolicy DeserializeAccountImmutabilityPolicy(J return new AccountImmutabilityPolicy(Optional.ToNullable(immutabilityPeriodSinceCreationInDays), Optional.ToNullable(state), Optional.ToNullable(allowProtectedAppendWrites), serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ImmutabilityPeriodSinceCreationInDays), out propertyOverride); + if (Optional.IsDefined(ImmutabilityPeriodSinceCreationInDays) || hasPropertyOverride) + { + builder.Append(" immutabilityPeriodSinceCreationInDays:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" {ImmutabilityPeriodSinceCreationInDays.Value}"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(State), out propertyOverride); + if (Optional.IsDefined(State) || hasPropertyOverride) + { + builder.Append(" state:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{State.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(AllowProtectedAppendWrites), out propertyOverride); + if (Optional.IsDefined(AllowProtectedAppendWrites) || hasPropertyOverride) + { + builder.Append(" allowProtectedAppendWrites:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var boolValue = AllowProtectedAppendWrites.Value == true ? "true" : "false"; + builder.AppendLine($" {boolValue}"); + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -130,6 +225,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterO { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(AccountImmutabilityPolicy)} does not support '{options.Format}' format."); } @@ -146,6 +243,8 @@ AccountImmutabilityPolicy IPersistableModel.Create(Bi using JsonDocument document = JsonDocument.Parse(data); return DeserializeAccountImmutabilityPolicy(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(AccountImmutabilityPolicy)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/BlobContainerData.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/BlobContainerData.Serialization.cs index 08df61599c254..0f816f067048b 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/BlobContainerData.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/BlobContainerData.Serialization.cs @@ -8,9 +8,12 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Linq; +using System.Text; using System.Text.Json; using Azure; using Azure.Core; +using Azure.ResourceManager; using Azure.ResourceManager.Models; using Azure.ResourceManager.Storage.Models; @@ -446,6 +449,435 @@ internal static BlobContainerData DeserializeBlobContainerData(JsonElement eleme return new BlobContainerData(id, name, type, systemData.Value, version.Value, Optional.ToNullable(deleted), Optional.ToNullable(deletedTime), Optional.ToNullable(remainingRetentionDays), defaultEncryptionScope.Value, Optional.ToNullable(denyEncryptionScopeOverride), Optional.ToNullable(publicAccess), Optional.ToNullable(lastModifiedTime), Optional.ToNullable(leaseStatus), Optional.ToNullable(leaseState), Optional.ToNullable(leaseDuration), Optional.ToDictionary(metadata), immutabilityPolicy.Value, legalHold.Value, Optional.ToNullable(hasLegalHold), Optional.ToNullable(hasImmutabilityPolicy), immutableStorageWithVersioning.Value, Optional.ToNullable(enableNfsV3RootSquash), Optional.ToNullable(enableNfsV3AllSquash), Optional.ToNullable(etag), serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Name), out propertyOverride); + if (Optional.IsDefined(Name) || hasPropertyOverride) + { + builder.Append(" name:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (Name.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{Name}'''"); + } + else + { + builder.AppendLine($" '{Name}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ETag), out propertyOverride); + if (Optional.IsDefined(ETag) || hasPropertyOverride) + { + builder.Append(" etag:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{ETag.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Id), out propertyOverride); + if (Optional.IsDefined(Id) || hasPropertyOverride) + { + builder.Append(" id:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{Id.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(SystemData), out propertyOverride); + if (Optional.IsDefined(SystemData) || hasPropertyOverride) + { + builder.Append(" systemData:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{SystemData.ToString()}'"); + } + } + + builder.Append(" properties:"); + builder.AppendLine(" {"); + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Version), out propertyOverride); + if (Optional.IsDefined(Version) || hasPropertyOverride) + { + builder.Append(" version:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (Version.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{Version}'''"); + } + else + { + builder.AppendLine($" '{Version}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(IsDeleted), out propertyOverride); + if (Optional.IsDefined(IsDeleted) || hasPropertyOverride) + { + builder.Append(" deleted:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var boolValue = IsDeleted.Value == true ? "true" : "false"; + builder.AppendLine($" {boolValue}"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(DeletedOn), out propertyOverride); + if (Optional.IsDefined(DeletedOn) || hasPropertyOverride) + { + builder.Append(" deletedTime:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var formattedDateTimeString = TypeFormatters.ToString(DeletedOn.Value, "o"); + builder.AppendLine($" '{formattedDateTimeString}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(RemainingRetentionDays), out propertyOverride); + if (Optional.IsDefined(RemainingRetentionDays) || hasPropertyOverride) + { + builder.Append(" remainingRetentionDays:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" {RemainingRetentionDays.Value}"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(DefaultEncryptionScope), out propertyOverride); + if (Optional.IsDefined(DefaultEncryptionScope) || hasPropertyOverride) + { + builder.Append(" defaultEncryptionScope:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (DefaultEncryptionScope.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{DefaultEncryptionScope}'''"); + } + else + { + builder.AppendLine($" '{DefaultEncryptionScope}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(PreventEncryptionScopeOverride), out propertyOverride); + if (Optional.IsDefined(PreventEncryptionScopeOverride) || hasPropertyOverride) + { + builder.Append(" denyEncryptionScopeOverride:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var boolValue = PreventEncryptionScopeOverride.Value == true ? "true" : "false"; + builder.AppendLine($" {boolValue}"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(PublicAccess), out propertyOverride); + if (Optional.IsDefined(PublicAccess) || hasPropertyOverride) + { + builder.Append(" publicAccess:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{PublicAccess.Value.ToSerialString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(LastModifiedOn), out propertyOverride); + if (Optional.IsDefined(LastModifiedOn) || hasPropertyOverride) + { + builder.Append(" lastModifiedTime:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var formattedDateTimeString = TypeFormatters.ToString(LastModifiedOn.Value, "o"); + builder.AppendLine($" '{formattedDateTimeString}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(LeaseStatus), out propertyOverride); + if (Optional.IsDefined(LeaseStatus) || hasPropertyOverride) + { + builder.Append(" leaseStatus:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{LeaseStatus.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(LeaseState), out propertyOverride); + if (Optional.IsDefined(LeaseState) || hasPropertyOverride) + { + builder.Append(" leaseState:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{LeaseState.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(LeaseDuration), out propertyOverride); + if (Optional.IsDefined(LeaseDuration) || hasPropertyOverride) + { + builder.Append(" leaseDuration:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{LeaseDuration.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Metadata), out propertyOverride); + if (Optional.IsCollectionDefined(Metadata) || hasPropertyOverride) + { + if (Metadata.Any() || hasPropertyOverride) + { + builder.Append(" metadata:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine(" {"); + foreach (var item in Metadata) + { + builder.Append($" {item.Key}:"); + if (item.Value == null) + { + builder.Append("null"); + continue; + } + if (item.Value.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{item.Value}'''"); + } + else + { + builder.AppendLine($" '{item.Value}'"); + } + } + builder.AppendLine(" }"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ImmutabilityPolicy), out propertyOverride); + if (Optional.IsDefined(ImmutabilityPolicy) || hasPropertyOverride) + { + builder.Append(" immutabilityPolicy:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, ImmutabilityPolicy, options, 4, false); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(LegalHold), out propertyOverride); + if (Optional.IsDefined(LegalHold) || hasPropertyOverride) + { + builder.Append(" legalHold:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, LegalHold, options, 4, false); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(HasLegalHold), out propertyOverride); + if (Optional.IsDefined(HasLegalHold) || hasPropertyOverride) + { + builder.Append(" hasLegalHold:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var boolValue = HasLegalHold.Value == true ? "true" : "false"; + builder.AppendLine($" {boolValue}"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(HasImmutabilityPolicy), out propertyOverride); + if (Optional.IsDefined(HasImmutabilityPolicy) || hasPropertyOverride) + { + builder.Append(" hasImmutabilityPolicy:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var boolValue = HasImmutabilityPolicy.Value == true ? "true" : "false"; + builder.AppendLine($" {boolValue}"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ImmutableStorageWithVersioning), out propertyOverride); + if (Optional.IsDefined(ImmutableStorageWithVersioning) || hasPropertyOverride) + { + builder.Append(" immutableStorageWithVersioning:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, ImmutableStorageWithVersioning, options, 4, false); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(EnableNfsV3RootSquash), out propertyOverride); + if (Optional.IsDefined(EnableNfsV3RootSquash) || hasPropertyOverride) + { + builder.Append(" enableNfsV3RootSquash:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var boolValue = EnableNfsV3RootSquash.Value == true ? "true" : "false"; + builder.AppendLine($" {boolValue}"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(EnableNfsV3AllSquash), out propertyOverride); + if (Optional.IsDefined(EnableNfsV3AllSquash) || hasPropertyOverride) + { + builder.Append(" enableNfsV3AllSquash:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var boolValue = EnableNfsV3AllSquash.Value == true ? "true" : "false"; + builder.AppendLine($" {boolValue}"); + } + } + + builder.AppendLine(" }"); + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -454,6 +886,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOptions o { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(BlobContainerData)} does not support '{options.Format}' format."); } @@ -470,6 +904,8 @@ BlobContainerData IPersistableModel.Create(BinaryData data, M using JsonDocument document = JsonDocument.Parse(data); return DeserializeBlobContainerData(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(BlobContainerData)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/BlobContainerImmutabilityPolicy.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/BlobContainerImmutabilityPolicy.Serialization.cs index 49369505bf5e0..7842e0741abb9 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/BlobContainerImmutabilityPolicy.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/BlobContainerImmutabilityPolicy.Serialization.cs @@ -8,9 +8,12 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Linq; +using System.Text; using System.Text.Json; using Azure; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -193,6 +196,153 @@ internal static BlobContainerImmutabilityPolicy DeserializeBlobContainerImmutabi return new BlobContainerImmutabilityPolicy(Optional.ToNullable(etag), Optional.ToList(updateHistory), Optional.ToNullable(immutabilityPeriodSinceCreationInDays), Optional.ToNullable(state), Optional.ToNullable(allowProtectedAppendWrites), Optional.ToNullable(allowProtectedAppendWritesAll), serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ETag), out propertyOverride); + if (Optional.IsDefined(ETag) || hasPropertyOverride) + { + builder.Append(" etag:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{ETag.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(UpdateHistory), out propertyOverride); + if (Optional.IsCollectionDefined(UpdateHistory) || hasPropertyOverride) + { + if (UpdateHistory.Any() || hasPropertyOverride) + { + builder.Append(" updateHistory:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine(" ["); + foreach (var item in UpdateHistory) + { + AppendChildObject(builder, item, options, 4, true); + } + builder.AppendLine(" ]"); + } + } + } + + builder.Append(" properties:"); + builder.AppendLine(" {"); + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ImmutabilityPeriodSinceCreationInDays), out propertyOverride); + if (Optional.IsDefined(ImmutabilityPeriodSinceCreationInDays) || hasPropertyOverride) + { + builder.Append(" immutabilityPeriodSinceCreationInDays:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" {ImmutabilityPeriodSinceCreationInDays.Value}"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(State), out propertyOverride); + if (Optional.IsDefined(State) || hasPropertyOverride) + { + builder.Append(" state:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{State.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(AllowProtectedAppendWrites), out propertyOverride); + if (Optional.IsDefined(AllowProtectedAppendWrites) || hasPropertyOverride) + { + builder.Append(" allowProtectedAppendWrites:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var boolValue = AllowProtectedAppendWrites.Value == true ? "true" : "false"; + builder.AppendLine($" {boolValue}"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(AllowProtectedAppendWritesAll), out propertyOverride); + if (Optional.IsDefined(AllowProtectedAppendWritesAll) || hasPropertyOverride) + { + builder.Append(" allowProtectedAppendWritesAll:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var boolValue = AllowProtectedAppendWritesAll.Value == true ? "true" : "false"; + builder.AppendLine($" {boolValue}"); + } + } + + builder.AppendLine(" }"); + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -201,6 +351,8 @@ BinaryData IPersistableModel.Write(ModelReaderW { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(BlobContainerImmutabilityPolicy)} does not support '{options.Format}' format."); } @@ -217,6 +369,8 @@ BlobContainerImmutabilityPolicy IPersistableModel propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Name), out propertyOverride); + if (Optional.IsDefined(Name) || hasPropertyOverride) + { + builder.Append(" name:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (Name.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{Name}'''"); + } + else + { + builder.AppendLine($" '{Name}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Id), out propertyOverride); + if (Optional.IsDefined(Id) || hasPropertyOverride) + { + builder.Append(" id:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{Id.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(SystemData), out propertyOverride); + if (Optional.IsDefined(SystemData) || hasPropertyOverride) + { + builder.Append(" systemData:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{SystemData.ToString()}'"); + } + } + + builder.Append(" properties:"); + builder.AppendLine(" {"); + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(LastModifiedOn), out propertyOverride); + if (Optional.IsDefined(LastModifiedOn) || hasPropertyOverride) + { + builder.Append(" lastModifiedTime:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var formattedDateTimeString = TypeFormatters.ToString(LastModifiedOn.Value, "o"); + builder.AppendLine($" '{formattedDateTimeString}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(PolicySchema), out propertyOverride); + if (Optional.IsDefined(PolicySchema) || hasPropertyOverride) + { + builder.Append(" policy:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, PolicySchema, options, 4, false); + } + } + + builder.AppendLine(" }"); + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -180,6 +314,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOpt { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(BlobInventoryPolicyData)} does not support '{options.Format}' format."); } @@ -196,6 +332,8 @@ BlobInventoryPolicyData IPersistableModel.Create(Binary using JsonDocument document = JsonDocument.Parse(data); return DeserializeBlobInventoryPolicyData(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(BlobInventoryPolicyData)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/BlobInventoryPolicyDefinition.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/BlobInventoryPolicyDefinition.Serialization.cs index d775a044566e2..06e328ee3d779 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/BlobInventoryPolicyDefinition.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/BlobInventoryPolicyDefinition.Serialization.cs @@ -8,8 +8,11 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Linq; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -134,6 +137,147 @@ internal static BlobInventoryPolicyDefinition DeserializeBlobInventoryPolicyDefi return new BlobInventoryPolicyDefinition(filters.Value, format, schedule, objectType, schemaFields, serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Filters), out propertyOverride); + if (Optional.IsDefined(Filters) || hasPropertyOverride) + { + builder.Append(" filters:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, Filters, options, 2, false); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Format), out propertyOverride); + if (Optional.IsDefined(Format) || hasPropertyOverride) + { + builder.Append(" format:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{Format.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Schedule), out propertyOverride); + if (Optional.IsDefined(Schedule) || hasPropertyOverride) + { + builder.Append(" schedule:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{Schedule.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ObjectType), out propertyOverride); + if (Optional.IsDefined(ObjectType) || hasPropertyOverride) + { + builder.Append(" objectType:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{ObjectType.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(SchemaFields), out propertyOverride); + if (Optional.IsCollectionDefined(SchemaFields) || hasPropertyOverride) + { + if (SchemaFields.Any() || hasPropertyOverride) + { + builder.Append(" schemaFields:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine(" ["); + foreach (var item in SchemaFields) + { + if (item == null) + { + builder.Append("null"); + continue; + } + if (item.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{item}'''"); + } + else + { + builder.AppendLine($" '{item}'"); + } + } + builder.AppendLine(" ]"); + } + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -142,6 +286,8 @@ BinaryData IPersistableModel.Write(ModelReaderWri { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(BlobInventoryPolicyDefinition)} does not support '{options.Format}' format."); } @@ -158,6 +304,8 @@ BlobInventoryPolicyDefinition IPersistableModel.C using JsonDocument document = JsonDocument.Parse(data); return DeserializeBlobInventoryPolicyDefinition(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(BlobInventoryPolicyDefinition)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/BlobInventoryPolicyFilter.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/BlobInventoryPolicyFilter.Serialization.cs index a06e4bf4283fe..ddd6abe13d427 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/BlobInventoryPolicyFilter.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/BlobInventoryPolicyFilter.Serialization.cs @@ -8,8 +8,11 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Linq; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -197,6 +200,206 @@ internal static BlobInventoryPolicyFilter DeserializeBlobInventoryPolicyFilter(J return new BlobInventoryPolicyFilter(Optional.ToList(prefixMatch), Optional.ToList(excludePrefix), Optional.ToList(blobTypes), Optional.ToNullable(includeBlobVersions), Optional.ToNullable(includeSnapshots), Optional.ToNullable(includeDeleted), serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(IncludePrefix), out propertyOverride); + if (Optional.IsCollectionDefined(IncludePrefix) || hasPropertyOverride) + { + if (IncludePrefix.Any() || hasPropertyOverride) + { + builder.Append(" prefixMatch:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine(" ["); + foreach (var item in IncludePrefix) + { + if (item == null) + { + builder.Append("null"); + continue; + } + if (item.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{item}'''"); + } + else + { + builder.AppendLine($" '{item}'"); + } + } + builder.AppendLine(" ]"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ExcludePrefix), out propertyOverride); + if (Optional.IsCollectionDefined(ExcludePrefix) || hasPropertyOverride) + { + if (ExcludePrefix.Any() || hasPropertyOverride) + { + builder.Append(" excludePrefix:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine(" ["); + foreach (var item in ExcludePrefix) + { + if (item == null) + { + builder.Append("null"); + continue; + } + if (item.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{item}'''"); + } + else + { + builder.AppendLine($" '{item}'"); + } + } + builder.AppendLine(" ]"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(BlobTypes), out propertyOverride); + if (Optional.IsCollectionDefined(BlobTypes) || hasPropertyOverride) + { + if (BlobTypes.Any() || hasPropertyOverride) + { + builder.Append(" blobTypes:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine(" ["); + foreach (var item in BlobTypes) + { + if (item == null) + { + builder.Append("null"); + continue; + } + if (item.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{item}'''"); + } + else + { + builder.AppendLine($" '{item}'"); + } + } + builder.AppendLine(" ]"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(IncludeBlobVersions), out propertyOverride); + if (Optional.IsDefined(IncludeBlobVersions) || hasPropertyOverride) + { + builder.Append(" includeBlobVersions:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var boolValue = IncludeBlobVersions.Value == true ? "true" : "false"; + builder.AppendLine($" {boolValue}"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(IncludeSnapshots), out propertyOverride); + if (Optional.IsDefined(IncludeSnapshots) || hasPropertyOverride) + { + builder.Append(" includeSnapshots:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var boolValue = IncludeSnapshots.Value == true ? "true" : "false"; + builder.AppendLine($" {boolValue}"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(IncludeDeleted), out propertyOverride); + if (Optional.IsDefined(IncludeDeleted) || hasPropertyOverride) + { + builder.Append(" includeDeleted:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var boolValue = IncludeDeleted.Value == true ? "true" : "false"; + builder.AppendLine($" {boolValue}"); + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -205,6 +408,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterO { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(BlobInventoryPolicyFilter)} does not support '{options.Format}' format."); } @@ -221,6 +426,8 @@ BlobInventoryPolicyFilter IPersistableModel.Create(Bi using JsonDocument document = JsonDocument.Parse(data); return DeserializeBlobInventoryPolicyFilter(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(BlobInventoryPolicyFilter)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/BlobInventoryPolicyRule.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/BlobInventoryPolicyRule.Serialization.cs index dbacad94ab9f8..8876fd6629092 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/BlobInventoryPolicyRule.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/BlobInventoryPolicyRule.Serialization.cs @@ -8,8 +8,10 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -109,6 +111,129 @@ internal static BlobInventoryPolicyRule DeserializeBlobInventoryPolicyRule(JsonE return new BlobInventoryPolicyRule(enabled, name, destination, definition, serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Name), out propertyOverride); + if (Optional.IsDefined(Name) || hasPropertyOverride) + { + builder.Append(" name:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (Name.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{Name}'''"); + } + else + { + builder.AppendLine($" '{Name}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(IsEnabled), out propertyOverride); + if (Optional.IsDefined(IsEnabled) || hasPropertyOverride) + { + builder.Append(" enabled:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var boolValue = IsEnabled == true ? "true" : "false"; + builder.AppendLine($" {boolValue}"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Destination), out propertyOverride); + if (Optional.IsDefined(Destination) || hasPropertyOverride) + { + builder.Append(" destination:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (Destination.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{Destination}'''"); + } + else + { + builder.AppendLine($" '{Destination}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Definition), out propertyOverride); + if (Optional.IsDefined(Definition) || hasPropertyOverride) + { + builder.Append(" definition:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, Definition, options, 2, false); + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -117,6 +242,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOpt { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(BlobInventoryPolicyRule)} does not support '{options.Format}' format."); } @@ -133,6 +260,8 @@ BlobInventoryPolicyRule IPersistableModel.Create(Binary using JsonDocument document = JsonDocument.Parse(data); return DeserializeBlobInventoryPolicyRule(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(BlobInventoryPolicyRule)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/BlobInventoryPolicySchema.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/BlobInventoryPolicySchema.Serialization.cs index 0305adcd77b1e..20a39aba602e8 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/BlobInventoryPolicySchema.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/BlobInventoryPolicySchema.Serialization.cs @@ -8,8 +8,11 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Linq; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -122,6 +125,115 @@ internal static BlobInventoryPolicySchema DeserializeBlobInventoryPolicySchema(J return new BlobInventoryPolicySchema(enabled, destination.Value, type, rules, serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(IsEnabled), out propertyOverride); + if (Optional.IsDefined(IsEnabled) || hasPropertyOverride) + { + builder.Append(" enabled:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var boolValue = IsEnabled == true ? "true" : "false"; + builder.AppendLine($" {boolValue}"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Destination), out propertyOverride); + if (Optional.IsDefined(Destination) || hasPropertyOverride) + { + builder.Append(" destination:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (Destination.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{Destination}'''"); + } + else + { + builder.AppendLine($" '{Destination}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Rules), out propertyOverride); + if (Optional.IsCollectionDefined(Rules) || hasPropertyOverride) + { + if (Rules.Any() || hasPropertyOverride) + { + builder.Append(" rules:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine(" ["); + foreach (var item in Rules) + { + AppendChildObject(builder, item, options, 4, true); + } + builder.AppendLine(" ]"); + } + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -130,6 +242,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterO { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(BlobInventoryPolicySchema)} does not support '{options.Format}' format."); } @@ -146,6 +260,8 @@ BlobInventoryPolicySchema IPersistableModel.Create(Bi using JsonDocument document = JsonDocument.Parse(data); return DeserializeBlobInventoryPolicySchema(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(BlobInventoryPolicySchema)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/BlobRestoreContent.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/BlobRestoreContent.Serialization.cs index 45556dcfeaf94..dabf57d79ca9c 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/BlobRestoreContent.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/BlobRestoreContent.Serialization.cs @@ -8,8 +8,11 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Linq; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -103,6 +106,93 @@ internal static BlobRestoreContent DeserializeBlobRestoreContent(JsonElement ele return new BlobRestoreContent(timetoRestore, blobRanges, serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(TimeToRestore), out propertyOverride); + if (Optional.IsDefined(TimeToRestore) || hasPropertyOverride) + { + builder.Append(" timetoRestore:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var formattedDateTimeString = TypeFormatters.ToString(TimeToRestore, "o"); + builder.AppendLine($" '{formattedDateTimeString}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(BlobRanges), out propertyOverride); + if (Optional.IsCollectionDefined(BlobRanges) || hasPropertyOverride) + { + if (BlobRanges.Any() || hasPropertyOverride) + { + builder.Append(" blobRanges:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine(" ["); + foreach (var item in BlobRanges) + { + AppendChildObject(builder, item, options, 4, true); + } + builder.AppendLine(" ]"); + } + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -111,6 +201,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOptions { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(BlobRestoreContent)} does not support '{options.Format}' format."); } @@ -127,6 +219,8 @@ BlobRestoreContent IPersistableModel.Create(BinaryData data, using JsonDocument document = JsonDocument.Parse(data); return DeserializeBlobRestoreContent(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(BlobRestoreContent)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/BlobRestoreRange.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/BlobRestoreRange.Serialization.cs index 2dab09d4ee169..c0fabfb9bcaf0 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/BlobRestoreRange.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/BlobRestoreRange.Serialization.cs @@ -8,8 +8,10 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -93,6 +95,100 @@ internal static BlobRestoreRange DeserializeBlobRestoreRange(JsonElement element return new BlobRestoreRange(startRange, endRange, serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(StartRange), out propertyOverride); + if (Optional.IsDefined(StartRange) || hasPropertyOverride) + { + builder.Append(" startRange:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (StartRange.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{StartRange}'''"); + } + else + { + builder.AppendLine($" '{StartRange}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(EndRange), out propertyOverride); + if (Optional.IsDefined(EndRange) || hasPropertyOverride) + { + builder.Append(" endRange:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (EndRange.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{EndRange}'''"); + } + else + { + builder.AppendLine($" '{EndRange}'"); + } + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -101,6 +197,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOptions op { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(BlobRestoreRange)} does not support '{options.Format}' format."); } @@ -117,6 +215,8 @@ BlobRestoreRange IPersistableModel.Create(BinaryData data, Mod using JsonDocument document = JsonDocument.Parse(data); return DeserializeBlobRestoreRange(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(BlobRestoreRange)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/BlobRestoreStatus.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/BlobRestoreStatus.Serialization.cs index 951f9825cdd4d..b8131848082ba 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/BlobRestoreStatus.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/BlobRestoreStatus.Serialization.cs @@ -8,8 +8,10 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -129,6 +131,128 @@ internal static BlobRestoreStatus DeserializeBlobRestoreStatus(JsonElement eleme return new BlobRestoreStatus(Optional.ToNullable(status), failureReason.Value, restoreId.Value, parameters.Value, serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Status), out propertyOverride); + if (Optional.IsDefined(Status) || hasPropertyOverride) + { + builder.Append(" status:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{Status.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(FailureReason), out propertyOverride); + if (Optional.IsDefined(FailureReason) || hasPropertyOverride) + { + builder.Append(" failureReason:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (FailureReason.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{FailureReason}'''"); + } + else + { + builder.AppendLine($" '{FailureReason}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(RestoreId), out propertyOverride); + if (Optional.IsDefined(RestoreId) || hasPropertyOverride) + { + builder.Append(" restoreId:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (RestoreId.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{RestoreId}'''"); + } + else + { + builder.AppendLine($" '{RestoreId}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Parameters), out propertyOverride); + if (Optional.IsDefined(Parameters) || hasPropertyOverride) + { + builder.Append(" parameters:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, Parameters, options, 2, false); + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -137,6 +261,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOptions o { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(BlobRestoreStatus)} does not support '{options.Format}' format."); } @@ -153,6 +279,8 @@ BlobRestoreStatus IPersistableModel.Create(BinaryData data, M using JsonDocument document = JsonDocument.Parse(data); return DeserializeBlobRestoreStatus(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(BlobRestoreStatus)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/BlobServiceChangeFeed.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/BlobServiceChangeFeed.Serialization.cs index 0efe0c3d3674d..9aec5c42c27c7 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/BlobServiceChangeFeed.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/BlobServiceChangeFeed.Serialization.cs @@ -8,8 +8,10 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -107,6 +109,85 @@ internal static BlobServiceChangeFeed DeserializeBlobServiceChangeFeed(JsonEleme return new BlobServiceChangeFeed(Optional.ToNullable(enabled), Optional.ToNullable(retentionInDays), serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(IsEnabled), out propertyOverride); + if (Optional.IsDefined(IsEnabled) || hasPropertyOverride) + { + builder.Append(" enabled:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var boolValue = IsEnabled.Value == true ? "true" : "false"; + builder.AppendLine($" {boolValue}"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(RetentionInDays), out propertyOverride); + if (Optional.IsDefined(RetentionInDays) || hasPropertyOverride) + { + builder.Append(" retentionInDays:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" {RetentionInDays.Value}"); + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -115,6 +196,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOptio { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(BlobServiceChangeFeed)} does not support '{options.Format}' format."); } @@ -131,6 +214,8 @@ BlobServiceChangeFeed IPersistableModel.Create(BinaryData using JsonDocument document = JsonDocument.Parse(data); return DeserializeBlobServiceChangeFeed(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(BlobServiceChangeFeed)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/BlobServiceData.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/BlobServiceData.Serialization.cs index fd0dd4fddaae2..c3b8a30858ed6 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/BlobServiceData.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/BlobServiceData.Serialization.cs @@ -8,8 +8,10 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; using Azure.ResourceManager.Models; using Azure.ResourceManager.Storage.Models; @@ -288,6 +290,259 @@ internal static BlobServiceData DeserializeBlobServiceData(JsonElement element, return new BlobServiceData(id, name, type, systemData.Value, sku.Value, cors.Value, defaultServiceVersion.Value, deleteRetentionPolicy.Value, Optional.ToNullable(isVersioningEnabled), Optional.ToNullable(automaticSnapshotPolicyEnabled), changeFeed.Value, restorePolicy.Value, containerDeleteRetentionPolicy.Value, lastAccessTimeTrackingPolicy.Value, serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Name), out propertyOverride); + if (Optional.IsDefined(Name) || hasPropertyOverride) + { + builder.Append(" name:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (Name.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{Name}'''"); + } + else + { + builder.AppendLine($" '{Name}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Sku), out propertyOverride); + if (Optional.IsDefined(Sku) || hasPropertyOverride) + { + builder.Append(" sku:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, Sku, options, 2, false); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Id), out propertyOverride); + if (Optional.IsDefined(Id) || hasPropertyOverride) + { + builder.Append(" id:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{Id.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(SystemData), out propertyOverride); + if (Optional.IsDefined(SystemData) || hasPropertyOverride) + { + builder.Append(" systemData:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{SystemData.ToString()}'"); + } + } + + builder.Append(" properties:"); + builder.AppendLine(" {"); + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Cors), out propertyOverride); + if (Optional.IsDefined(Cors) || hasPropertyOverride) + { + builder.Append(" cors:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, Cors, options, 4, false); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(DefaultServiceVersion), out propertyOverride); + if (Optional.IsDefined(DefaultServiceVersion) || hasPropertyOverride) + { + builder.Append(" defaultServiceVersion:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (DefaultServiceVersion.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{DefaultServiceVersion}'''"); + } + else + { + builder.AppendLine($" '{DefaultServiceVersion}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(DeleteRetentionPolicy), out propertyOverride); + if (Optional.IsDefined(DeleteRetentionPolicy) || hasPropertyOverride) + { + builder.Append(" deleteRetentionPolicy:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, DeleteRetentionPolicy, options, 4, false); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(IsVersioningEnabled), out propertyOverride); + if (Optional.IsDefined(IsVersioningEnabled) || hasPropertyOverride) + { + builder.Append(" isVersioningEnabled:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var boolValue = IsVersioningEnabled.Value == true ? "true" : "false"; + builder.AppendLine($" {boolValue}"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(IsAutomaticSnapshotPolicyEnabled), out propertyOverride); + if (Optional.IsDefined(IsAutomaticSnapshotPolicyEnabled) || hasPropertyOverride) + { + builder.Append(" automaticSnapshotPolicyEnabled:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var boolValue = IsAutomaticSnapshotPolicyEnabled.Value == true ? "true" : "false"; + builder.AppendLine($" {boolValue}"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ChangeFeed), out propertyOverride); + if (Optional.IsDefined(ChangeFeed) || hasPropertyOverride) + { + builder.Append(" changeFeed:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, ChangeFeed, options, 4, false); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(RestorePolicy), out propertyOverride); + if (Optional.IsDefined(RestorePolicy) || hasPropertyOverride) + { + builder.Append(" restorePolicy:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, RestorePolicy, options, 4, false); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ContainerDeleteRetentionPolicy), out propertyOverride); + if (Optional.IsDefined(ContainerDeleteRetentionPolicy) || hasPropertyOverride) + { + builder.Append(" containerDeleteRetentionPolicy:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, ContainerDeleteRetentionPolicy, options, 4, false); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(LastAccessTimeTrackingPolicy), out propertyOverride); + if (Optional.IsDefined(LastAccessTimeTrackingPolicy) || hasPropertyOverride) + { + builder.Append(" lastAccessTimeTrackingPolicy:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, LastAccessTimeTrackingPolicy, options, 4, false); + } + } + + builder.AppendLine(" }"); + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -296,6 +551,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOptions opt { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(BlobServiceData)} does not support '{options.Format}' format."); } @@ -312,6 +569,8 @@ BlobServiceData IPersistableModel.Create(BinaryData data, Model using JsonDocument document = JsonDocument.Parse(data); return DeserializeBlobServiceData(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(BlobServiceData)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/BlobServiceItems.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/BlobServiceItems.Serialization.cs index bf9070d741f8c..069f1476b4a1b 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/BlobServiceItems.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/BlobServiceItems.Serialization.cs @@ -8,8 +8,11 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Linq; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; using Azure.ResourceManager.Storage; namespace Azure.ResourceManager.Storage.Models @@ -103,6 +106,78 @@ internal static BlobServiceItems DeserializeBlobServiceItems(JsonElement element return new BlobServiceItems(Optional.ToList(value), serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Value), out propertyOverride); + if (Optional.IsCollectionDefined(Value) || hasPropertyOverride) + { + if (Value.Any() || hasPropertyOverride) + { + builder.Append(" value:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine(" ["); + foreach (var item in Value) + { + AppendChildObject(builder, item, options, 4, true); + } + builder.AppendLine(" ]"); + } + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -111,6 +186,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOptions op { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(BlobServiceItems)} does not support '{options.Format}' format."); } @@ -127,6 +204,8 @@ BlobServiceItems IPersistableModel.Create(BinaryData data, Mod using JsonDocument document = JsonDocument.Parse(data); return DeserializeBlobServiceItems(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(BlobServiceItems)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/DateAfterCreation.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/DateAfterCreation.Serialization.cs index 684b4f11ae421..4817890031cbb 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/DateAfterCreation.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/DateAfterCreation.Serialization.cs @@ -8,8 +8,10 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -100,6 +102,84 @@ internal static DateAfterCreation DeserializeDateAfterCreation(JsonElement eleme return new DateAfterCreation(daysAfterCreationGreaterThan, Optional.ToNullable(daysAfterLastTierChangeGreaterThan), serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(DaysAfterCreationGreaterThan), out propertyOverride); + if (Optional.IsDefined(DaysAfterCreationGreaterThan) || hasPropertyOverride) + { + builder.Append(" daysAfterCreationGreaterThan:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{DaysAfterCreationGreaterThan.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(DaysAfterLastTierChangeGreaterThan), out propertyOverride); + if (Optional.IsDefined(DaysAfterLastTierChangeGreaterThan) || hasPropertyOverride) + { + builder.Append(" daysAfterLastTierChangeGreaterThan:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{DaysAfterLastTierChangeGreaterThan.Value.ToString()}'"); + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -108,6 +188,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOptions o { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(DateAfterCreation)} does not support '{options.Format}' format."); } @@ -124,6 +206,8 @@ DateAfterCreation IPersistableModel.Create(BinaryData data, M using JsonDocument document = JsonDocument.Parse(data); return DeserializeDateAfterCreation(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(DateAfterCreation)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/DateAfterModification.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/DateAfterModification.Serialization.cs index 247a004bcec50..757ac04feb003 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/DateAfterModification.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/DateAfterModification.Serialization.cs @@ -8,8 +8,10 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -137,6 +139,112 @@ internal static DateAfterModification DeserializeDateAfterModification(JsonEleme return new DateAfterModification(Optional.ToNullable(daysAfterModificationGreaterThan), Optional.ToNullable(daysAfterLastAccessTimeGreaterThan), Optional.ToNullable(daysAfterLastTierChangeGreaterThan), Optional.ToNullable(daysAfterCreationGreaterThan), serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(DaysAfterModificationGreaterThan), out propertyOverride); + if (Optional.IsDefined(DaysAfterModificationGreaterThan) || hasPropertyOverride) + { + builder.Append(" daysAfterModificationGreaterThan:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{DaysAfterModificationGreaterThan.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(DaysAfterLastAccessTimeGreaterThan), out propertyOverride); + if (Optional.IsDefined(DaysAfterLastAccessTimeGreaterThan) || hasPropertyOverride) + { + builder.Append(" daysAfterLastAccessTimeGreaterThan:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{DaysAfterLastAccessTimeGreaterThan.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(DaysAfterLastTierChangeGreaterThan), out propertyOverride); + if (Optional.IsDefined(DaysAfterLastTierChangeGreaterThan) || hasPropertyOverride) + { + builder.Append(" daysAfterLastTierChangeGreaterThan:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{DaysAfterLastTierChangeGreaterThan.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(DaysAfterCreationGreaterThan), out propertyOverride); + if (Optional.IsDefined(DaysAfterCreationGreaterThan) || hasPropertyOverride) + { + builder.Append(" daysAfterCreationGreaterThan:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{DaysAfterCreationGreaterThan.Value.ToString()}'"); + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -145,6 +253,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOptio { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(DateAfterModification)} does not support '{options.Format}' format."); } @@ -161,6 +271,8 @@ DateAfterModification IPersistableModel.Create(BinaryData using JsonDocument document = JsonDocument.Parse(data); return DeserializeDateAfterModification(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(DateAfterModification)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/DeleteRetentionPolicy.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/DeleteRetentionPolicy.Serialization.cs index 7f8c26c0fb373..7422aaa436f0f 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/DeleteRetentionPolicy.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/DeleteRetentionPolicy.Serialization.cs @@ -8,8 +8,10 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -122,6 +124,100 @@ internal static DeleteRetentionPolicy DeserializeDeleteRetentionPolicy(JsonEleme return new DeleteRetentionPolicy(Optional.ToNullable(enabled), Optional.ToNullable(days), Optional.ToNullable(allowPermanentDelete), serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(IsEnabled), out propertyOverride); + if (Optional.IsDefined(IsEnabled) || hasPropertyOverride) + { + builder.Append(" enabled:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var boolValue = IsEnabled.Value == true ? "true" : "false"; + builder.AppendLine($" {boolValue}"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Days), out propertyOverride); + if (Optional.IsDefined(Days) || hasPropertyOverride) + { + builder.Append(" days:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" {Days.Value}"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(AllowPermanentDelete), out propertyOverride); + if (Optional.IsDefined(AllowPermanentDelete) || hasPropertyOverride) + { + builder.Append(" allowPermanentDelete:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var boolValue = AllowPermanentDelete.Value == true ? "true" : "false"; + builder.AppendLine($" {boolValue}"); + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -130,6 +226,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOptio { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(DeleteRetentionPolicy)} does not support '{options.Format}' format."); } @@ -146,6 +244,8 @@ DeleteRetentionPolicy IPersistableModel.Create(BinaryData using JsonDocument document = JsonDocument.Parse(data); return DeserializeDeleteRetentionPolicy(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(DeleteRetentionPolicy)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/DeletedAccountData.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/DeletedAccountData.Serialization.cs index aa786c844f6d6..05a50007bf8f3 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/DeletedAccountData.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/DeletedAccountData.Serialization.cs @@ -8,8 +8,10 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; using Azure.ResourceManager.Models; namespace Azure.ResourceManager.Storage @@ -212,6 +214,189 @@ internal static DeletedAccountData DeserializeDeletedAccountData(JsonElement ele return new DeletedAccountData(id, name, type, systemData.Value, storageAccountResourceId.Value, Optional.ToNullable(location), restoreReference.Value, Optional.ToNullable(creationTime), Optional.ToNullable(deletionTime), serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Name), out propertyOverride); + if (Optional.IsDefined(Name) || hasPropertyOverride) + { + builder.Append(" name:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (Name.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{Name}'''"); + } + else + { + builder.AppendLine($" '{Name}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Id), out propertyOverride); + if (Optional.IsDefined(Id) || hasPropertyOverride) + { + builder.Append(" id:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{Id.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(SystemData), out propertyOverride); + if (Optional.IsDefined(SystemData) || hasPropertyOverride) + { + builder.Append(" systemData:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{SystemData.ToString()}'"); + } + } + + builder.Append(" properties:"); + builder.AppendLine(" {"); + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(StorageAccountResourceId), out propertyOverride); + if (Optional.IsDefined(StorageAccountResourceId) || hasPropertyOverride) + { + builder.Append(" storageAccountResourceId:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{StorageAccountResourceId.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Location), out propertyOverride); + if (Optional.IsDefined(Location) || hasPropertyOverride) + { + builder.Append(" location:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{Location.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(RestoreReference), out propertyOverride); + if (Optional.IsDefined(RestoreReference) || hasPropertyOverride) + { + builder.Append(" restoreReference:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (RestoreReference.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{RestoreReference}'''"); + } + else + { + builder.AppendLine($" '{RestoreReference}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(CreatedOn), out propertyOverride); + if (Optional.IsDefined(CreatedOn) || hasPropertyOverride) + { + builder.Append(" creationTime:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var formattedDateTimeString = TypeFormatters.ToString(CreatedOn.Value, "o"); + builder.AppendLine($" '{formattedDateTimeString}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(DeletedOn), out propertyOverride); + if (Optional.IsDefined(DeletedOn) || hasPropertyOverride) + { + builder.Append(" deletionTime:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var formattedDateTimeString = TypeFormatters.ToString(DeletedOn.Value, "o"); + builder.AppendLine($" '{formattedDateTimeString}'"); + } + } + + builder.AppendLine(" }"); + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -220,6 +405,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOptions { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(DeletedAccountData)} does not support '{options.Format}' format."); } @@ -236,6 +423,8 @@ DeletedAccountData IPersistableModel.Create(BinaryData data, using JsonDocument document = JsonDocument.Parse(data); return DeserializeDeletedAccountData(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(DeletedAccountData)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/DeletedAccountListResult.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/DeletedAccountListResult.Serialization.cs index bf5ab5284174c..ec9ec829e4feb 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/DeletedAccountListResult.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/DeletedAccountListResult.Serialization.cs @@ -8,8 +8,11 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Linq; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; using Azure.ResourceManager.Storage; namespace Azure.ResourceManager.Storage.Models @@ -114,6 +117,100 @@ internal static DeletedAccountListResult DeserializeDeletedAccountListResult(Jso return new DeletedAccountListResult(Optional.ToList(value), nextLink.Value, serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Value), out propertyOverride); + if (Optional.IsCollectionDefined(Value) || hasPropertyOverride) + { + if (Value.Any() || hasPropertyOverride) + { + builder.Append(" value:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine(" ["); + foreach (var item in Value) + { + AppendChildObject(builder, item, options, 4, true); + } + builder.AppendLine(" ]"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(NextLink), out propertyOverride); + if (Optional.IsDefined(NextLink) || hasPropertyOverride) + { + builder.Append(" nextLink:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (NextLink.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{NextLink}'''"); + } + else + { + builder.AppendLine($" '{NextLink}'"); + } + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -122,6 +219,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOp { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(DeletedAccountListResult)} does not support '{options.Format}' format."); } @@ -138,6 +237,8 @@ DeletedAccountListResult IPersistableModel.Create(Bina using JsonDocument document = JsonDocument.Parse(data); return DeserializeDeletedAccountListResult(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(DeletedAccountListResult)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/EncryptionScopeData.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/EncryptionScopeData.Serialization.cs index ea69dbd4edd0b..7c5abe7115229 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/EncryptionScopeData.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/EncryptionScopeData.Serialization.cs @@ -8,8 +8,10 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; using Azure.ResourceManager.Models; using Azure.ResourceManager.Storage.Models; @@ -232,6 +234,196 @@ internal static EncryptionScopeData DeserializeEncryptionScopeData(JsonElement e return new EncryptionScopeData(id, name, type, systemData.Value, Optional.ToNullable(source), Optional.ToNullable(state), Optional.ToNullable(creationTime), Optional.ToNullable(lastModifiedTime), keyVaultProperties.Value, Optional.ToNullable(requireInfrastructureEncryption), serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Name), out propertyOverride); + if (Optional.IsDefined(Name) || hasPropertyOverride) + { + builder.Append(" name:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (Name.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{Name}'''"); + } + else + { + builder.AppendLine($" '{Name}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Id), out propertyOverride); + if (Optional.IsDefined(Id) || hasPropertyOverride) + { + builder.Append(" id:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{Id.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(SystemData), out propertyOverride); + if (Optional.IsDefined(SystemData) || hasPropertyOverride) + { + builder.Append(" systemData:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{SystemData.ToString()}'"); + } + } + + builder.Append(" properties:"); + builder.AppendLine(" {"); + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Source), out propertyOverride); + if (Optional.IsDefined(Source) || hasPropertyOverride) + { + builder.Append(" source:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{Source.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(State), out propertyOverride); + if (Optional.IsDefined(State) || hasPropertyOverride) + { + builder.Append(" state:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{State.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(CreatedOn), out propertyOverride); + if (Optional.IsDefined(CreatedOn) || hasPropertyOverride) + { + builder.Append(" creationTime:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var formattedDateTimeString = TypeFormatters.ToString(CreatedOn.Value, "o"); + builder.AppendLine($" '{formattedDateTimeString}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(LastModifiedOn), out propertyOverride); + if (Optional.IsDefined(LastModifiedOn) || hasPropertyOverride) + { + builder.Append(" lastModifiedTime:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var formattedDateTimeString = TypeFormatters.ToString(LastModifiedOn.Value, "o"); + builder.AppendLine($" '{formattedDateTimeString}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(KeyVaultProperties), out propertyOverride); + if (Optional.IsDefined(KeyVaultProperties) || hasPropertyOverride) + { + builder.Append(" keyVaultProperties:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, KeyVaultProperties, options, 4, false); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(RequireInfrastructureEncryption), out propertyOverride); + if (Optional.IsDefined(RequireInfrastructureEncryption) || hasPropertyOverride) + { + builder.Append(" requireInfrastructureEncryption:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var boolValue = RequireInfrastructureEncryption.Value == true ? "true" : "false"; + builder.AppendLine($" {boolValue}"); + } + } + + builder.AppendLine(" }"); + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -240,6 +432,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOptions { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(EncryptionScopeData)} does not support '{options.Format}' format."); } @@ -256,6 +450,8 @@ EncryptionScopeData IPersistableModel.Create(BinaryData dat using JsonDocument document = JsonDocument.Parse(data); return DeserializeEncryptionScopeData(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(EncryptionScopeData)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/EncryptionScopeKeyVaultProperties.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/EncryptionScopeKeyVaultProperties.Serialization.cs index e60a5c040aab9..e14a4c1974d68 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/EncryptionScopeKeyVaultProperties.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/EncryptionScopeKeyVaultProperties.Serialization.cs @@ -8,8 +8,10 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -118,6 +120,107 @@ internal static EncryptionScopeKeyVaultProperties DeserializeEncryptionScopeKeyV return new EncryptionScopeKeyVaultProperties(keyUri.Value, currentVersionedKeyIdentifier.Value, Optional.ToNullable(lastKeyRotationTimestamp), serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(KeyUri), out propertyOverride); + if (Optional.IsDefined(KeyUri) || hasPropertyOverride) + { + builder.Append(" keyUri:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{KeyUri.AbsoluteUri}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(CurrentVersionedKeyIdentifier), out propertyOverride); + if (Optional.IsDefined(CurrentVersionedKeyIdentifier) || hasPropertyOverride) + { + builder.Append(" currentVersionedKeyIdentifier:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (CurrentVersionedKeyIdentifier.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{CurrentVersionedKeyIdentifier}'''"); + } + else + { + builder.AppendLine($" '{CurrentVersionedKeyIdentifier}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(LastKeyRotationTimestamp), out propertyOverride); + if (Optional.IsDefined(LastKeyRotationTimestamp) || hasPropertyOverride) + { + builder.Append(" lastKeyRotationTimestamp:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var formattedDateTimeString = TypeFormatters.ToString(LastKeyRotationTimestamp.Value, "o"); + builder.AppendLine($" '{formattedDateTimeString}'"); + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -126,6 +229,8 @@ BinaryData IPersistableModel.Write(ModelReade { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(EncryptionScopeKeyVaultProperties)} does not support '{options.Format}' format."); } @@ -142,6 +247,8 @@ EncryptionScopeKeyVaultProperties IPersistableModel propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Value), out propertyOverride); + if (Optional.IsCollectionDefined(Value) || hasPropertyOverride) + { + if (Value.Any() || hasPropertyOverride) + { + builder.Append(" value:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine(" ["); + foreach (var item in Value) + { + AppendChildObject(builder, item, options, 4, true); + } + builder.AppendLine(" ]"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(NextLink), out propertyOverride); + if (Optional.IsDefined(NextLink) || hasPropertyOverride) + { + builder.Append(" nextLink:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (NextLink.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{NextLink}'''"); + } + else + { + builder.AppendLine($" '{NextLink}'"); + } + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -122,6 +219,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterO { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(EncryptionScopeListResult)} does not support '{options.Format}' format."); } @@ -138,6 +237,8 @@ EncryptionScopeListResult IPersistableModel.Create(Bi using JsonDocument document = JsonDocument.Parse(data); return DeserializeEncryptionScopeListResult(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(EncryptionScopeListResult)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/FileServiceData.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/FileServiceData.Serialization.cs index a9389681748c0..c7283c67380d0 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/FileServiceData.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/FileServiceData.Serialization.cs @@ -8,8 +8,10 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; using Azure.ResourceManager.Models; using Azure.ResourceManager.Storage.Models; @@ -202,6 +204,165 @@ internal static FileServiceData DeserializeFileServiceData(JsonElement element, return new FileServiceData(id, name, type, systemData.Value, sku.Value, cors.Value, shareDeleteRetentionPolicy.Value, protocolSettings.Value, serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Name), out propertyOverride); + if (Optional.IsDefined(Name) || hasPropertyOverride) + { + builder.Append(" name:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (Name.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{Name}'''"); + } + else + { + builder.AppendLine($" '{Name}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Sku), out propertyOverride); + if (Optional.IsDefined(Sku) || hasPropertyOverride) + { + builder.Append(" sku:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, Sku, options, 2, false); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Id), out propertyOverride); + if (Optional.IsDefined(Id) || hasPropertyOverride) + { + builder.Append(" id:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{Id.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(SystemData), out propertyOverride); + if (Optional.IsDefined(SystemData) || hasPropertyOverride) + { + builder.Append(" systemData:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{SystemData.ToString()}'"); + } + } + + builder.Append(" properties:"); + builder.AppendLine(" {"); + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Cors), out propertyOverride); + if (Optional.IsDefined(Cors) || hasPropertyOverride) + { + builder.Append(" cors:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, Cors, options, 4, false); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ShareDeleteRetentionPolicy), out propertyOverride); + if (Optional.IsDefined(ShareDeleteRetentionPolicy) || hasPropertyOverride) + { + builder.Append(" shareDeleteRetentionPolicy:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, ShareDeleteRetentionPolicy, options, 4, false); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ProtocolSettings), out propertyOverride); + if (Optional.IsDefined(ProtocolSettings) || hasPropertyOverride) + { + builder.Append(" protocolSettings:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, ProtocolSettings, options, 4, false); + } + } + + builder.AppendLine(" }"); + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -210,6 +371,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOptions opt { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(FileServiceData)} does not support '{options.Format}' format."); } @@ -226,6 +389,8 @@ FileServiceData IPersistableModel.Create(BinaryData data, Model using JsonDocument document = JsonDocument.Parse(data); return DeserializeFileServiceData(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(FileServiceData)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/FileServiceItems.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/FileServiceItems.Serialization.cs index 70799db542eb0..4389b4802206d 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/FileServiceItems.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/FileServiceItems.Serialization.cs @@ -8,8 +8,11 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Linq; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; using Azure.ResourceManager.Storage; namespace Azure.ResourceManager.Storage.Models @@ -103,6 +106,78 @@ internal static FileServiceItems DeserializeFileServiceItems(JsonElement element return new FileServiceItems(Optional.ToList(value), serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Value), out propertyOverride); + if (Optional.IsCollectionDefined(Value) || hasPropertyOverride) + { + if (Value.Any() || hasPropertyOverride) + { + builder.Append(" value:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine(" ["); + foreach (var item in Value) + { + AppendChildObject(builder, item, options, 4, true); + } + builder.AppendLine(" ]"); + } + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -111,6 +186,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOptions op { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(FileServiceItems)} does not support '{options.Format}' format."); } @@ -127,6 +204,8 @@ FileServiceItems IPersistableModel.Create(BinaryData data, Mod using JsonDocument document = JsonDocument.Parse(data); return DeserializeFileServiceItems(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(FileServiceItems)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/FileShareData.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/FileShareData.Serialization.cs index 909e1b9b55d4c..f53c2bcf8bb82 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/FileShareData.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/FileShareData.Serialization.cs @@ -8,9 +8,12 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Linq; +using System.Text; using System.Text.Json; using Azure; using Azure.Core; +using Azure.ResourceManager; using Azure.ResourceManager.Models; using Azure.ResourceManager.Storage.Models; @@ -441,6 +444,426 @@ internal static FileShareData DeserializeFileShareData(JsonElement element, Mode return new FileShareData(id, name, type, systemData.Value, Optional.ToNullable(lastModifiedTime), Optional.ToDictionary(metadata), Optional.ToNullable(shareQuota), Optional.ToNullable(enabledProtocols), Optional.ToNullable(rootSquash), version.Value, Optional.ToNullable(deleted), Optional.ToNullable(deletedTime), Optional.ToNullable(remainingRetentionDays), Optional.ToNullable(accessTier), Optional.ToNullable(accessTierChangeTime), accessTierStatus.Value, Optional.ToNullable(shareUsageBytes), Optional.ToNullable(leaseStatus), Optional.ToNullable(leaseState), Optional.ToNullable(leaseDuration), Optional.ToList(signedIdentifiers), Optional.ToNullable(snapshotTime), Optional.ToNullable(etag), serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Name), out propertyOverride); + if (Optional.IsDefined(Name) || hasPropertyOverride) + { + builder.Append(" name:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (Name.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{Name}'''"); + } + else + { + builder.AppendLine($" '{Name}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ETag), out propertyOverride); + if (Optional.IsDefined(ETag) || hasPropertyOverride) + { + builder.Append(" etag:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{ETag.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Id), out propertyOverride); + if (Optional.IsDefined(Id) || hasPropertyOverride) + { + builder.Append(" id:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{Id.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(SystemData), out propertyOverride); + if (Optional.IsDefined(SystemData) || hasPropertyOverride) + { + builder.Append(" systemData:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{SystemData.ToString()}'"); + } + } + + builder.Append(" properties:"); + builder.AppendLine(" {"); + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(LastModifiedOn), out propertyOverride); + if (Optional.IsDefined(LastModifiedOn) || hasPropertyOverride) + { + builder.Append(" lastModifiedTime:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var formattedDateTimeString = TypeFormatters.ToString(LastModifiedOn.Value, "o"); + builder.AppendLine($" '{formattedDateTimeString}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Metadata), out propertyOverride); + if (Optional.IsCollectionDefined(Metadata) || hasPropertyOverride) + { + if (Metadata.Any() || hasPropertyOverride) + { + builder.Append(" metadata:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine(" {"); + foreach (var item in Metadata) + { + builder.Append($" {item.Key}:"); + if (item.Value == null) + { + builder.Append("null"); + continue; + } + if (item.Value.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{item.Value}'''"); + } + else + { + builder.AppendLine($" '{item.Value}'"); + } + } + builder.AppendLine(" }"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ShareQuota), out propertyOverride); + if (Optional.IsDefined(ShareQuota) || hasPropertyOverride) + { + builder.Append(" shareQuota:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" {ShareQuota.Value}"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(EnabledProtocol), out propertyOverride); + if (Optional.IsDefined(EnabledProtocol) || hasPropertyOverride) + { + builder.Append(" enabledProtocols:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{EnabledProtocol.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(RootSquash), out propertyOverride); + if (Optional.IsDefined(RootSquash) || hasPropertyOverride) + { + builder.Append(" rootSquash:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{RootSquash.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Version), out propertyOverride); + if (Optional.IsDefined(Version) || hasPropertyOverride) + { + builder.Append(" version:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (Version.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{Version}'''"); + } + else + { + builder.AppendLine($" '{Version}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(IsDeleted), out propertyOverride); + if (Optional.IsDefined(IsDeleted) || hasPropertyOverride) + { + builder.Append(" deleted:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var boolValue = IsDeleted.Value == true ? "true" : "false"; + builder.AppendLine($" {boolValue}"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(DeletedOn), out propertyOverride); + if (Optional.IsDefined(DeletedOn) || hasPropertyOverride) + { + builder.Append(" deletedTime:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var formattedDateTimeString = TypeFormatters.ToString(DeletedOn.Value, "o"); + builder.AppendLine($" '{formattedDateTimeString}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(RemainingRetentionDays), out propertyOverride); + if (Optional.IsDefined(RemainingRetentionDays) || hasPropertyOverride) + { + builder.Append(" remainingRetentionDays:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" {RemainingRetentionDays.Value}"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(AccessTier), out propertyOverride); + if (Optional.IsDefined(AccessTier) || hasPropertyOverride) + { + builder.Append(" accessTier:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{AccessTier.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(AccessTierChangeOn), out propertyOverride); + if (Optional.IsDefined(AccessTierChangeOn) || hasPropertyOverride) + { + builder.Append(" accessTierChangeTime:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var formattedDateTimeString = TypeFormatters.ToString(AccessTierChangeOn.Value, "o"); + builder.AppendLine($" '{formattedDateTimeString}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(AccessTierStatus), out propertyOverride); + if (Optional.IsDefined(AccessTierStatus) || hasPropertyOverride) + { + builder.Append(" accessTierStatus:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (AccessTierStatus.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{AccessTierStatus}'''"); + } + else + { + builder.AppendLine($" '{AccessTierStatus}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ShareUsageBytes), out propertyOverride); + if (Optional.IsDefined(ShareUsageBytes) || hasPropertyOverride) + { + builder.Append(" shareUsageBytes:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{ShareUsageBytes.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(LeaseStatus), out propertyOverride); + if (Optional.IsDefined(LeaseStatus) || hasPropertyOverride) + { + builder.Append(" leaseStatus:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{LeaseStatus.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(LeaseState), out propertyOverride); + if (Optional.IsDefined(LeaseState) || hasPropertyOverride) + { + builder.Append(" leaseState:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{LeaseState.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(LeaseDuration), out propertyOverride); + if (Optional.IsDefined(LeaseDuration) || hasPropertyOverride) + { + builder.Append(" leaseDuration:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{LeaseDuration.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(SignedIdentifiers), out propertyOverride); + if (Optional.IsCollectionDefined(SignedIdentifiers) || hasPropertyOverride) + { + if (SignedIdentifiers.Any() || hasPropertyOverride) + { + builder.Append(" signedIdentifiers:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine(" ["); + foreach (var item in SignedIdentifiers) + { + AppendChildObject(builder, item, options, 6, true); + } + builder.AppendLine(" ]"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(SnapshotOn), out propertyOverride); + if (Optional.IsDefined(SnapshotOn) || hasPropertyOverride) + { + builder.Append(" snapshotTime:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var formattedDateTimeString = TypeFormatters.ToString(SnapshotOn.Value, "o"); + builder.AppendLine($" '{formattedDateTimeString}'"); + } + } + + builder.AppendLine(" }"); + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -449,6 +872,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOptions optio { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(FileShareData)} does not support '{options.Format}' format."); } @@ -465,6 +890,8 @@ FileShareData IPersistableModel.Create(BinaryData data, ModelRead using JsonDocument document = JsonDocument.Parse(data); return DeserializeFileShareData(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(FileShareData)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/FileShareItems.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/FileShareItems.Serialization.cs index 3fd02856f1012..1bbe317d89c06 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/FileShareItems.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/FileShareItems.Serialization.cs @@ -8,8 +8,11 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Linq; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; using Azure.ResourceManager.Storage; namespace Azure.ResourceManager.Storage.Models @@ -114,6 +117,100 @@ internal static FileShareItems DeserializeFileShareItems(JsonElement element, Mo return new FileShareItems(Optional.ToList(value), nextLink.Value, serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Value), out propertyOverride); + if (Optional.IsCollectionDefined(Value) || hasPropertyOverride) + { + if (Value.Any() || hasPropertyOverride) + { + builder.Append(" value:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine(" ["); + foreach (var item in Value) + { + AppendChildObject(builder, item, options, 4, true); + } + builder.AppendLine(" ]"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(NextLink), out propertyOverride); + if (Optional.IsDefined(NextLink) || hasPropertyOverride) + { + builder.Append(" nextLink:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (NextLink.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{NextLink}'''"); + } + else + { + builder.AppendLine($" '{NextLink}'"); + } + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -122,6 +219,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOptions opti { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(FileShareItems)} does not support '{options.Format}' format."); } @@ -138,6 +237,8 @@ FileShareItems IPersistableModel.Create(BinaryData data, ModelRe using JsonDocument document = JsonDocument.Parse(data); return DeserializeFileShareItems(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(FileShareItems)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/FilesIdentityBasedAuthentication.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/FilesIdentityBasedAuthentication.Serialization.cs index f53fe52aba7d6..20eb7205f0981 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/FilesIdentityBasedAuthentication.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/FilesIdentityBasedAuthentication.Serialization.cs @@ -8,8 +8,10 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -115,6 +117,98 @@ internal static FilesIdentityBasedAuthentication DeserializeFilesIdentityBasedAu return new FilesIdentityBasedAuthentication(directoryServiceOptions, activeDirectoryProperties.Value, Optional.ToNullable(defaultSharePermission), serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(DirectoryServiceOptions), out propertyOverride); + if (Optional.IsDefined(DirectoryServiceOptions) || hasPropertyOverride) + { + builder.Append(" directoryServiceOptions:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{DirectoryServiceOptions.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ActiveDirectoryProperties), out propertyOverride); + if (Optional.IsDefined(ActiveDirectoryProperties) || hasPropertyOverride) + { + builder.Append(" activeDirectoryProperties:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, ActiveDirectoryProperties, options, 2, false); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(DefaultSharePermission), out propertyOverride); + if (Optional.IsDefined(DefaultSharePermission) || hasPropertyOverride) + { + builder.Append(" defaultSharePermission:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{DefaultSharePermission.Value.ToString()}'"); + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -123,6 +217,8 @@ BinaryData IPersistableModel.Write(ModelReader { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(FilesIdentityBasedAuthentication)} does not support '{options.Format}' format."); } @@ -139,6 +235,8 @@ FilesIdentityBasedAuthentication IPersistableModel propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Status), out propertyOverride); + if (Optional.IsDefined(Status) || hasPropertyOverride) + { + builder.Append(" status:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{Status.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(LastSyncOn), out propertyOverride); + if (Optional.IsDefined(LastSyncOn) || hasPropertyOverride) + { + builder.Append(" lastSyncTime:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var formattedDateTimeString = TypeFormatters.ToString(LastSyncOn.Value, "o"); + builder.AppendLine($" '{formattedDateTimeString}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(CanFailover), out propertyOverride); + if (Optional.IsDefined(CanFailover) || hasPropertyOverride) + { + builder.Append(" canFailover:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var boolValue = CanFailover.Value == true ? "true" : "false"; + builder.AppendLine($" {boolValue}"); + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -130,6 +226,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOp { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(GeoReplicationStatistics)} does not support '{options.Format}' format."); } @@ -146,6 +244,8 @@ GeoReplicationStatistics IPersistableModel.Create(Bina using JsonDocument document = JsonDocument.Parse(data); return DeserializeGeoReplicationStatistics(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(GeoReplicationStatistics)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/GetAccountSasResult.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/GetAccountSasResult.Serialization.cs index 2c8f498d4ff30..84f974df4e003 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/GetAccountSasResult.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/GetAccountSasResult.Serialization.cs @@ -8,8 +8,10 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -88,6 +90,78 @@ internal static GetAccountSasResult DeserializeGetAccountSasResult(JsonElement e return new GetAccountSasResult(accountSasToken.Value, serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(AccountSasToken), out propertyOverride); + if (Optional.IsDefined(AccountSasToken) || hasPropertyOverride) + { + builder.Append(" accountSasToken:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (AccountSasToken.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{AccountSasToken}'''"); + } + else + { + builder.AppendLine($" '{AccountSasToken}'"); + } + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -96,6 +170,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOptions { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(GetAccountSasResult)} does not support '{options.Format}' format."); } @@ -112,6 +188,8 @@ GetAccountSasResult IPersistableModel.Create(BinaryData dat using JsonDocument document = JsonDocument.Parse(data); return DeserializeGetAccountSasResult(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(GetAccountSasResult)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/GetServiceSasResult.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/GetServiceSasResult.Serialization.cs index 260885753ac59..a3a4269e36340 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/GetServiceSasResult.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/GetServiceSasResult.Serialization.cs @@ -8,8 +8,10 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -88,6 +90,78 @@ internal static GetServiceSasResult DeserializeGetServiceSasResult(JsonElement e return new GetServiceSasResult(serviceSasToken.Value, serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ServiceSasToken), out propertyOverride); + if (Optional.IsDefined(ServiceSasToken) || hasPropertyOverride) + { + builder.Append(" serviceSasToken:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (ServiceSasToken.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{ServiceSasToken}'''"); + } + else + { + builder.AppendLine($" '{ServiceSasToken}'"); + } + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -96,6 +170,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOptions { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(GetServiceSasResult)} does not support '{options.Format}' format."); } @@ -112,6 +188,8 @@ GetServiceSasResult IPersistableModel.Create(BinaryData dat using JsonDocument document = JsonDocument.Parse(data); return DeserializeGetServiceSasResult(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(GetServiceSasResult)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ImmutabilityPolicyData.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ImmutabilityPolicyData.Serialization.cs index 88418651ef8d0..28482082329e3 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ImmutabilityPolicyData.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ImmutabilityPolicyData.Serialization.cs @@ -8,9 +8,11 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Text; using System.Text.Json; using Azure; using Azure.Core; +using Azure.ResourceManager; using Azure.ResourceManager.Models; using Azure.ResourceManager.Storage.Models; @@ -218,6 +220,181 @@ internal static ImmutabilityPolicyData DeserializeImmutabilityPolicyData(JsonEle return new ImmutabilityPolicyData(id, name, type, systemData.Value, Optional.ToNullable(immutabilityPeriodSinceCreationInDays), Optional.ToNullable(state), Optional.ToNullable(allowProtectedAppendWrites), Optional.ToNullable(allowProtectedAppendWritesAll), Optional.ToNullable(etag), serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Name), out propertyOverride); + if (Optional.IsDefined(Name) || hasPropertyOverride) + { + builder.Append(" name:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (Name.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{Name}'''"); + } + else + { + builder.AppendLine($" '{Name}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ETag), out propertyOverride); + if (Optional.IsDefined(ETag) || hasPropertyOverride) + { + builder.Append(" etag:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{ETag.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Id), out propertyOverride); + if (Optional.IsDefined(Id) || hasPropertyOverride) + { + builder.Append(" id:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{Id.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(SystemData), out propertyOverride); + if (Optional.IsDefined(SystemData) || hasPropertyOverride) + { + builder.Append(" systemData:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{SystemData.ToString()}'"); + } + } + + builder.Append(" properties:"); + builder.AppendLine(" {"); + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ImmutabilityPeriodSinceCreationInDays), out propertyOverride); + if (Optional.IsDefined(ImmutabilityPeriodSinceCreationInDays) || hasPropertyOverride) + { + builder.Append(" immutabilityPeriodSinceCreationInDays:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" {ImmutabilityPeriodSinceCreationInDays.Value}"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(State), out propertyOverride); + if (Optional.IsDefined(State) || hasPropertyOverride) + { + builder.Append(" state:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{State.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(AllowProtectedAppendWrites), out propertyOverride); + if (Optional.IsDefined(AllowProtectedAppendWrites) || hasPropertyOverride) + { + builder.Append(" allowProtectedAppendWrites:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var boolValue = AllowProtectedAppendWrites.Value == true ? "true" : "false"; + builder.AppendLine($" {boolValue}"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(AllowProtectedAppendWritesAll), out propertyOverride); + if (Optional.IsDefined(AllowProtectedAppendWritesAll) || hasPropertyOverride) + { + builder.Append(" allowProtectedAppendWritesAll:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var boolValue = AllowProtectedAppendWritesAll.Value == true ? "true" : "false"; + builder.AppendLine($" {boolValue}"); + } + } + + builder.AppendLine(" }"); + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -226,6 +403,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOpti { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(ImmutabilityPolicyData)} does not support '{options.Format}' format."); } @@ -242,6 +421,8 @@ ImmutabilityPolicyData IPersistableModel.Create(BinaryDa using JsonDocument document = JsonDocument.Parse(data); return DeserializeImmutabilityPolicyData(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(ImmutabilityPolicyData)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ImmutableStorageAccount.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ImmutableStorageAccount.Serialization.cs index 86b010b287956..a4a7b83120011 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ImmutableStorageAccount.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ImmutableStorageAccount.Serialization.cs @@ -8,8 +8,10 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -107,6 +109,85 @@ internal static ImmutableStorageAccount DeserializeImmutableStorageAccount(JsonE return new ImmutableStorageAccount(Optional.ToNullable(enabled), immutabilityPolicy.Value, serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(IsEnabled), out propertyOverride); + if (Optional.IsDefined(IsEnabled) || hasPropertyOverride) + { + builder.Append(" enabled:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var boolValue = IsEnabled.Value == true ? "true" : "false"; + builder.AppendLine($" {boolValue}"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ImmutabilityPolicy), out propertyOverride); + if (Optional.IsDefined(ImmutabilityPolicy) || hasPropertyOverride) + { + builder.Append(" immutabilityPolicy:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, ImmutabilityPolicy, options, 2, false); + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -115,6 +196,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOpt { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(ImmutableStorageAccount)} does not support '{options.Format}' format."); } @@ -131,6 +214,8 @@ ImmutableStorageAccount IPersistableModel.Create(Binary using JsonDocument document = JsonDocument.Parse(data); return DeserializeImmutableStorageAccount(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(ImmutableStorageAccount)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ImmutableStorageWithVersioning.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ImmutableStorageWithVersioning.Serialization.cs index 9ec45f28547d2..44b1bb6de6a5b 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ImmutableStorageWithVersioning.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ImmutableStorageWithVersioning.Serialization.cs @@ -8,8 +8,10 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -122,6 +124,100 @@ internal static ImmutableStorageWithVersioning DeserializeImmutableStorageWithVe return new ImmutableStorageWithVersioning(Optional.ToNullable(enabled), Optional.ToNullable(timeStamp), Optional.ToNullable(migrationState), serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(IsEnabled), out propertyOverride); + if (Optional.IsDefined(IsEnabled) || hasPropertyOverride) + { + builder.Append(" enabled:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var boolValue = IsEnabled.Value == true ? "true" : "false"; + builder.AppendLine($" {boolValue}"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(TimeStamp), out propertyOverride); + if (Optional.IsDefined(TimeStamp) || hasPropertyOverride) + { + builder.Append(" timeStamp:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var formattedDateTimeString = TypeFormatters.ToString(TimeStamp.Value, "o"); + builder.AppendLine($" '{formattedDateTimeString}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(MigrationState), out propertyOverride); + if (Optional.IsDefined(MigrationState) || hasPropertyOverride) + { + builder.Append(" migrationState:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{MigrationState.Value.ToString()}'"); + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -130,6 +226,8 @@ BinaryData IPersistableModel.Write(ModelReaderWr { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(ImmutableStorageWithVersioning)} does not support '{options.Format}' format."); } @@ -146,6 +244,8 @@ ImmutableStorageWithVersioning IPersistableModel using JsonDocument document = JsonDocument.Parse(data); return DeserializeImmutableStorageWithVersioning(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(ImmutableStorageWithVersioning)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/LastAccessTimeTrackingPolicy.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/LastAccessTimeTrackingPolicy.Serialization.cs index b1582c235b74a..07435ed6102de 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/LastAccessTimeTrackingPolicy.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/LastAccessTimeTrackingPolicy.Serialization.cs @@ -8,8 +8,11 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Linq; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -140,6 +143,134 @@ internal static LastAccessTimeTrackingPolicy DeserializeLastAccessTimeTrackingPo return new LastAccessTimeTrackingPolicy(enable, Optional.ToNullable(name), Optional.ToNullable(trackingGranularityInDays), Optional.ToList(blobType), serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Name), out propertyOverride); + if (Optional.IsDefined(Name) || hasPropertyOverride) + { + builder.Append(" name:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{Name.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(IsEnabled), out propertyOverride); + if (Optional.IsDefined(IsEnabled) || hasPropertyOverride) + { + builder.Append(" enable:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var boolValue = IsEnabled == true ? "true" : "false"; + builder.AppendLine($" {boolValue}"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(TrackingGranularityInDays), out propertyOverride); + if (Optional.IsDefined(TrackingGranularityInDays) || hasPropertyOverride) + { + builder.Append(" trackingGranularityInDays:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" {TrackingGranularityInDays.Value}"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(BlobType), out propertyOverride); + if (Optional.IsCollectionDefined(BlobType) || hasPropertyOverride) + { + if (BlobType.Any() || hasPropertyOverride) + { + builder.Append(" blobType:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine(" ["); + foreach (var item in BlobType) + { + if (item == null) + { + builder.Append("null"); + continue; + } + if (item.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{item}'''"); + } + else + { + builder.AppendLine($" '{item}'"); + } + } + builder.AppendLine(" ]"); + } + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -148,6 +279,8 @@ BinaryData IPersistableModel.Write(ModelReaderWrit { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(LastAccessTimeTrackingPolicy)} does not support '{options.Format}' format."); } @@ -164,6 +297,8 @@ LastAccessTimeTrackingPolicy IPersistableModel.Cre using JsonDocument document = JsonDocument.Parse(data); return DeserializeLastAccessTimeTrackingPolicy(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(LastAccessTimeTrackingPolicy)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/LeaseContainerResponse.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/LeaseContainerResponse.Serialization.cs index e3130ac073ffc..6f6127dbb889d 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/LeaseContainerResponse.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/LeaseContainerResponse.Serialization.cs @@ -8,8 +8,10 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -99,6 +101,100 @@ internal static LeaseContainerResponse DeserializeLeaseContainerResponse(JsonEle return new LeaseContainerResponse(leaseId.Value, leaseTimeSeconds.Value, serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(LeaseId), out propertyOverride); + if (Optional.IsDefined(LeaseId) || hasPropertyOverride) + { + builder.Append(" leaseId:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (LeaseId.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{LeaseId}'''"); + } + else + { + builder.AppendLine($" '{LeaseId}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(LeaseTimeSeconds), out propertyOverride); + if (Optional.IsDefined(LeaseTimeSeconds) || hasPropertyOverride) + { + builder.Append(" leaseTimeSeconds:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (LeaseTimeSeconds.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{LeaseTimeSeconds}'''"); + } + else + { + builder.AppendLine($" '{LeaseTimeSeconds}'"); + } + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -107,6 +203,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOpti { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(LeaseContainerResponse)} does not support '{options.Format}' format."); } @@ -123,6 +221,8 @@ LeaseContainerResponse IPersistableModel.Create(BinaryDa using JsonDocument document = JsonDocument.Parse(data); return DeserializeLeaseContainerResponse(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(LeaseContainerResponse)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/LeaseShareResponse.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/LeaseShareResponse.Serialization.cs index 362d1be532418..cdd26b9d9cdd4 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/LeaseShareResponse.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/LeaseShareResponse.Serialization.cs @@ -8,8 +8,10 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -99,6 +101,100 @@ internal static LeaseShareResponse DeserializeLeaseShareResponse(JsonElement ele return new LeaseShareResponse(leaseId.Value, leaseTimeSeconds.Value, serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(LeaseId), out propertyOverride); + if (Optional.IsDefined(LeaseId) || hasPropertyOverride) + { + builder.Append(" leaseId:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (LeaseId.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{LeaseId}'''"); + } + else + { + builder.AppendLine($" '{LeaseId}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(LeaseTimeSeconds), out propertyOverride); + if (Optional.IsDefined(LeaseTimeSeconds) || hasPropertyOverride) + { + builder.Append(" leaseTimeSeconds:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (LeaseTimeSeconds.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{LeaseTimeSeconds}'''"); + } + else + { + builder.AppendLine($" '{LeaseTimeSeconds}'"); + } + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -107,6 +203,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOptions { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(LeaseShareResponse)} does not support '{options.Format}' format."); } @@ -123,6 +221,8 @@ LeaseShareResponse IPersistableModel.Create(BinaryData data, using JsonDocument document = JsonDocument.Parse(data); return DeserializeLeaseShareResponse(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(LeaseShareResponse)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/LegalHold.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/LegalHold.Serialization.cs index f235de5a480fb..cea41fe05a020 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/LegalHold.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/LegalHold.Serialization.cs @@ -8,8 +8,11 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Linq; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -125,6 +128,121 @@ internal static LegalHold DeserializeLegalHold(JsonElement element, ModelReaderW return new LegalHold(Optional.ToNullable(hasLegalHold), tags, Optional.ToNullable(allowProtectedAppendWritesAll), serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Tags), out propertyOverride); + if (Optional.IsCollectionDefined(Tags) || hasPropertyOverride) + { + if (Tags.Any() || hasPropertyOverride) + { + builder.Append(" tags:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine(" ["); + foreach (var item in Tags) + { + if (item == null) + { + builder.Append("null"); + continue; + } + if (item.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{item}'''"); + } + else + { + builder.AppendLine($" '{item}'"); + } + } + builder.AppendLine(" ]"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(HasLegalHold), out propertyOverride); + if (Optional.IsDefined(HasLegalHold) || hasPropertyOverride) + { + builder.Append(" hasLegalHold:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var boolValue = HasLegalHold.Value == true ? "true" : "false"; + builder.AppendLine($" {boolValue}"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(AllowProtectedAppendWritesAll), out propertyOverride); + if (Optional.IsDefined(AllowProtectedAppendWritesAll) || hasPropertyOverride) + { + builder.Append(" allowProtectedAppendWritesAll:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var boolValue = AllowProtectedAppendWritesAll.Value == true ? "true" : "false"; + builder.AppendLine($" {boolValue}"); + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -133,6 +251,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(LegalHold)} does not support '{options.Format}' format."); } @@ -149,6 +269,8 @@ LegalHold IPersistableModel.Create(BinaryData data, ModelReaderWriter using JsonDocument document = JsonDocument.Parse(data); return DeserializeLegalHold(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(LegalHold)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/LegalHoldProperties.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/LegalHoldProperties.Serialization.cs index 40e7f3443eb97..234384168c03c 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/LegalHoldProperties.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/LegalHoldProperties.Serialization.cs @@ -8,8 +8,11 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Linq; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -132,6 +135,107 @@ internal static LegalHoldProperties DeserializeLegalHoldProperties(JsonElement e return new LegalHoldProperties(Optional.ToNullable(hasLegalHold), Optional.ToList(tags), protectedAppendWritesHistory.Value, serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Tags), out propertyOverride); + if (Optional.IsCollectionDefined(Tags) || hasPropertyOverride) + { + if (Tags.Any() || hasPropertyOverride) + { + builder.Append(" tags:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine(" ["); + foreach (var item in Tags) + { + AppendChildObject(builder, item, options, 4, true); + } + builder.AppendLine(" ]"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(HasLegalHold), out propertyOverride); + if (Optional.IsDefined(HasLegalHold) || hasPropertyOverride) + { + builder.Append(" hasLegalHold:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var boolValue = HasLegalHold.Value == true ? "true" : "false"; + builder.AppendLine($" {boolValue}"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ProtectedAppendWritesHistory), out propertyOverride); + if (Optional.IsDefined(ProtectedAppendWritesHistory) || hasPropertyOverride) + { + builder.Append(" protectedAppendWritesHistory:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, ProtectedAppendWritesHistory, options, 2, false); + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -140,6 +244,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOptions { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(LegalHoldProperties)} does not support '{options.Format}' format."); } @@ -156,6 +262,8 @@ LegalHoldProperties IPersistableModel.Create(BinaryData dat using JsonDocument document = JsonDocument.Parse(data); return DeserializeLegalHoldProperties(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(LegalHoldProperties)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/LegalHoldTag.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/LegalHoldTag.Serialization.cs index 229f0719cbb5a..dacc3752cffc4 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/LegalHoldTag.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/LegalHoldTag.Serialization.cs @@ -8,8 +8,10 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -140,6 +142,151 @@ internal static LegalHoldTag DeserializeLegalHoldTag(JsonElement element, ModelR return new LegalHoldTag(tag.Value, Optional.ToNullable(timestamp), objectIdentifier.Value, Optional.ToNullable(tenantId), upn.Value, serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Tag), out propertyOverride); + if (Optional.IsDefined(Tag) || hasPropertyOverride) + { + builder.Append(" tag:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (Tag.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{Tag}'''"); + } + else + { + builder.AppendLine($" '{Tag}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Timestamp), out propertyOverride); + if (Optional.IsDefined(Timestamp) || hasPropertyOverride) + { + builder.Append(" timestamp:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var formattedDateTimeString = TypeFormatters.ToString(Timestamp.Value, "o"); + builder.AppendLine($" '{formattedDateTimeString}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ObjectIdentifier), out propertyOverride); + if (Optional.IsDefined(ObjectIdentifier) || hasPropertyOverride) + { + builder.Append(" objectIdentifier:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (ObjectIdentifier.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{ObjectIdentifier}'''"); + } + else + { + builder.AppendLine($" '{ObjectIdentifier}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(TenantId), out propertyOverride); + if (Optional.IsDefined(TenantId) || hasPropertyOverride) + { + builder.Append(" tenantId:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{TenantId.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Upn), out propertyOverride); + if (Optional.IsDefined(Upn) || hasPropertyOverride) + { + builder.Append(" upn:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (Upn.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{Upn}'''"); + } + else + { + builder.AppendLine($" '{Upn}'"); + } + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -148,6 +295,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOptions option { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(LegalHoldTag)} does not support '{options.Format}' format."); } @@ -164,6 +313,8 @@ LegalHoldTag IPersistableModel.Create(BinaryData data, ModelReader using JsonDocument document = JsonDocument.Parse(data); return DeserializeLegalHoldTag(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(LegalHoldTag)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ListBlobInventoryPolicy.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ListBlobInventoryPolicy.Serialization.cs index 63e2c21f5b150..62f4f09543463 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ListBlobInventoryPolicy.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ListBlobInventoryPolicy.Serialization.cs @@ -8,8 +8,11 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Linq; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; using Azure.ResourceManager.Storage; namespace Azure.ResourceManager.Storage.Models @@ -103,6 +106,78 @@ internal static ListBlobInventoryPolicy DeserializeListBlobInventoryPolicy(JsonE return new ListBlobInventoryPolicy(Optional.ToList(value), serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Value), out propertyOverride); + if (Optional.IsCollectionDefined(Value) || hasPropertyOverride) + { + if (Value.Any() || hasPropertyOverride) + { + builder.Append(" value:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine(" ["); + foreach (var item in Value) + { + AppendChildObject(builder, item, options, 4, true); + } + builder.AppendLine(" ]"); + } + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -111,6 +186,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOpt { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(ListBlobInventoryPolicy)} does not support '{options.Format}' format."); } @@ -127,6 +204,8 @@ ListBlobInventoryPolicy IPersistableModel.Create(Binary using JsonDocument document = JsonDocument.Parse(data); return DeserializeListBlobInventoryPolicy(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(ListBlobInventoryPolicy)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ListContainerItems.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ListContainerItems.Serialization.cs index 3e3a2074d841c..8c1a4a6e97a9b 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ListContainerItems.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ListContainerItems.Serialization.cs @@ -8,8 +8,11 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Linq; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; using Azure.ResourceManager.Storage; namespace Azure.ResourceManager.Storage.Models @@ -114,6 +117,100 @@ internal static ListContainerItems DeserializeListContainerItems(JsonElement ele return new ListContainerItems(Optional.ToList(value), nextLink.Value, serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Value), out propertyOverride); + if (Optional.IsCollectionDefined(Value) || hasPropertyOverride) + { + if (Value.Any() || hasPropertyOverride) + { + builder.Append(" value:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine(" ["); + foreach (var item in Value) + { + AppendChildObject(builder, item, options, 4, true); + } + builder.AppendLine(" ]"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(NextLink), out propertyOverride); + if (Optional.IsDefined(NextLink) || hasPropertyOverride) + { + builder.Append(" nextLink:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (NextLink.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{NextLink}'''"); + } + else + { + builder.AppendLine($" '{NextLink}'"); + } + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -122,6 +219,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOptions { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(ListContainerItems)} does not support '{options.Format}' format."); } @@ -138,6 +237,8 @@ ListContainerItems IPersistableModel.Create(BinaryData data, using JsonDocument document = JsonDocument.Parse(data); return DeserializeListContainerItems(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(ListContainerItems)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ListQueueResource.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ListQueueResource.Serialization.cs index b757c8e45a376..7951d03fe2bf0 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ListQueueResource.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ListQueueResource.Serialization.cs @@ -8,8 +8,11 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Linq; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; using Azure.ResourceManager.Storage; namespace Azure.ResourceManager.Storage.Models @@ -114,6 +117,100 @@ internal static ListQueueResource DeserializeListQueueResource(JsonElement eleme return new ListQueueResource(Optional.ToList(value), nextLink.Value, serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Value), out propertyOverride); + if (Optional.IsCollectionDefined(Value) || hasPropertyOverride) + { + if (Value.Any() || hasPropertyOverride) + { + builder.Append(" value:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine(" ["); + foreach (var item in Value) + { + AppendChildObject(builder, item, options, 4, true); + } + builder.AppendLine(" ]"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(NextLink), out propertyOverride); + if (Optional.IsDefined(NextLink) || hasPropertyOverride) + { + builder.Append(" nextLink:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (NextLink.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{NextLink}'''"); + } + else + { + builder.AppendLine($" '{NextLink}'"); + } + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -122,6 +219,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOptions o { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(ListQueueResource)} does not support '{options.Format}' format."); } @@ -138,6 +237,8 @@ ListQueueResource IPersistableModel.Create(BinaryData data, M using JsonDocument document = JsonDocument.Parse(data); return DeserializeListQueueResource(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(ListQueueResource)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ListQueueServices.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ListQueueServices.Serialization.cs index b53dfefed6ac2..39fbcfa8b6852 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ListQueueServices.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ListQueueServices.Serialization.cs @@ -8,8 +8,11 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Linq; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; using Azure.ResourceManager.Storage; namespace Azure.ResourceManager.Storage.Models @@ -103,6 +106,78 @@ internal static ListQueueServices DeserializeListQueueServices(JsonElement eleme return new ListQueueServices(Optional.ToList(value), serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Value), out propertyOverride); + if (Optional.IsCollectionDefined(Value) || hasPropertyOverride) + { + if (Value.Any() || hasPropertyOverride) + { + builder.Append(" value:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine(" ["); + foreach (var item in Value) + { + AppendChildObject(builder, item, options, 4, true); + } + builder.AppendLine(" ]"); + } + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -111,6 +186,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOptions o { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(ListQueueServices)} does not support '{options.Format}' format."); } @@ -127,6 +204,8 @@ ListQueueServices IPersistableModel.Create(BinaryData data, M using JsonDocument document = JsonDocument.Parse(data); return DeserializeListQueueServices(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(ListQueueServices)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ListTableResource.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ListTableResource.Serialization.cs index d523b92772af2..b9b9a750261a4 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ListTableResource.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ListTableResource.Serialization.cs @@ -8,8 +8,11 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Linq; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; using Azure.ResourceManager.Storage; namespace Azure.ResourceManager.Storage.Models @@ -114,6 +117,100 @@ internal static ListTableResource DeserializeListTableResource(JsonElement eleme return new ListTableResource(Optional.ToList(value), nextLink.Value, serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Value), out propertyOverride); + if (Optional.IsCollectionDefined(Value) || hasPropertyOverride) + { + if (Value.Any() || hasPropertyOverride) + { + builder.Append(" value:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine(" ["); + foreach (var item in Value) + { + AppendChildObject(builder, item, options, 4, true); + } + builder.AppendLine(" ]"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(NextLink), out propertyOverride); + if (Optional.IsDefined(NextLink) || hasPropertyOverride) + { + builder.Append(" nextLink:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (NextLink.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{NextLink}'''"); + } + else + { + builder.AppendLine($" '{NextLink}'"); + } + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -122,6 +219,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOptions o { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(ListTableResource)} does not support '{options.Format}' format."); } @@ -138,6 +237,8 @@ ListTableResource IPersistableModel.Create(BinaryData data, M using JsonDocument document = JsonDocument.Parse(data); return DeserializeListTableResource(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(ListTableResource)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ListTableServices.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ListTableServices.Serialization.cs index baf7bdf3b6b15..296d4055db670 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ListTableServices.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ListTableServices.Serialization.cs @@ -8,8 +8,11 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Linq; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; using Azure.ResourceManager.Storage; namespace Azure.ResourceManager.Storage.Models @@ -103,6 +106,78 @@ internal static ListTableServices DeserializeListTableServices(JsonElement eleme return new ListTableServices(Optional.ToList(value), serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Value), out propertyOverride); + if (Optional.IsCollectionDefined(Value) || hasPropertyOverride) + { + if (Value.Any() || hasPropertyOverride) + { + builder.Append(" value:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine(" ["); + foreach (var item in Value) + { + AppendChildObject(builder, item, options, 4, true); + } + builder.AppendLine(" ]"); + } + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -111,6 +186,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOptions o { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(ListTableServices)} does not support '{options.Format}' format."); } @@ -127,6 +204,8 @@ ListTableServices IPersistableModel.Create(BinaryData data, M using JsonDocument document = JsonDocument.Parse(data); return DeserializeListTableServices(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(ListTableServices)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/LocalUserKeys.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/LocalUserKeys.Serialization.cs index bf24103ec3a33..1e0a3dd7507a2 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/LocalUserKeys.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/LocalUserKeys.Serialization.cs @@ -8,8 +8,11 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Linq; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -113,6 +116,100 @@ internal static LocalUserKeys DeserializeLocalUserKeys(JsonElement element, Mode return new LocalUserKeys(Optional.ToList(sshAuthorizedKeys), sharedKey.Value, serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(SshAuthorizedKeys), out propertyOverride); + if (Optional.IsCollectionDefined(SshAuthorizedKeys) || hasPropertyOverride) + { + if (SshAuthorizedKeys.Any() || hasPropertyOverride) + { + builder.Append(" sshAuthorizedKeys:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine(" ["); + foreach (var item in SshAuthorizedKeys) + { + AppendChildObject(builder, item, options, 4, true); + } + builder.AppendLine(" ]"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(SharedKey), out propertyOverride); + if (Optional.IsDefined(SharedKey) || hasPropertyOverride) + { + builder.Append(" sharedKey:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (SharedKey.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{SharedKey}'''"); + } + else + { + builder.AppendLine($" '{SharedKey}'"); + } + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -121,6 +218,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOptions optio { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(LocalUserKeys)} does not support '{options.Format}' format."); } @@ -137,6 +236,8 @@ LocalUserKeys IPersistableModel.Create(BinaryData data, ModelRead using JsonDocument document = JsonDocument.Parse(data); return DeserializeLocalUserKeys(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(LocalUserKeys)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/LocalUserRegeneratePasswordResult.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/LocalUserRegeneratePasswordResult.Serialization.cs index 12126ecff04b9..6a5403196bae2 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/LocalUserRegeneratePasswordResult.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/LocalUserRegeneratePasswordResult.Serialization.cs @@ -8,8 +8,10 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -88,6 +90,78 @@ internal static LocalUserRegeneratePasswordResult DeserializeLocalUserRegenerate return new LocalUserRegeneratePasswordResult(sshPassword.Value, serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(SshPassword), out propertyOverride); + if (Optional.IsDefined(SshPassword) || hasPropertyOverride) + { + builder.Append(" sshPassword:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (SshPassword.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{SshPassword}'''"); + } + else + { + builder.AppendLine($" '{SshPassword}'"); + } + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -96,6 +170,8 @@ BinaryData IPersistableModel.Write(ModelReade { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(LocalUserRegeneratePasswordResult)} does not support '{options.Format}' format."); } @@ -112,6 +188,8 @@ LocalUserRegeneratePasswordResult IPersistableModel propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Value), out propertyOverride); + if (Optional.IsCollectionDefined(Value) || hasPropertyOverride) + { + if (Value.Any() || hasPropertyOverride) + { + builder.Append(" value:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine(" ["); + foreach (var item in Value) + { + AppendChildObject(builder, item, options, 4, true); + } + builder.AppendLine(" ]"); + } + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -111,6 +186,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(LocalUsers)} does not support '{options.Format}' format."); } @@ -127,6 +204,8 @@ LocalUsers IPersistableModel.Create(BinaryData data, ModelReaderWrit using JsonDocument document = JsonDocument.Parse(data); return DeserializeLocalUsers(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(LocalUsers)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ManagementPolicyAction.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ManagementPolicyAction.Serialization.cs index 366d718eeabeb..72ea40bc4087e 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ManagementPolicyAction.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ManagementPolicyAction.Serialization.cs @@ -8,8 +8,10 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -122,6 +124,98 @@ internal static ManagementPolicyAction DeserializeManagementPolicyAction(JsonEle return new ManagementPolicyAction(baseBlob.Value, snapshot.Value, version.Value, serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(BaseBlob), out propertyOverride); + if (Optional.IsDefined(BaseBlob) || hasPropertyOverride) + { + builder.Append(" baseBlob:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, BaseBlob, options, 2, false); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Snapshot), out propertyOverride); + if (Optional.IsDefined(Snapshot) || hasPropertyOverride) + { + builder.Append(" snapshot:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, Snapshot, options, 2, false); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Version), out propertyOverride); + if (Optional.IsDefined(Version) || hasPropertyOverride) + { + builder.Append(" version:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, Version, options, 2, false); + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -130,6 +224,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOpti { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(ManagementPolicyAction)} does not support '{options.Format}' format."); } @@ -146,6 +242,8 @@ ManagementPolicyAction IPersistableModel.Create(BinaryDa using JsonDocument document = JsonDocument.Parse(data); return DeserializeManagementPolicyAction(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(ManagementPolicyAction)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ManagementPolicyBaseBlob.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ManagementPolicyBaseBlob.Serialization.cs index 70d9ad5b3810c..9892b68de7f8b 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ManagementPolicyBaseBlob.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ManagementPolicyBaseBlob.Serialization.cs @@ -8,8 +8,10 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -167,6 +169,141 @@ internal static ManagementPolicyBaseBlob DeserializeManagementPolicyBaseBlob(Jso return new ManagementPolicyBaseBlob(tierToCool.Value, tierToArchive.Value, tierToCold.Value, tierToHot.Value, delete.Value, Optional.ToNullable(enableAutoTierToHotFromCool), serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(TierToCool), out propertyOverride); + if (Optional.IsDefined(TierToCool) || hasPropertyOverride) + { + builder.Append(" tierToCool:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, TierToCool, options, 2, false); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(TierToArchive), out propertyOverride); + if (Optional.IsDefined(TierToArchive) || hasPropertyOverride) + { + builder.Append(" tierToArchive:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, TierToArchive, options, 2, false); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(TierToCold), out propertyOverride); + if (Optional.IsDefined(TierToCold) || hasPropertyOverride) + { + builder.Append(" tierToCold:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, TierToCold, options, 2, false); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(TierToHot), out propertyOverride); + if (Optional.IsDefined(TierToHot) || hasPropertyOverride) + { + builder.Append(" tierToHot:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, TierToHot, options, 2, false); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Delete), out propertyOverride); + if (Optional.IsDefined(Delete) || hasPropertyOverride) + { + builder.Append(" delete:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, Delete, options, 2, false); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(EnableAutoTierToHotFromCool), out propertyOverride); + if (Optional.IsDefined(EnableAutoTierToHotFromCool) || hasPropertyOverride) + { + builder.Append(" enableAutoTierToHotFromCool:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var boolValue = EnableAutoTierToHotFromCool.Value == true ? "true" : "false"; + builder.AppendLine($" {boolValue}"); + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -175,6 +312,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOp { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(ManagementPolicyBaseBlob)} does not support '{options.Format}' format."); } @@ -191,6 +330,8 @@ ManagementPolicyBaseBlob IPersistableModel.Create(Bina using JsonDocument document = JsonDocument.Parse(data); return DeserializeManagementPolicyBaseBlob(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(ManagementPolicyBaseBlob)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ManagementPolicyDefinition.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ManagementPolicyDefinition.Serialization.cs index 35a1ac3c18aa4..5b761bd0fa825 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ManagementPolicyDefinition.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ManagementPolicyDefinition.Serialization.cs @@ -8,8 +8,10 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -100,6 +102,84 @@ internal static ManagementPolicyDefinition DeserializeManagementPolicyDefinition return new ManagementPolicyDefinition(actions, filters.Value, serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Actions), out propertyOverride); + if (Optional.IsDefined(Actions) || hasPropertyOverride) + { + builder.Append(" actions:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, Actions, options, 2, false); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Filters), out propertyOverride); + if (Optional.IsDefined(Filters) || hasPropertyOverride) + { + builder.Append(" filters:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, Filters, options, 2, false); + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -108,6 +188,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriter { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(ManagementPolicyDefinition)} does not support '{options.Format}' format."); } @@ -124,6 +206,8 @@ ManagementPolicyDefinition IPersistableModel.Create( using JsonDocument document = JsonDocument.Parse(data); return DeserializeManagementPolicyDefinition(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(ManagementPolicyDefinition)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ManagementPolicyFilter.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ManagementPolicyFilter.Serialization.cs index 8b73403a78c30..29864663e6b46 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ManagementPolicyFilter.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ManagementPolicyFilter.Serialization.cs @@ -8,8 +8,11 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Linq; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -145,6 +148,148 @@ internal static ManagementPolicyFilter DeserializeManagementPolicyFilter(JsonEle return new ManagementPolicyFilter(Optional.ToList(prefixMatch), blobTypes, Optional.ToList(blobIndexMatch), serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(PrefixMatch), out propertyOverride); + if (Optional.IsCollectionDefined(PrefixMatch) || hasPropertyOverride) + { + if (PrefixMatch.Any() || hasPropertyOverride) + { + builder.Append(" prefixMatch:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine(" ["); + foreach (var item in PrefixMatch) + { + if (item == null) + { + builder.Append("null"); + continue; + } + if (item.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{item}'''"); + } + else + { + builder.AppendLine($" '{item}'"); + } + } + builder.AppendLine(" ]"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(BlobTypes), out propertyOverride); + if (Optional.IsCollectionDefined(BlobTypes) || hasPropertyOverride) + { + if (BlobTypes.Any() || hasPropertyOverride) + { + builder.Append(" blobTypes:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine(" ["); + foreach (var item in BlobTypes) + { + if (item == null) + { + builder.Append("null"); + continue; + } + if (item.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{item}'''"); + } + else + { + builder.AppendLine($" '{item}'"); + } + } + builder.AppendLine(" ]"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(BlobIndexMatch), out propertyOverride); + if (Optional.IsCollectionDefined(BlobIndexMatch) || hasPropertyOverride) + { + if (BlobIndexMatch.Any() || hasPropertyOverride) + { + builder.Append(" blobIndexMatch:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine(" ["); + foreach (var item in BlobIndexMatch) + { + AppendChildObject(builder, item, options, 4, true); + } + builder.AppendLine(" ]"); + } + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -153,6 +298,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOpti { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(ManagementPolicyFilter)} does not support '{options.Format}' format."); } @@ -169,6 +316,8 @@ ManagementPolicyFilter IPersistableModel.Create(BinaryDa using JsonDocument document = JsonDocument.Parse(data); return DeserializeManagementPolicyFilter(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(ManagementPolicyFilter)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ManagementPolicyRule.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ManagementPolicyRule.Serialization.cs index 39d026f9a4e07..a076b96849417 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ManagementPolicyRule.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ManagementPolicyRule.Serialization.cs @@ -8,8 +8,10 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -116,6 +118,107 @@ internal static ManagementPolicyRule DeserializeManagementPolicyRule(JsonElement return new ManagementPolicyRule(Optional.ToNullable(enabled), name, type, definition, serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Name), out propertyOverride); + if (Optional.IsDefined(Name) || hasPropertyOverride) + { + builder.Append(" name:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (Name.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{Name}'''"); + } + else + { + builder.AppendLine($" '{Name}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(IsEnabled), out propertyOverride); + if (Optional.IsDefined(IsEnabled) || hasPropertyOverride) + { + builder.Append(" enabled:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var boolValue = IsEnabled.Value == true ? "true" : "false"; + builder.AppendLine($" {boolValue}"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Definition), out propertyOverride); + if (Optional.IsDefined(Definition) || hasPropertyOverride) + { + builder.Append(" definition:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, Definition, options, 2, false); + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -124,6 +227,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOption { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(ManagementPolicyRule)} does not support '{options.Format}' format."); } @@ -140,6 +245,8 @@ ManagementPolicyRule IPersistableModel.Create(BinaryData d using JsonDocument document = JsonDocument.Parse(data); return DeserializeManagementPolicyRule(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(ManagementPolicyRule)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ManagementPolicySchema.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ManagementPolicySchema.Serialization.cs index f24f335ecdfb8..95d1a232cae99 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ManagementPolicySchema.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ManagementPolicySchema.Serialization.cs @@ -8,8 +8,11 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Linq; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -95,6 +98,78 @@ internal static ManagementPolicySchema DeserializeManagementPolicySchema(JsonEle return new ManagementPolicySchema(rules, serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Rules), out propertyOverride); + if (Optional.IsCollectionDefined(Rules) || hasPropertyOverride) + { + if (Rules.Any() || hasPropertyOverride) + { + builder.Append(" rules:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine(" ["); + foreach (var item in Rules) + { + AppendChildObject(builder, item, options, 4, true); + } + builder.AppendLine(" ]"); + } + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -103,6 +178,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOpti { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(ManagementPolicySchema)} does not support '{options.Format}' format."); } @@ -119,6 +196,8 @@ ManagementPolicySchema IPersistableModel.Create(BinaryDa using JsonDocument document = JsonDocument.Parse(data); return DeserializeManagementPolicySchema(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(ManagementPolicySchema)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ManagementPolicySnapShot.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ManagementPolicySnapShot.Serialization.cs index 09fa84ffa0850..ff6acfd2e0d2e 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ManagementPolicySnapShot.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ManagementPolicySnapShot.Serialization.cs @@ -8,8 +8,10 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -152,6 +154,126 @@ internal static ManagementPolicySnapShot DeserializeManagementPolicySnapShot(Jso return new ManagementPolicySnapShot(tierToCool.Value, tierToArchive.Value, tierToCold.Value, tierToHot.Value, delete.Value, serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(TierToCool), out propertyOverride); + if (Optional.IsDefined(TierToCool) || hasPropertyOverride) + { + builder.Append(" tierToCool:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, TierToCool, options, 2, false); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(TierToArchive), out propertyOverride); + if (Optional.IsDefined(TierToArchive) || hasPropertyOverride) + { + builder.Append(" tierToArchive:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, TierToArchive, options, 2, false); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(TierToCold), out propertyOverride); + if (Optional.IsDefined(TierToCold) || hasPropertyOverride) + { + builder.Append(" tierToCold:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, TierToCold, options, 2, false); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(TierToHot), out propertyOverride); + if (Optional.IsDefined(TierToHot) || hasPropertyOverride) + { + builder.Append(" tierToHot:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, TierToHot, options, 2, false); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Delete), out propertyOverride); + if (Optional.IsDefined(Delete) || hasPropertyOverride) + { + builder.Append(" delete:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, Delete, options, 2, false); + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -160,6 +282,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOp { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(ManagementPolicySnapShot)} does not support '{options.Format}' format."); } @@ -176,6 +300,8 @@ ManagementPolicySnapShot IPersistableModel.Create(Bina using JsonDocument document = JsonDocument.Parse(data); return DeserializeManagementPolicySnapShot(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(ManagementPolicySnapShot)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ManagementPolicyTagFilter.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ManagementPolicyTagFilter.Serialization.cs index bc9fc34b4e3ee..380889f6e1fd8 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ManagementPolicyTagFilter.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ManagementPolicyTagFilter.Serialization.cs @@ -8,8 +8,10 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -101,6 +103,122 @@ internal static ManagementPolicyTagFilter DeserializeManagementPolicyTagFilter(J return new ManagementPolicyTagFilter(name, op, value, serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Name), out propertyOverride); + if (Optional.IsDefined(Name) || hasPropertyOverride) + { + builder.Append(" name:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (Name.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{Name}'''"); + } + else + { + builder.AppendLine($" '{Name}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Operator), out propertyOverride); + if (Optional.IsDefined(Operator) || hasPropertyOverride) + { + builder.Append(" op:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (Operator.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{Operator}'''"); + } + else + { + builder.AppendLine($" '{Operator}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Value), out propertyOverride); + if (Optional.IsDefined(Value) || hasPropertyOverride) + { + builder.Append(" value:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (Value.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{Value}'''"); + } + else + { + builder.AppendLine($" '{Value}'"); + } + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -109,6 +227,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterO { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(ManagementPolicyTagFilter)} does not support '{options.Format}' format."); } @@ -125,6 +245,8 @@ ManagementPolicyTagFilter IPersistableModel.Create(Bi using JsonDocument document = JsonDocument.Parse(data); return DeserializeManagementPolicyTagFilter(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(ManagementPolicyTagFilter)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ManagementPolicyVersion.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ManagementPolicyVersion.Serialization.cs index adfd133e85beb..0575f2a785f40 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ManagementPolicyVersion.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ManagementPolicyVersion.Serialization.cs @@ -8,8 +8,10 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -152,6 +154,126 @@ internal static ManagementPolicyVersion DeserializeManagementPolicyVersion(JsonE return new ManagementPolicyVersion(tierToCool.Value, tierToArchive.Value, tierToCold.Value, tierToHot.Value, delete.Value, serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(TierToCool), out propertyOverride); + if (Optional.IsDefined(TierToCool) || hasPropertyOverride) + { + builder.Append(" tierToCool:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, TierToCool, options, 2, false); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(TierToArchive), out propertyOverride); + if (Optional.IsDefined(TierToArchive) || hasPropertyOverride) + { + builder.Append(" tierToArchive:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, TierToArchive, options, 2, false); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(TierToCold), out propertyOverride); + if (Optional.IsDefined(TierToCold) || hasPropertyOverride) + { + builder.Append(" tierToCold:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, TierToCold, options, 2, false); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(TierToHot), out propertyOverride); + if (Optional.IsDefined(TierToHot) || hasPropertyOverride) + { + builder.Append(" tierToHot:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, TierToHot, options, 2, false); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Delete), out propertyOverride); + if (Optional.IsDefined(Delete) || hasPropertyOverride) + { + builder.Append(" delete:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, Delete, options, 2, false); + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -160,6 +282,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOpt { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(ManagementPolicyVersion)} does not support '{options.Format}' format."); } @@ -176,6 +300,8 @@ ManagementPolicyVersion IPersistableModel.Create(Binary using JsonDocument document = JsonDocument.Parse(data); return DeserializeManagementPolicyVersion(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(ManagementPolicyVersion)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/Multichannel.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/Multichannel.Serialization.cs index d86d62eb01c72..0bc4e9a6f0c5a 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/Multichannel.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/Multichannel.Serialization.cs @@ -8,8 +8,10 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -92,6 +94,71 @@ internal static Multichannel DeserializeMultichannel(JsonElement element, ModelR return new Multichannel(Optional.ToNullable(enabled), serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(IsMultiChannelEnabled), out propertyOverride); + if (Optional.IsDefined(IsMultiChannelEnabled) || hasPropertyOverride) + { + builder.Append(" enabled:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var boolValue = IsMultiChannelEnabled.Value == true ? "true" : "false"; + builder.AppendLine($" {boolValue}"); + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -100,6 +167,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOptions option { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(Multichannel)} does not support '{options.Format}' format."); } @@ -116,6 +185,8 @@ Multichannel IPersistableModel.Create(BinaryData data, ModelReader using JsonDocument document = JsonDocument.Parse(data); return DeserializeMultichannel(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(Multichannel)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ObjectReplicationPolicies.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ObjectReplicationPolicies.Serialization.cs index 6416477050b7e..093c79c5c989b 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ObjectReplicationPolicies.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ObjectReplicationPolicies.Serialization.cs @@ -8,8 +8,11 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Linq; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; using Azure.ResourceManager.Storage; namespace Azure.ResourceManager.Storage.Models @@ -103,6 +106,78 @@ internal static ObjectReplicationPolicies DeserializeObjectReplicationPolicies(J return new ObjectReplicationPolicies(Optional.ToList(value), serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Value), out propertyOverride); + if (Optional.IsCollectionDefined(Value) || hasPropertyOverride) + { + if (Value.Any() || hasPropertyOverride) + { + builder.Append(" value:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine(" ["); + foreach (var item in Value) + { + AppendChildObject(builder, item, options, 4, true); + } + builder.AppendLine(" ]"); + } + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -111,6 +186,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterO { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(ObjectReplicationPolicies)} does not support '{options.Format}' format."); } @@ -127,6 +204,8 @@ ObjectReplicationPolicies IPersistableModel.Create(Bi using JsonDocument document = JsonDocument.Parse(data); return DeserializeObjectReplicationPolicies(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(ObjectReplicationPolicies)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ObjectReplicationPolicyData.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ObjectReplicationPolicyData.Serialization.cs index ef4961348b900..bc0f0b261bdac 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ObjectReplicationPolicyData.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ObjectReplicationPolicyData.Serialization.cs @@ -8,8 +8,11 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Linq; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; using Azure.ResourceManager.Models; using Azure.ResourceManager.Storage.Models; @@ -215,6 +218,212 @@ internal static ObjectReplicationPolicyData DeserializeObjectReplicationPolicyDa return new ObjectReplicationPolicyData(id, name, type, systemData.Value, policyId.Value, Optional.ToNullable(enabledTime), sourceAccount.Value, destinationAccount.Value, Optional.ToList(rules), serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Name), out propertyOverride); + if (Optional.IsDefined(Name) || hasPropertyOverride) + { + builder.Append(" name:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (Name.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{Name}'''"); + } + else + { + builder.AppendLine($" '{Name}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Id), out propertyOverride); + if (Optional.IsDefined(Id) || hasPropertyOverride) + { + builder.Append(" id:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{Id.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(SystemData), out propertyOverride); + if (Optional.IsDefined(SystemData) || hasPropertyOverride) + { + builder.Append(" systemData:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{SystemData.ToString()}'"); + } + } + + builder.Append(" properties:"); + builder.AppendLine(" {"); + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(PolicyId), out propertyOverride); + if (Optional.IsDefined(PolicyId) || hasPropertyOverride) + { + builder.Append(" policyId:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (PolicyId.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{PolicyId}'''"); + } + else + { + builder.AppendLine($" '{PolicyId}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(EnabledOn), out propertyOverride); + if (Optional.IsDefined(EnabledOn) || hasPropertyOverride) + { + builder.Append(" enabledTime:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var formattedDateTimeString = TypeFormatters.ToString(EnabledOn.Value, "o"); + builder.AppendLine($" '{formattedDateTimeString}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(SourceAccount), out propertyOverride); + if (Optional.IsDefined(SourceAccount) || hasPropertyOverride) + { + builder.Append(" sourceAccount:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (SourceAccount.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{SourceAccount}'''"); + } + else + { + builder.AppendLine($" '{SourceAccount}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(DestinationAccount), out propertyOverride); + if (Optional.IsDefined(DestinationAccount) || hasPropertyOverride) + { + builder.Append(" destinationAccount:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (DestinationAccount.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{DestinationAccount}'''"); + } + else + { + builder.AppendLine($" '{DestinationAccount}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Rules), out propertyOverride); + if (Optional.IsCollectionDefined(Rules) || hasPropertyOverride) + { + if (Rules.Any() || hasPropertyOverride) + { + builder.Append(" rules:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine(" ["); + foreach (var item in Rules) + { + AppendChildObject(builder, item, options, 6, true); + } + builder.AppendLine(" ]"); + } + } + } + + builder.AppendLine(" }"); + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -223,6 +432,8 @@ BinaryData IPersistableModel.Write(ModelReaderWrite { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(ObjectReplicationPolicyData)} does not support '{options.Format}' format."); } @@ -239,6 +450,8 @@ ObjectReplicationPolicyData IPersistableModel.Creat using JsonDocument document = JsonDocument.Parse(data); return DeserializeObjectReplicationPolicyData(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(ObjectReplicationPolicyData)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ObjectReplicationPolicyFilter.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ObjectReplicationPolicyFilter.Serialization.cs index 41500a25c141f..1b391d80c768f 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ObjectReplicationPolicyFilter.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ObjectReplicationPolicyFilter.Serialization.cs @@ -8,8 +8,11 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Linq; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -113,6 +116,113 @@ internal static ObjectReplicationPolicyFilter DeserializeObjectReplicationPolicy return new ObjectReplicationPolicyFilter(Optional.ToList(prefixMatch), minCreationTime.Value, serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(PrefixMatch), out propertyOverride); + if (Optional.IsCollectionDefined(PrefixMatch) || hasPropertyOverride) + { + if (PrefixMatch.Any() || hasPropertyOverride) + { + builder.Append(" prefixMatch:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine(" ["); + foreach (var item in PrefixMatch) + { + if (item == null) + { + builder.Append("null"); + continue; + } + if (item.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{item}'''"); + } + else + { + builder.AppendLine($" '{item}'"); + } + } + builder.AppendLine(" ]"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(MinCreationTime), out propertyOverride); + if (Optional.IsDefined(MinCreationTime) || hasPropertyOverride) + { + builder.Append(" minCreationTime:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (MinCreationTime.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{MinCreationTime}'''"); + } + else + { + builder.AppendLine($" '{MinCreationTime}'"); + } + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -121,6 +231,8 @@ BinaryData IPersistableModel.Write(ModelReaderWri { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(ObjectReplicationPolicyFilter)} does not support '{options.Format}' format."); } @@ -137,6 +249,8 @@ ObjectReplicationPolicyFilter IPersistableModel.C using JsonDocument document = JsonDocument.Parse(data); return DeserializeObjectReplicationPolicyFilter(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(ObjectReplicationPolicyFilter)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ObjectReplicationPolicyRule.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ObjectReplicationPolicyRule.Serialization.cs index 869b79dcb25a4..b92d6f2f0d333 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ObjectReplicationPolicyRule.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ObjectReplicationPolicyRule.Serialization.cs @@ -8,8 +8,10 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -119,6 +121,136 @@ internal static ObjectReplicationPolicyRule DeserializeObjectReplicationPolicyRu return new ObjectReplicationPolicyRule(ruleId.Value, sourceContainer, destinationContainer, filters.Value, serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(RuleId), out propertyOverride); + if (Optional.IsDefined(RuleId) || hasPropertyOverride) + { + builder.Append(" ruleId:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (RuleId.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{RuleId}'''"); + } + else + { + builder.AppendLine($" '{RuleId}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(SourceContainer), out propertyOverride); + if (Optional.IsDefined(SourceContainer) || hasPropertyOverride) + { + builder.Append(" sourceContainer:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (SourceContainer.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{SourceContainer}'''"); + } + else + { + builder.AppendLine($" '{SourceContainer}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(DestinationContainer), out propertyOverride); + if (Optional.IsDefined(DestinationContainer) || hasPropertyOverride) + { + builder.Append(" destinationContainer:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (DestinationContainer.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{DestinationContainer}'''"); + } + else + { + builder.AppendLine($" '{DestinationContainer}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Filters), out propertyOverride); + if (Optional.IsDefined(Filters) || hasPropertyOverride) + { + builder.Append(" filters:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, Filters, options, 2, false); + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -127,6 +259,8 @@ BinaryData IPersistableModel.Write(ModelReaderWrite { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(ObjectReplicationPolicyRule)} does not support '{options.Format}' format."); } @@ -143,6 +277,8 @@ ObjectReplicationPolicyRule IPersistableModel.Creat using JsonDocument document = JsonDocument.Parse(data); return DeserializeObjectReplicationPolicyRule(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(ObjectReplicationPolicyRule)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ProtectedAppendWritesHistory.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ProtectedAppendWritesHistory.Serialization.cs index fe9e5b425386c..fac2011fb1bca 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ProtectedAppendWritesHistory.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ProtectedAppendWritesHistory.Serialization.cs @@ -8,8 +8,10 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -107,6 +109,86 @@ internal static ProtectedAppendWritesHistory DeserializeProtectedAppendWritesHis return new ProtectedAppendWritesHistory(Optional.ToNullable(allowProtectedAppendWritesAll), Optional.ToNullable(timestamp), serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(AllowProtectedAppendWritesAll), out propertyOverride); + if (Optional.IsDefined(AllowProtectedAppendWritesAll) || hasPropertyOverride) + { + builder.Append(" allowProtectedAppendWritesAll:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var boolValue = AllowProtectedAppendWritesAll.Value == true ? "true" : "false"; + builder.AppendLine($" {boolValue}"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Timestamp), out propertyOverride); + if (Optional.IsDefined(Timestamp) || hasPropertyOverride) + { + builder.Append(" timestamp:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var formattedDateTimeString = TypeFormatters.ToString(Timestamp.Value, "o"); + builder.AppendLine($" '{formattedDateTimeString}'"); + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -115,6 +197,8 @@ BinaryData IPersistableModel.Write(ModelReaderWrit { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(ProtectedAppendWritesHistory)} does not support '{options.Format}' format."); } @@ -131,6 +215,8 @@ ProtectedAppendWritesHistory IPersistableModel.Cre using JsonDocument document = JsonDocument.Parse(data); return DeserializeProtectedAppendWritesHistory(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(ProtectedAppendWritesHistory)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ProtocolSettings.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ProtocolSettings.Serialization.cs index fceb6eb7b66c5..9b93af83351fb 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ProtocolSettings.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/ProtocolSettings.Serialization.cs @@ -8,8 +8,10 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -92,6 +94,70 @@ internal static ProtocolSettings DeserializeProtocolSettings(JsonElement element return new ProtocolSettings(smb.Value, serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(SmbSetting), out propertyOverride); + if (Optional.IsDefined(SmbSetting) || hasPropertyOverride) + { + builder.Append(" smb:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, SmbSetting, options, 2, false); + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -100,6 +166,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOptions op { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(ProtocolSettings)} does not support '{options.Format}' format."); } @@ -116,6 +184,8 @@ ProtocolSettings IPersistableModel.Create(BinaryData data, Mod using JsonDocument document = JsonDocument.Parse(data); return DeserializeProtocolSettings(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(ProtocolSettings)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/QueueServiceData.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/QueueServiceData.Serialization.cs index d480e1ba3b4eb..fb8351dead6b5 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/QueueServiceData.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/QueueServiceData.Serialization.cs @@ -8,8 +8,10 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; using Azure.ResourceManager.Models; using Azure.ResourceManager.Storage.Models; @@ -157,6 +159,123 @@ internal static QueueServiceData DeserializeQueueServiceData(JsonElement element return new QueueServiceData(id, name, type, systemData.Value, cors.Value, serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Name), out propertyOverride); + if (Optional.IsDefined(Name) || hasPropertyOverride) + { + builder.Append(" name:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (Name.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{Name}'''"); + } + else + { + builder.AppendLine($" '{Name}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Id), out propertyOverride); + if (Optional.IsDefined(Id) || hasPropertyOverride) + { + builder.Append(" id:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{Id.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(SystemData), out propertyOverride); + if (Optional.IsDefined(SystemData) || hasPropertyOverride) + { + builder.Append(" systemData:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{SystemData.ToString()}'"); + } + } + + builder.Append(" properties:"); + builder.AppendLine(" {"); + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Cors), out propertyOverride); + if (Optional.IsDefined(Cors) || hasPropertyOverride) + { + builder.Append(" cors:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, Cors, options, 4, false); + } + } + + builder.AppendLine(" }"); + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -165,6 +284,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOptions op { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(QueueServiceData)} does not support '{options.Format}' format."); } @@ -181,6 +302,8 @@ QueueServiceData IPersistableModel.Create(BinaryData data, Mod using JsonDocument document = JsonDocument.Parse(data); return DeserializeQueueServiceData(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(QueueServiceData)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/RestorePolicy.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/RestorePolicy.Serialization.cs index 2dfbab8372e57..b35a0014b9422 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/RestorePolicy.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/RestorePolicy.Serialization.cs @@ -8,8 +8,10 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -130,6 +132,115 @@ internal static RestorePolicy DeserializeRestorePolicy(JsonElement element, Mode return new RestorePolicy(enabled, Optional.ToNullable(days), Optional.ToNullable(lastEnabledTime), Optional.ToNullable(minRestoreTime), serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(IsEnabled), out propertyOverride); + if (Optional.IsDefined(IsEnabled) || hasPropertyOverride) + { + builder.Append(" enabled:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var boolValue = IsEnabled == true ? "true" : "false"; + builder.AppendLine($" {boolValue}"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Days), out propertyOverride); + if (Optional.IsDefined(Days) || hasPropertyOverride) + { + builder.Append(" days:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" {Days.Value}"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(LastEnabledOn), out propertyOverride); + if (Optional.IsDefined(LastEnabledOn) || hasPropertyOverride) + { + builder.Append(" lastEnabledTime:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var formattedDateTimeString = TypeFormatters.ToString(LastEnabledOn.Value, "o"); + builder.AppendLine($" '{formattedDateTimeString}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(MinRestoreOn), out propertyOverride); + if (Optional.IsDefined(MinRestoreOn) || hasPropertyOverride) + { + builder.Append(" minRestoreTime:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var formattedDateTimeString = TypeFormatters.ToString(MinRestoreOn.Value, "o"); + builder.AppendLine($" '{formattedDateTimeString}'"); + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -138,6 +249,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOptions optio { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(RestorePolicy)} does not support '{options.Format}' format."); } @@ -154,6 +267,8 @@ RestorePolicy IPersistableModel.Create(BinaryData data, ModelRead using JsonDocument document = JsonDocument.Parse(data); return DeserializeRestorePolicy(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(RestorePolicy)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/SmbSetting.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/SmbSetting.Serialization.cs index 1a7f61534e6a7..58bd98f18fee9 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/SmbSetting.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/SmbSetting.Serialization.cs @@ -8,8 +8,10 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -136,6 +138,158 @@ internal static SmbSetting DeserializeSmbSetting(JsonElement element, ModelReade return new SmbSetting(multichannel.Value, versions.Value, authenticationMethods.Value, kerberosTicketEncryption.Value, channelEncryption.Value, serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Multichannel), out propertyOverride); + if (Optional.IsDefined(Multichannel) || hasPropertyOverride) + { + builder.Append(" multichannel:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, Multichannel, options, 2, false); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Versions), out propertyOverride); + if (Optional.IsDefined(Versions) || hasPropertyOverride) + { + builder.Append(" versions:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (Versions.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{Versions}'''"); + } + else + { + builder.AppendLine($" '{Versions}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(AuthenticationMethods), out propertyOverride); + if (Optional.IsDefined(AuthenticationMethods) || hasPropertyOverride) + { + builder.Append(" authenticationMethods:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (AuthenticationMethods.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{AuthenticationMethods}'''"); + } + else + { + builder.AppendLine($" '{AuthenticationMethods}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(KerberosTicketEncryption), out propertyOverride); + if (Optional.IsDefined(KerberosTicketEncryption) || hasPropertyOverride) + { + builder.Append(" kerberosTicketEncryption:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (KerberosTicketEncryption.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{KerberosTicketEncryption}'''"); + } + else + { + builder.AppendLine($" '{KerberosTicketEncryption}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ChannelEncryption), out propertyOverride); + if (Optional.IsDefined(ChannelEncryption) || hasPropertyOverride) + { + builder.Append(" channelEncryption:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (ChannelEncryption.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{ChannelEncryption}'''"); + } + else + { + builder.AppendLine($" '{ChannelEncryption}'"); + } + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -144,6 +298,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(SmbSetting)} does not support '{options.Format}' format."); } @@ -160,6 +316,8 @@ SmbSetting IPersistableModel.Create(BinaryData data, ModelReaderWrit using JsonDocument document = JsonDocument.Parse(data); return DeserializeSmbSetting(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(SmbSetting)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageAccountData.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageAccountData.Serialization.cs index f493b9965099e..178e98ac28143 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageAccountData.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageAccountData.Serialization.cs @@ -8,8 +8,11 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Linq; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; using Azure.ResourceManager.Models; using Azure.ResourceManager.Resources.Models; using Azure.ResourceManager.Storage.Models; @@ -819,6 +822,767 @@ internal static StorageAccountData DeserializeStorageAccountData(JsonElement ele return new StorageAccountData(id, name, type, systemData.Value, Optional.ToDictionary(tags), location, sku.Value, Optional.ToNullable(kind), identity, extendedLocation, Optional.ToNullable(provisioningState), primaryEndpoints.Value, Optional.ToNullable(primaryLocation), Optional.ToNullable(statusOfPrimary), Optional.ToNullable(lastGeoFailoverTime), Optional.ToNullable(secondaryLocation), Optional.ToNullable(statusOfSecondary), Optional.ToNullable(creationTime), customDomain.Value, sasPolicy.Value, keyPolicy.Value, keyCreationTime.Value, secondaryEndpoints.Value, encryption.Value, Optional.ToNullable(accessTier), azureFilesIdentityBasedAuthentication.Value, Optional.ToNullable(supportsHttpsTrafficOnly), networkAcls.Value, Optional.ToNullable(isSftpEnabled), Optional.ToNullable(isLocalUserEnabled), Optional.ToNullable(isHnsEnabled), geoReplicationStats.Value, Optional.ToNullable(failoverInProgress), Optional.ToNullable(largeFileSharesState), Optional.ToList(privateEndpointConnections), routingPreference.Value, blobRestoreStatus.Value, Optional.ToNullable(allowBlobPublicAccess), Optional.ToNullable(minimumTlsVersion), Optional.ToNullable(allowSharedKeyAccess), Optional.ToNullable(isNfsV3Enabled), Optional.ToNullable(allowCrossTenantReplication), Optional.ToNullable(defaultToOAuthAuthentication), Optional.ToNullable(publicNetworkAccess), immutableStorageWithVersioning.Value, Optional.ToNullable(allowedCopyScope), storageAccountSkuConversionStatus.Value, Optional.ToNullable(dnsEndpointType), serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Name), out propertyOverride); + if (Optional.IsDefined(Name) || hasPropertyOverride) + { + builder.Append(" name:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (Name.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{Name}'''"); + } + else + { + builder.AppendLine($" '{Name}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Location), out propertyOverride); + if (Optional.IsDefined(Location) || hasPropertyOverride) + { + builder.Append(" location:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{Location.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Tags), out propertyOverride); + if (Optional.IsCollectionDefined(Tags) || hasPropertyOverride) + { + if (Tags.Any() || hasPropertyOverride) + { + builder.Append(" tags:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine(" {"); + foreach (var item in Tags) + { + builder.Append($" {item.Key}:"); + if (item.Value == null) + { + builder.Append("null"); + continue; + } + if (item.Value.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{item.Value}'''"); + } + else + { + builder.AppendLine($" '{item.Value}'"); + } + } + builder.AppendLine(" }"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Sku), out propertyOverride); + if (Optional.IsDefined(Sku) || hasPropertyOverride) + { + builder.Append(" sku:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, Sku, options, 2, false); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Kind), out propertyOverride); + if (Optional.IsDefined(Kind) || hasPropertyOverride) + { + builder.Append(" kind:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{Kind.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Identity), out propertyOverride); + if (Optional.IsDefined(Identity) || hasPropertyOverride) + { + builder.Append(" identity:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, Identity, options, 2, false); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ExtendedLocation), out propertyOverride); + if (Optional.IsDefined(ExtendedLocation) || hasPropertyOverride) + { + builder.Append(" extendedLocation:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, ExtendedLocation, options, 2, false); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Id), out propertyOverride); + if (Optional.IsDefined(Id) || hasPropertyOverride) + { + builder.Append(" id:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{Id.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(SystemData), out propertyOverride); + if (Optional.IsDefined(SystemData) || hasPropertyOverride) + { + builder.Append(" systemData:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{SystemData.ToString()}'"); + } + } + + builder.Append(" properties:"); + builder.AppendLine(" {"); + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ProvisioningState), out propertyOverride); + if (Optional.IsDefined(ProvisioningState) || hasPropertyOverride) + { + builder.Append(" provisioningState:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{ProvisioningState.Value.ToSerialString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(PrimaryEndpoints), out propertyOverride); + if (Optional.IsDefined(PrimaryEndpoints) || hasPropertyOverride) + { + builder.Append(" primaryEndpoints:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, PrimaryEndpoints, options, 4, false); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(PrimaryLocation), out propertyOverride); + if (Optional.IsDefined(PrimaryLocation) || hasPropertyOverride) + { + builder.Append(" primaryLocation:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{PrimaryLocation.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(StatusOfPrimary), out propertyOverride); + if (Optional.IsDefined(StatusOfPrimary) || hasPropertyOverride) + { + builder.Append(" statusOfPrimary:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{StatusOfPrimary.Value.ToSerialString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(LastGeoFailoverOn), out propertyOverride); + if (Optional.IsDefined(LastGeoFailoverOn) || hasPropertyOverride) + { + builder.Append(" lastGeoFailoverTime:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var formattedDateTimeString = TypeFormatters.ToString(LastGeoFailoverOn.Value, "o"); + builder.AppendLine($" '{formattedDateTimeString}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(SecondaryLocation), out propertyOverride); + if (Optional.IsDefined(SecondaryLocation) || hasPropertyOverride) + { + builder.Append(" secondaryLocation:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{SecondaryLocation.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(StatusOfSecondary), out propertyOverride); + if (Optional.IsDefined(StatusOfSecondary) || hasPropertyOverride) + { + builder.Append(" statusOfSecondary:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{StatusOfSecondary.Value.ToSerialString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(CreatedOn), out propertyOverride); + if (Optional.IsDefined(CreatedOn) || hasPropertyOverride) + { + builder.Append(" creationTime:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var formattedDateTimeString = TypeFormatters.ToString(CreatedOn.Value, "o"); + builder.AppendLine($" '{formattedDateTimeString}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(CustomDomain), out propertyOverride); + if (Optional.IsDefined(CustomDomain) || hasPropertyOverride) + { + builder.Append(" customDomain:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, CustomDomain, options, 4, false); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(SasPolicy), out propertyOverride); + if (Optional.IsDefined(SasPolicy) || hasPropertyOverride) + { + builder.Append(" sasPolicy:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, SasPolicy, options, 4, false); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(KeyPolicy), out propertyOverride); + if (Optional.IsDefined(KeyPolicy) || hasPropertyOverride) + { + builder.Append(" keyPolicy:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, KeyPolicy, options, 4, false); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(KeyCreationTime), out propertyOverride); + if (Optional.IsDefined(KeyCreationTime) || hasPropertyOverride) + { + builder.Append(" keyCreationTime:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, KeyCreationTime, options, 4, false); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(SecondaryEndpoints), out propertyOverride); + if (Optional.IsDefined(SecondaryEndpoints) || hasPropertyOverride) + { + builder.Append(" secondaryEndpoints:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, SecondaryEndpoints, options, 4, false); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Encryption), out propertyOverride); + if (Optional.IsDefined(Encryption) || hasPropertyOverride) + { + builder.Append(" encryption:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, Encryption, options, 4, false); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(AccessTier), out propertyOverride); + if (Optional.IsDefined(AccessTier) || hasPropertyOverride) + { + builder.Append(" accessTier:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{AccessTier.Value.ToSerialString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(AzureFilesIdentityBasedAuthentication), out propertyOverride); + if (Optional.IsDefined(AzureFilesIdentityBasedAuthentication) || hasPropertyOverride) + { + builder.Append(" azureFilesIdentityBasedAuthentication:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, AzureFilesIdentityBasedAuthentication, options, 4, false); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(EnableHttpsTrafficOnly), out propertyOverride); + if (Optional.IsDefined(EnableHttpsTrafficOnly) || hasPropertyOverride) + { + builder.Append(" supportsHttpsTrafficOnly:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var boolValue = EnableHttpsTrafficOnly.Value == true ? "true" : "false"; + builder.AppendLine($" {boolValue}"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(NetworkRuleSet), out propertyOverride); + if (Optional.IsDefined(NetworkRuleSet) || hasPropertyOverride) + { + builder.Append(" networkAcls:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, NetworkRuleSet, options, 4, false); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(IsSftpEnabled), out propertyOverride); + if (Optional.IsDefined(IsSftpEnabled) || hasPropertyOverride) + { + builder.Append(" isSftpEnabled:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var boolValue = IsSftpEnabled.Value == true ? "true" : "false"; + builder.AppendLine($" {boolValue}"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(IsLocalUserEnabled), out propertyOverride); + if (Optional.IsDefined(IsLocalUserEnabled) || hasPropertyOverride) + { + builder.Append(" isLocalUserEnabled:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var boolValue = IsLocalUserEnabled.Value == true ? "true" : "false"; + builder.AppendLine($" {boolValue}"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(IsHnsEnabled), out propertyOverride); + if (Optional.IsDefined(IsHnsEnabled) || hasPropertyOverride) + { + builder.Append(" isHnsEnabled:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var boolValue = IsHnsEnabled.Value == true ? "true" : "false"; + builder.AppendLine($" {boolValue}"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(GeoReplicationStats), out propertyOverride); + if (Optional.IsDefined(GeoReplicationStats) || hasPropertyOverride) + { + builder.Append(" geoReplicationStats:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, GeoReplicationStats, options, 4, false); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(IsFailoverInProgress), out propertyOverride); + if (Optional.IsDefined(IsFailoverInProgress) || hasPropertyOverride) + { + builder.Append(" failoverInProgress:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var boolValue = IsFailoverInProgress.Value == true ? "true" : "false"; + builder.AppendLine($" {boolValue}"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(LargeFileSharesState), out propertyOverride); + if (Optional.IsDefined(LargeFileSharesState) || hasPropertyOverride) + { + builder.Append(" largeFileSharesState:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{LargeFileSharesState.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(PrivateEndpointConnections), out propertyOverride); + if (Optional.IsCollectionDefined(PrivateEndpointConnections) || hasPropertyOverride) + { + if (PrivateEndpointConnections.Any() || hasPropertyOverride) + { + builder.Append(" privateEndpointConnections:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine(" ["); + foreach (var item in PrivateEndpointConnections) + { + AppendChildObject(builder, item, options, 6, true); + } + builder.AppendLine(" ]"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(RoutingPreference), out propertyOverride); + if (Optional.IsDefined(RoutingPreference) || hasPropertyOverride) + { + builder.Append(" routingPreference:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, RoutingPreference, options, 4, false); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(BlobRestoreStatus), out propertyOverride); + if (Optional.IsDefined(BlobRestoreStatus) || hasPropertyOverride) + { + builder.Append(" blobRestoreStatus:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, BlobRestoreStatus, options, 4, false); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(AllowBlobPublicAccess), out propertyOverride); + if (Optional.IsDefined(AllowBlobPublicAccess) || hasPropertyOverride) + { + builder.Append(" allowBlobPublicAccess:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var boolValue = AllowBlobPublicAccess.Value == true ? "true" : "false"; + builder.AppendLine($" {boolValue}"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(MinimumTlsVersion), out propertyOverride); + if (Optional.IsDefined(MinimumTlsVersion) || hasPropertyOverride) + { + builder.Append(" minimumTlsVersion:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{MinimumTlsVersion.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(AllowSharedKeyAccess), out propertyOverride); + if (Optional.IsDefined(AllowSharedKeyAccess) || hasPropertyOverride) + { + builder.Append(" allowSharedKeyAccess:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var boolValue = AllowSharedKeyAccess.Value == true ? "true" : "false"; + builder.AppendLine($" {boolValue}"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(IsNfsV3Enabled), out propertyOverride); + if (Optional.IsDefined(IsNfsV3Enabled) || hasPropertyOverride) + { + builder.Append(" isNfsV3Enabled:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var boolValue = IsNfsV3Enabled.Value == true ? "true" : "false"; + builder.AppendLine($" {boolValue}"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(AllowCrossTenantReplication), out propertyOverride); + if (Optional.IsDefined(AllowCrossTenantReplication) || hasPropertyOverride) + { + builder.Append(" allowCrossTenantReplication:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var boolValue = AllowCrossTenantReplication.Value == true ? "true" : "false"; + builder.AppendLine($" {boolValue}"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(IsDefaultToOAuthAuthentication), out propertyOverride); + if (Optional.IsDefined(IsDefaultToOAuthAuthentication) || hasPropertyOverride) + { + builder.Append(" defaultToOAuthAuthentication:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var boolValue = IsDefaultToOAuthAuthentication.Value == true ? "true" : "false"; + builder.AppendLine($" {boolValue}"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(PublicNetworkAccess), out propertyOverride); + if (Optional.IsDefined(PublicNetworkAccess) || hasPropertyOverride) + { + builder.Append(" publicNetworkAccess:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{PublicNetworkAccess.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ImmutableStorageWithVersioning), out propertyOverride); + if (Optional.IsDefined(ImmutableStorageWithVersioning) || hasPropertyOverride) + { + builder.Append(" immutableStorageWithVersioning:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, ImmutableStorageWithVersioning, options, 4, false); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(AllowedCopyScope), out propertyOverride); + if (Optional.IsDefined(AllowedCopyScope) || hasPropertyOverride) + { + builder.Append(" allowedCopyScope:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{AllowedCopyScope.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(StorageAccountSkuConversionStatus), out propertyOverride); + if (Optional.IsDefined(StorageAccountSkuConversionStatus) || hasPropertyOverride) + { + builder.Append(" storageAccountSkuConversionStatus:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, StorageAccountSkuConversionStatus, options, 4, false); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(DnsEndpointType), out propertyOverride); + if (Optional.IsDefined(DnsEndpointType) || hasPropertyOverride) + { + builder.Append(" dnsEndpointType:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{DnsEndpointType.Value.ToString()}'"); + } + } + + builder.AppendLine(" }"); + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -827,6 +1591,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOptions { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(StorageAccountData)} does not support '{options.Format}' format."); } @@ -843,6 +1609,8 @@ StorageAccountData IPersistableModel.Create(BinaryData data, using JsonDocument document = JsonDocument.Parse(data); return DeserializeStorageAccountData(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(StorageAccountData)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageAccountEncryption.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageAccountEncryption.Serialization.cs index e9dadfa2c899b..d949a979d3f42 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageAccountEncryption.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageAccountEncryption.Serialization.cs @@ -8,8 +8,10 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -152,6 +154,127 @@ internal static StorageAccountEncryption DeserializeStorageAccountEncryption(Jso return new StorageAccountEncryption(services.Value, Optional.ToNullable(keySource), Optional.ToNullable(requireInfrastructureEncryption), keyvaultproperties.Value, identity.Value, serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Services), out propertyOverride); + if (Optional.IsDefined(Services) || hasPropertyOverride) + { + builder.Append(" services:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, Services, options, 2, false); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(KeySource), out propertyOverride); + if (Optional.IsDefined(KeySource) || hasPropertyOverride) + { + builder.Append(" keySource:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{KeySource.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(RequireInfrastructureEncryption), out propertyOverride); + if (Optional.IsDefined(RequireInfrastructureEncryption) || hasPropertyOverride) + { + builder.Append(" requireInfrastructureEncryption:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var boolValue = RequireInfrastructureEncryption.Value == true ? "true" : "false"; + builder.AppendLine($" {boolValue}"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(KeyVaultProperties), out propertyOverride); + if (Optional.IsDefined(KeyVaultProperties) || hasPropertyOverride) + { + builder.Append(" keyvaultproperties:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, KeyVaultProperties, options, 2, false); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(EncryptionIdentity), out propertyOverride); + if (Optional.IsDefined(EncryptionIdentity) || hasPropertyOverride) + { + builder.Append(" identity:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, EncryptionIdentity, options, 2, false); + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -160,6 +283,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOp { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(StorageAccountEncryption)} does not support '{options.Format}' format."); } @@ -176,6 +301,8 @@ StorageAccountEncryption IPersistableModel.Create(Bina using JsonDocument document = JsonDocument.Parse(data); return DeserializeStorageAccountEncryption(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(StorageAccountEncryption)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageAccountEncryptionIdentity.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageAccountEncryptionIdentity.Serialization.cs index ea5d7634b7756..4d2848fec58c9 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageAccountEncryptionIdentity.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageAccountEncryptionIdentity.Serialization.cs @@ -8,8 +8,10 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -99,6 +101,100 @@ internal static StorageAccountEncryptionIdentity DeserializeStorageAccountEncryp return new StorageAccountEncryptionIdentity(userAssignedIdentity.Value, federatedIdentityClientId.Value, serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(EncryptionUserAssignedIdentity), out propertyOverride); + if (Optional.IsDefined(EncryptionUserAssignedIdentity) || hasPropertyOverride) + { + builder.Append(" userAssignedIdentity:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (EncryptionUserAssignedIdentity.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{EncryptionUserAssignedIdentity}'''"); + } + else + { + builder.AppendLine($" '{EncryptionUserAssignedIdentity}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(EncryptionFederatedIdentityClientId), out propertyOverride); + if (Optional.IsDefined(EncryptionFederatedIdentityClientId) || hasPropertyOverride) + { + builder.Append(" federatedIdentityClientId:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (EncryptionFederatedIdentityClientId.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{EncryptionFederatedIdentityClientId}'''"); + } + else + { + builder.AppendLine($" '{EncryptionFederatedIdentityClientId}'"); + } + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -107,6 +203,8 @@ BinaryData IPersistableModel.Write(ModelReader { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(StorageAccountEncryptionIdentity)} does not support '{options.Format}' format."); } @@ -123,6 +221,8 @@ StorageAccountEncryptionIdentity IPersistableModel propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Blob), out propertyOverride); + if (Optional.IsDefined(Blob) || hasPropertyOverride) + { + builder.Append(" blob:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, Blob, options, 2, false); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(File), out propertyOverride); + if (Optional.IsDefined(File) || hasPropertyOverride) + { + builder.Append(" file:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, File, options, 2, false); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Table), out propertyOverride); + if (Optional.IsDefined(Table) || hasPropertyOverride) + { + builder.Append(" table:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, Table, options, 2, false); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Queue), out propertyOverride); + if (Optional.IsDefined(Queue) || hasPropertyOverride) + { + builder.Append(" queue:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, Queue, options, 2, false); + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -145,6 +253,8 @@ BinaryData IPersistableModel.Write(ModelReader { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(StorageAccountEncryptionServices)} does not support '{options.Format}' format."); } @@ -161,6 +271,8 @@ StorageAccountEncryptionServices IPersistableModel propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(BlobUri), out propertyOverride); + if (Optional.IsDefined(BlobUri) || hasPropertyOverride) + { + builder.Append(" blob:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{BlobUri.AbsoluteUri}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(QueueUri), out propertyOverride); + if (Optional.IsDefined(QueueUri) || hasPropertyOverride) + { + builder.Append(" queue:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{QueueUri.AbsoluteUri}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(TableUri), out propertyOverride); + if (Optional.IsDefined(TableUri) || hasPropertyOverride) + { + builder.Append(" table:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{TableUri.AbsoluteUri}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(FileUri), out propertyOverride); + if (Optional.IsDefined(FileUri) || hasPropertyOverride) + { + builder.Append(" file:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{FileUri.AbsoluteUri}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(WebUri), out propertyOverride); + if (Optional.IsDefined(WebUri) || hasPropertyOverride) + { + builder.Append(" web:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{WebUri.AbsoluteUri}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(DfsUri), out propertyOverride); + if (Optional.IsDefined(DfsUri) || hasPropertyOverride) + { + builder.Append(" dfs:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{DfsUri.AbsoluteUri}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(MicrosoftEndpoints), out propertyOverride); + if (Optional.IsDefined(MicrosoftEndpoints) || hasPropertyOverride) + { + builder.Append(" microsoftEndpoints:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, MicrosoftEndpoints, options, 2, false); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(InternetEndpoints), out propertyOverride); + if (Optional.IsDefined(InternetEndpoints) || hasPropertyOverride) + { + builder.Append(" internetEndpoints:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, InternetEndpoints, options, 2, false); + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -205,6 +369,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOpt { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(StorageAccountEndpoints)} does not support '{options.Format}' format."); } @@ -221,6 +387,8 @@ StorageAccountEndpoints IPersistableModel.Create(Binary using JsonDocument document = JsonDocument.Parse(data); return DeserializeStorageAccountEndpoints(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(StorageAccountEndpoints)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageAccountGetKeysResult.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageAccountGetKeysResult.Serialization.cs index 23986ff9232e6..ddc8560327d6d 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageAccountGetKeysResult.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageAccountGetKeysResult.Serialization.cs @@ -8,8 +8,11 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Linq; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -102,6 +105,78 @@ internal static StorageAccountGetKeysResult DeserializeStorageAccountGetKeysResu return new StorageAccountGetKeysResult(Optional.ToList(keys), serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Keys), out propertyOverride); + if (Optional.IsCollectionDefined(Keys) || hasPropertyOverride) + { + if (Keys.Any() || hasPropertyOverride) + { + builder.Append(" keys:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine(" ["); + foreach (var item in Keys) + { + AppendChildObject(builder, item, options, 4, true); + } + builder.AppendLine(" ]"); + } + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -110,6 +185,8 @@ BinaryData IPersistableModel.Write(ModelReaderWrite { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(StorageAccountGetKeysResult)} does not support '{options.Format}' format."); } @@ -126,6 +203,8 @@ StorageAccountGetKeysResult IPersistableModel.Creat using JsonDocument document = JsonDocument.Parse(data); return DeserializeStorageAccountGetKeysResult(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(StorageAccountGetKeysResult)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageAccountIPRule.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageAccountIPRule.Serialization.cs index 2d49e6d8e2bd6..e164f926840b4 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageAccountIPRule.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageAccountIPRule.Serialization.cs @@ -8,8 +8,10 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -100,6 +102,92 @@ internal static StorageAccountIPRule DeserializeStorageAccountIPRule(JsonElement return new StorageAccountIPRule(value, Optional.ToNullable(action), serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(IPAddressOrRange), out propertyOverride); + if (Optional.IsDefined(IPAddressOrRange) || hasPropertyOverride) + { + builder.Append(" value:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (IPAddressOrRange.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{IPAddressOrRange}'''"); + } + else + { + builder.AppendLine($" '{IPAddressOrRange}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Action), out propertyOverride); + if (Optional.IsDefined(Action) || hasPropertyOverride) + { + builder.Append(" action:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{Action.Value.ToString()}'"); + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -108,6 +196,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOption { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(StorageAccountIPRule)} does not support '{options.Format}' format."); } @@ -124,6 +214,8 @@ StorageAccountIPRule IPersistableModel.Create(BinaryData d using JsonDocument document = JsonDocument.Parse(data); return DeserializeStorageAccountIPRule(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(StorageAccountIPRule)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageAccountInternetEndpoints.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageAccountInternetEndpoints.Serialization.cs index d14abd1ce9373..d3003d0c83c09 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageAccountInternetEndpoints.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageAccountInternetEndpoints.Serialization.cs @@ -8,8 +8,10 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -137,6 +139,112 @@ internal static StorageAccountInternetEndpoints DeserializeStorageAccountInterne return new StorageAccountInternetEndpoints(blob.Value, file.Value, web.Value, dfs.Value, serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(BlobUri), out propertyOverride); + if (Optional.IsDefined(BlobUri) || hasPropertyOverride) + { + builder.Append(" blob:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{BlobUri.AbsoluteUri}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(FileUri), out propertyOverride); + if (Optional.IsDefined(FileUri) || hasPropertyOverride) + { + builder.Append(" file:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{FileUri.AbsoluteUri}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(WebUri), out propertyOverride); + if (Optional.IsDefined(WebUri) || hasPropertyOverride) + { + builder.Append(" web:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{WebUri.AbsoluteUri}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(DfsUri), out propertyOverride); + if (Optional.IsDefined(DfsUri) || hasPropertyOverride) + { + builder.Append(" dfs:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{DfsUri.AbsoluteUri}'"); + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -145,6 +253,8 @@ BinaryData IPersistableModel.Write(ModelReaderW { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(StorageAccountInternetEndpoints)} does not support '{options.Format}' format."); } @@ -161,6 +271,8 @@ StorageAccountInternetEndpoints IPersistableModel propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(KeyName), out propertyOverride); + if (Optional.IsDefined(KeyName) || hasPropertyOverride) + { + builder.Append(" keyName:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (KeyName.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{KeyName}'''"); + } + else + { + builder.AppendLine($" '{KeyName}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Value), out propertyOverride); + if (Optional.IsDefined(Value) || hasPropertyOverride) + { + builder.Append(" value:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (Value.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{Value}'''"); + } + else + { + builder.AppendLine($" '{Value}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Permissions), out propertyOverride); + if (Optional.IsDefined(Permissions) || hasPropertyOverride) + { + builder.Append(" permissions:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{Permissions.Value.ToSerialString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(CreatedOn), out propertyOverride); + if (Optional.IsDefined(CreatedOn) || hasPropertyOverride) + { + builder.Append(" creationTime:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var formattedDateTimeString = TypeFormatters.ToString(CreatedOn.Value, "o"); + builder.AppendLine($" '{formattedDateTimeString}'"); + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -137,6 +262,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOptions o { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(StorageAccountKey)} does not support '{options.Format}' format."); } @@ -153,6 +280,8 @@ StorageAccountKey IPersistableModel.Create(BinaryData data, M using JsonDocument document = JsonDocument.Parse(data); return DeserializeStorageAccountKey(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(StorageAccountKey)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageAccountKeyCreationTime.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageAccountKeyCreationTime.Serialization.cs index 8147d19f19703..93d8cd212258d 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageAccountKeyCreationTime.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageAccountKeyCreationTime.Serialization.cs @@ -8,8 +8,10 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -107,6 +109,86 @@ internal static StorageAccountKeyCreationTime DeserializeStorageAccountKeyCreati return new StorageAccountKeyCreationTime(Optional.ToNullable(key1), Optional.ToNullable(key2), serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Key1), out propertyOverride); + if (Optional.IsDefined(Key1) || hasPropertyOverride) + { + builder.Append(" key1:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var formattedDateTimeString = TypeFormatters.ToString(Key1.Value, "o"); + builder.AppendLine($" '{formattedDateTimeString}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Key2), out propertyOverride); + if (Optional.IsDefined(Key2) || hasPropertyOverride) + { + builder.Append(" key2:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var formattedDateTimeString = TypeFormatters.ToString(Key2.Value, "o"); + builder.AppendLine($" '{formattedDateTimeString}'"); + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -115,6 +197,8 @@ BinaryData IPersistableModel.Write(ModelReaderWri { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(StorageAccountKeyCreationTime)} does not support '{options.Format}' format."); } @@ -131,6 +215,8 @@ StorageAccountKeyCreationTime IPersistableModel.C using JsonDocument document = JsonDocument.Parse(data); return DeserializeStorageAccountKeyCreationTime(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(StorageAccountKeyCreationTime)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageAccountKeyPolicy.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageAccountKeyPolicy.Serialization.cs index c12c2813fab6a..76bd308c66254 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageAccountKeyPolicy.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageAccountKeyPolicy.Serialization.cs @@ -8,8 +8,10 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -85,6 +87,70 @@ internal static StorageAccountKeyPolicy DeserializeStorageAccountKeyPolicy(JsonE return new StorageAccountKeyPolicy(keyExpirationPeriodInDays, serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(KeyExpirationPeriodInDays), out propertyOverride); + if (Optional.IsDefined(KeyExpirationPeriodInDays) || hasPropertyOverride) + { + builder.Append(" keyExpirationPeriodInDays:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" {KeyExpirationPeriodInDays}"); + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -93,6 +159,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOpt { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(StorageAccountKeyPolicy)} does not support '{options.Format}' format."); } @@ -109,6 +177,8 @@ StorageAccountKeyPolicy IPersistableModel.Create(Binary using JsonDocument document = JsonDocument.Parse(data); return DeserializeStorageAccountKeyPolicy(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(StorageAccountKeyPolicy)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageAccountKeyVaultProperties.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageAccountKeyVaultProperties.Serialization.cs index 8122f335053c1..25ff0b568329e 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageAccountKeyVaultProperties.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageAccountKeyVaultProperties.Serialization.cs @@ -8,8 +8,10 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -155,6 +157,166 @@ internal static StorageAccountKeyVaultProperties DeserializeStorageAccountKeyVau return new StorageAccountKeyVaultProperties(keyname.Value, keyversion.Value, keyvaulturi.Value, currentVersionedKeyIdentifier.Value, Optional.ToNullable(lastKeyRotationTimestamp), Optional.ToNullable(currentVersionedKeyExpirationTimestamp), serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(KeyName), out propertyOverride); + if (Optional.IsDefined(KeyName) || hasPropertyOverride) + { + builder.Append(" keyname:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (KeyName.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{KeyName}'''"); + } + else + { + builder.AppendLine($" '{KeyName}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(KeyVersion), out propertyOverride); + if (Optional.IsDefined(KeyVersion) || hasPropertyOverride) + { + builder.Append(" keyversion:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (KeyVersion.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{KeyVersion}'''"); + } + else + { + builder.AppendLine($" '{KeyVersion}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(KeyVaultUri), out propertyOverride); + if (Optional.IsDefined(KeyVaultUri) || hasPropertyOverride) + { + builder.Append(" keyvaulturi:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{KeyVaultUri.AbsoluteUri}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(CurrentVersionedKeyIdentifier), out propertyOverride); + if (Optional.IsDefined(CurrentVersionedKeyIdentifier) || hasPropertyOverride) + { + builder.Append(" currentVersionedKeyIdentifier:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (CurrentVersionedKeyIdentifier.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{CurrentVersionedKeyIdentifier}'''"); + } + else + { + builder.AppendLine($" '{CurrentVersionedKeyIdentifier}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(LastKeyRotationTimestamp), out propertyOverride); + if (Optional.IsDefined(LastKeyRotationTimestamp) || hasPropertyOverride) + { + builder.Append(" lastKeyRotationTimestamp:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var formattedDateTimeString = TypeFormatters.ToString(LastKeyRotationTimestamp.Value, "o"); + builder.AppendLine($" '{formattedDateTimeString}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(CurrentVersionedKeyExpirationTimestamp), out propertyOverride); + if (Optional.IsDefined(CurrentVersionedKeyExpirationTimestamp) || hasPropertyOverride) + { + builder.Append(" currentVersionedKeyExpirationTimestamp:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var formattedDateTimeString = TypeFormatters.ToString(CurrentVersionedKeyExpirationTimestamp.Value, "o"); + builder.AppendLine($" '{formattedDateTimeString}'"); + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -163,6 +325,8 @@ BinaryData IPersistableModel.Write(ModelReader { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(StorageAccountKeyVaultProperties)} does not support '{options.Format}' format."); } @@ -179,6 +343,8 @@ StorageAccountKeyVaultProperties IPersistableModel propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Value), out propertyOverride); + if (Optional.IsCollectionDefined(Value) || hasPropertyOverride) + { + if (Value.Any() || hasPropertyOverride) + { + builder.Append(" value:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine(" ["); + foreach (var item in Value) + { + AppendChildObject(builder, item, options, 4, true); + } + builder.AppendLine(" ]"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(NextLink), out propertyOverride); + if (Optional.IsDefined(NextLink) || hasPropertyOverride) + { + builder.Append(" nextLink:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (NextLink.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{NextLink}'''"); + } + else + { + builder.AppendLine($" '{NextLink}'"); + } + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -122,6 +219,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOp { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(StorageAccountListResult)} does not support '{options.Format}' format."); } @@ -138,6 +237,8 @@ StorageAccountListResult IPersistableModel.Create(Bina using JsonDocument document = JsonDocument.Parse(data); return DeserializeStorageAccountListResult(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(StorageAccountListResult)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageAccountLocalUserData.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageAccountLocalUserData.Serialization.cs index 3f527a1c1a678..e8d953c39e8ef 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageAccountLocalUserData.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageAccountLocalUserData.Serialization.cs @@ -8,8 +8,11 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Linq; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; using Azure.ResourceManager.Models; using Azure.ResourceManager.Storage.Models; @@ -259,6 +262,242 @@ internal static StorageAccountLocalUserData DeserializeStorageAccountLocalUserDa return new StorageAccountLocalUserData(id, name, type, systemData.Value, Optional.ToList(permissionScopes), homeDirectory.Value, Optional.ToList(sshAuthorizedKeys), sid.Value, Optional.ToNullable(hasSharedKey), Optional.ToNullable(hasSshKey), Optional.ToNullable(hasSshPassword), serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Name), out propertyOverride); + if (Optional.IsDefined(Name) || hasPropertyOverride) + { + builder.Append(" name:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (Name.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{Name}'''"); + } + else + { + builder.AppendLine($" '{Name}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Id), out propertyOverride); + if (Optional.IsDefined(Id) || hasPropertyOverride) + { + builder.Append(" id:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{Id.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(SystemData), out propertyOverride); + if (Optional.IsDefined(SystemData) || hasPropertyOverride) + { + builder.Append(" systemData:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{SystemData.ToString()}'"); + } + } + + builder.Append(" properties:"); + builder.AppendLine(" {"); + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(PermissionScopes), out propertyOverride); + if (Optional.IsCollectionDefined(PermissionScopes) || hasPropertyOverride) + { + if (PermissionScopes.Any() || hasPropertyOverride) + { + builder.Append(" permissionScopes:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine(" ["); + foreach (var item in PermissionScopes) + { + AppendChildObject(builder, item, options, 6, true); + } + builder.AppendLine(" ]"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(HomeDirectory), out propertyOverride); + if (Optional.IsDefined(HomeDirectory) || hasPropertyOverride) + { + builder.Append(" homeDirectory:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (HomeDirectory.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{HomeDirectory}'''"); + } + else + { + builder.AppendLine($" '{HomeDirectory}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(SshAuthorizedKeys), out propertyOverride); + if (Optional.IsCollectionDefined(SshAuthorizedKeys) || hasPropertyOverride) + { + if (SshAuthorizedKeys.Any() || hasPropertyOverride) + { + builder.Append(" sshAuthorizedKeys:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine(" ["); + foreach (var item in SshAuthorizedKeys) + { + AppendChildObject(builder, item, options, 6, true); + } + builder.AppendLine(" ]"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Sid), out propertyOverride); + if (Optional.IsDefined(Sid) || hasPropertyOverride) + { + builder.Append(" sid:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (Sid.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{Sid}'''"); + } + else + { + builder.AppendLine($" '{Sid}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(HasSharedKey), out propertyOverride); + if (Optional.IsDefined(HasSharedKey) || hasPropertyOverride) + { + builder.Append(" hasSharedKey:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var boolValue = HasSharedKey.Value == true ? "true" : "false"; + builder.AppendLine($" {boolValue}"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(HasSshKey), out propertyOverride); + if (Optional.IsDefined(HasSshKey) || hasPropertyOverride) + { + builder.Append(" hasSshKey:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var boolValue = HasSshKey.Value == true ? "true" : "false"; + builder.AppendLine($" {boolValue}"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(HasSshPassword), out propertyOverride); + if (Optional.IsDefined(HasSshPassword) || hasPropertyOverride) + { + builder.Append(" hasSshPassword:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var boolValue = HasSshPassword.Value == true ? "true" : "false"; + builder.AppendLine($" {boolValue}"); + } + } + + builder.AppendLine(" }"); + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -267,6 +506,8 @@ BinaryData IPersistableModel.Write(ModelReaderWrite { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(StorageAccountLocalUserData)} does not support '{options.Format}' format."); } @@ -283,6 +524,8 @@ StorageAccountLocalUserData IPersistableModel.Creat using JsonDocument document = JsonDocument.Parse(data); return DeserializeStorageAccountLocalUserData(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(StorageAccountLocalUserData)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageAccountManagementPolicyData.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageAccountManagementPolicyData.Serialization.cs index b409381af3d87..d2e54b15b04e2 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageAccountManagementPolicyData.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageAccountManagementPolicyData.Serialization.cs @@ -8,8 +8,10 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; using Azure.ResourceManager.Models; using Azure.ResourceManager.Storage.Models; @@ -172,6 +174,138 @@ internal static StorageAccountManagementPolicyData DeserializeStorageAccountMana return new StorageAccountManagementPolicyData(id, name, type, systemData.Value, Optional.ToNullable(lastModifiedTime), policy.Value, serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Name), out propertyOverride); + if (Optional.IsDefined(Name) || hasPropertyOverride) + { + builder.Append(" name:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (Name.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{Name}'''"); + } + else + { + builder.AppendLine($" '{Name}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Id), out propertyOverride); + if (Optional.IsDefined(Id) || hasPropertyOverride) + { + builder.Append(" id:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{Id.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(SystemData), out propertyOverride); + if (Optional.IsDefined(SystemData) || hasPropertyOverride) + { + builder.Append(" systemData:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{SystemData.ToString()}'"); + } + } + + builder.Append(" properties:"); + builder.AppendLine(" {"); + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(LastModifiedOn), out propertyOverride); + if (Optional.IsDefined(LastModifiedOn) || hasPropertyOverride) + { + builder.Append(" lastModifiedTime:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var formattedDateTimeString = TypeFormatters.ToString(LastModifiedOn.Value, "o"); + builder.AppendLine($" '{formattedDateTimeString}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Policy), out propertyOverride); + if (Optional.IsDefined(Policy) || hasPropertyOverride) + { + builder.Append(" policy:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, Policy, options, 4, false); + } + } + + builder.AppendLine(" }"); + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -180,6 +314,8 @@ BinaryData IPersistableModel.Write(ModelRead { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(StorageAccountManagementPolicyData)} does not support '{options.Format}' format."); } @@ -196,6 +332,8 @@ StorageAccountManagementPolicyData IPersistableModel propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(BlobUri), out propertyOverride); + if (Optional.IsDefined(BlobUri) || hasPropertyOverride) + { + builder.Append(" blob:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{BlobUri.AbsoluteUri}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(QueueUri), out propertyOverride); + if (Optional.IsDefined(QueueUri) || hasPropertyOverride) + { + builder.Append(" queue:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{QueueUri.AbsoluteUri}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(TableUri), out propertyOverride); + if (Optional.IsDefined(TableUri) || hasPropertyOverride) + { + builder.Append(" table:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{TableUri.AbsoluteUri}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(FileUri), out propertyOverride); + if (Optional.IsDefined(FileUri) || hasPropertyOverride) + { + builder.Append(" file:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{FileUri.AbsoluteUri}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(WebUri), out propertyOverride); + if (Optional.IsDefined(WebUri) || hasPropertyOverride) + { + builder.Append(" web:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{WebUri.AbsoluteUri}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(DfsUri), out propertyOverride); + if (Optional.IsDefined(DfsUri) || hasPropertyOverride) + { + builder.Append(" dfs:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{DfsUri.AbsoluteUri}'"); + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -175,6 +311,8 @@ BinaryData IPersistableModel.Write(ModelReader { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(StorageAccountMicrosoftEndpoints)} does not support '{options.Format}' format."); } @@ -191,6 +329,8 @@ StorageAccountMicrosoftEndpoints IPersistableModel propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(IsNameAvailable), out propertyOverride); + if (Optional.IsDefined(IsNameAvailable) || hasPropertyOverride) + { + builder.Append(" nameAvailable:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var boolValue = IsNameAvailable.Value == true ? "true" : "false"; + builder.AppendLine($" {boolValue}"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Reason), out propertyOverride); + if (Optional.IsDefined(Reason) || hasPropertyOverride) + { + builder.Append(" reason:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{Reason.Value.ToSerialString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Message), out propertyOverride); + if (Optional.IsDefined(Message) || hasPropertyOverride) + { + builder.Append(" message:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (Message.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{Message}'''"); + } + else + { + builder.AppendLine($" '{Message}'"); + } + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -126,6 +229,8 @@ BinaryData IPersistableModel.Write(ModelRe { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(StorageAccountNameAvailabilityResult)} does not support '{options.Format}' format."); } @@ -142,6 +247,8 @@ StorageAccountNameAvailabilityResult IPersistableModel propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Bypass), out propertyOverride); + if (Optional.IsDefined(Bypass) || hasPropertyOverride) + { + builder.Append(" bypass:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{Bypass.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ResourceAccessRules), out propertyOverride); + if (Optional.IsCollectionDefined(ResourceAccessRules) || hasPropertyOverride) + { + if (ResourceAccessRules.Any() || hasPropertyOverride) + { + builder.Append(" resourceAccessRules:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine(" ["); + foreach (var item in ResourceAccessRules) + { + AppendChildObject(builder, item, options, 4, true); + } + builder.AppendLine(" ]"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(VirtualNetworkRules), out propertyOverride); + if (Optional.IsCollectionDefined(VirtualNetworkRules) || hasPropertyOverride) + { + if (VirtualNetworkRules.Any() || hasPropertyOverride) + { + builder.Append(" virtualNetworkRules:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine(" ["); + foreach (var item in VirtualNetworkRules) + { + AppendChildObject(builder, item, options, 4, true); + } + builder.AppendLine(" ]"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(IPRules), out propertyOverride); + if (Optional.IsCollectionDefined(IPRules) || hasPropertyOverride) + { + if (IPRules.Any() || hasPropertyOverride) + { + builder.Append(" ipRules:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine(" ["); + foreach (var item in IPRules) + { + AppendChildObject(builder, item, options, 4, true); + } + builder.AppendLine(" ]"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(DefaultAction), out propertyOverride); + if (Optional.IsDefined(DefaultAction) || hasPropertyOverride) + { + builder.Append(" defaultAction:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{DefaultAction.ToSerialString()}'"); + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -183,6 +330,8 @@ BinaryData IPersistableModel.Write(ModelReaderWrit { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(StorageAccountNetworkRuleSet)} does not support '{options.Format}' format."); } @@ -199,6 +348,8 @@ StorageAccountNetworkRuleSet IPersistableModel.Cre using JsonDocument document = JsonDocument.Parse(data); return DeserializeStorageAccountNetworkRuleSet(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(StorageAccountNetworkRuleSet)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageAccountResourceAccessRule.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageAccountResourceAccessRule.Serialization.cs index 69d830fe2363a..14ab92eea4496 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageAccountResourceAccessRule.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageAccountResourceAccessRule.Serialization.cs @@ -8,8 +8,10 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -107,6 +109,84 @@ internal static StorageAccountResourceAccessRule DeserializeStorageAccountResour return new StorageAccountResourceAccessRule(Optional.ToNullable(tenantId), resourceId.Value, serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(TenantId), out propertyOverride); + if (Optional.IsDefined(TenantId) || hasPropertyOverride) + { + builder.Append(" tenantId:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{TenantId.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ResourceId), out propertyOverride); + if (Optional.IsDefined(ResourceId) || hasPropertyOverride) + { + builder.Append(" resourceId:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{ResourceId.ToString()}'"); + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -115,6 +195,8 @@ BinaryData IPersistableModel.Write(ModelReader { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(StorageAccountResourceAccessRule)} does not support '{options.Format}' format."); } @@ -131,6 +213,8 @@ StorageAccountResourceAccessRule IPersistableModel propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(SasExpirationPeriod), out propertyOverride); + if (Optional.IsDefined(SasExpirationPeriod) || hasPropertyOverride) + { + builder.Append(" sasExpirationPeriod:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (SasExpirationPeriod.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{SasExpirationPeriod}'''"); + } + else + { + builder.AppendLine($" '{SasExpirationPeriod}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ExpirationAction), out propertyOverride); + if (Optional.IsDefined(ExpirationAction) || hasPropertyOverride) + { + builder.Append(" expirationAction:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{ExpirationAction.ToString()}'"); + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -101,6 +189,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOpt { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(StorageAccountSasPolicy)} does not support '{options.Format}' format."); } @@ -117,6 +207,8 @@ StorageAccountSasPolicy IPersistableModel.Create(Binary using JsonDocument document = JsonDocument.Parse(data); return DeserializeStorageAccountSasPolicy(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(StorageAccountSasPolicy)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageAccountSkuConversionStatus.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageAccountSkuConversionStatus.Serialization.cs index 97c6e171df385..72304b64994bf 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageAccountSkuConversionStatus.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageAccountSkuConversionStatus.Serialization.cs @@ -8,8 +8,10 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -137,6 +139,114 @@ internal static StorageAccountSkuConversionStatus DeserializeStorageAccountSkuCo return new StorageAccountSkuConversionStatus(Optional.ToNullable(skuConversionStatus), Optional.ToNullable(targetSkuName), Optional.ToNullable(startTime), Optional.ToNullable(endTime), serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(SkuConversionStatus), out propertyOverride); + if (Optional.IsDefined(SkuConversionStatus) || hasPropertyOverride) + { + builder.Append(" skuConversionStatus:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{SkuConversionStatus.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(TargetSkuName), out propertyOverride); + if (Optional.IsDefined(TargetSkuName) || hasPropertyOverride) + { + builder.Append(" targetSkuName:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{TargetSkuName.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(StartOn), out propertyOverride); + if (Optional.IsDefined(StartOn) || hasPropertyOverride) + { + builder.Append(" startTime:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var formattedDateTimeString = TypeFormatters.ToString(StartOn.Value, "o"); + builder.AppendLine($" '{formattedDateTimeString}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(EndOn), out propertyOverride); + if (Optional.IsDefined(EndOn) || hasPropertyOverride) + { + builder.Append(" endTime:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var formattedDateTimeString = TypeFormatters.ToString(EndOn.Value, "o"); + builder.AppendLine($" '{formattedDateTimeString}'"); + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -145,6 +255,8 @@ BinaryData IPersistableModel.Write(ModelReade { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(StorageAccountSkuConversionStatus)} does not support '{options.Format}' format."); } @@ -161,6 +273,8 @@ StorageAccountSkuConversionStatus IPersistableModel propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(VirtualNetworkResourceId), out propertyOverride); + if (Optional.IsDefined(VirtualNetworkResourceId) || hasPropertyOverride) + { + builder.Append(" id:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{VirtualNetworkResourceId.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Action), out propertyOverride); + if (Optional.IsDefined(Action) || hasPropertyOverride) + { + builder.Append(" action:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{Action.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(State), out propertyOverride); + if (Optional.IsDefined(State) || hasPropertyOverride) + { + builder.Append(" state:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{State.Value.ToString()}'"); + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -123,6 +217,8 @@ BinaryData IPersistableModel.Write(ModelReader { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(StorageAccountVirtualNetworkRule)} does not support '{options.Format}' format."); } @@ -139,6 +235,8 @@ StorageAccountVirtualNetworkRule IPersistableModel propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(DomainName), out propertyOverride); + if (Optional.IsDefined(DomainName) || hasPropertyOverride) + { + builder.Append(" domainName:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (DomainName.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{DomainName}'''"); + } + else + { + builder.AppendLine($" '{DomainName}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(NetBiosDomainName), out propertyOverride); + if (Optional.IsDefined(NetBiosDomainName) || hasPropertyOverride) + { + builder.Append(" netBiosDomainName:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (NetBiosDomainName.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{NetBiosDomainName}'''"); + } + else + { + builder.AppendLine($" '{NetBiosDomainName}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ForestName), out propertyOverride); + if (Optional.IsDefined(ForestName) || hasPropertyOverride) + { + builder.Append(" forestName:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (ForestName.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{ForestName}'''"); + } + else + { + builder.AppendLine($" '{ForestName}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(DomainGuid), out propertyOverride); + if (Optional.IsDefined(DomainGuid) || hasPropertyOverride) + { + builder.Append(" domainGuid:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{DomainGuid.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(DomainSid), out propertyOverride); + if (Optional.IsDefined(DomainSid) || hasPropertyOverride) + { + builder.Append(" domainSid:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (DomainSid.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{DomainSid}'''"); + } + else + { + builder.AppendLine($" '{DomainSid}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(AzureStorageSid), out propertyOverride); + if (Optional.IsDefined(AzureStorageSid) || hasPropertyOverride) + { + builder.Append(" azureStorageSid:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (AzureStorageSid.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{AzureStorageSid}'''"); + } + else + { + builder.AppendLine($" '{AzureStorageSid}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(SamAccountName), out propertyOverride); + if (Optional.IsDefined(SamAccountName) || hasPropertyOverride) + { + builder.Append(" samAccountName:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (SamAccountName.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{SamAccountName}'''"); + } + else + { + builder.AppendLine($" '{SamAccountName}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(AccountType), out propertyOverride); + if (Optional.IsDefined(AccountType) || hasPropertyOverride) + { + builder.Append(" accountType:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{AccountType.Value.ToString()}'"); + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -171,6 +383,8 @@ BinaryData IPersistableModel.Write(ModelReader { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(StorageActiveDirectoryProperties)} does not support '{options.Format}' format."); } @@ -187,6 +401,8 @@ StorageActiveDirectoryProperties IPersistableModel propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(AllowedOrigins), out propertyOverride); + if (Optional.IsCollectionDefined(AllowedOrigins) || hasPropertyOverride) + { + if (AllowedOrigins.Any() || hasPropertyOverride) + { + builder.Append(" allowedOrigins:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine(" ["); + foreach (var item in AllowedOrigins) + { + if (item == null) + { + builder.Append("null"); + continue; + } + if (item.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{item}'''"); + } + else + { + builder.AppendLine($" '{item}'"); + } + } + builder.AppendLine(" ]"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(AllowedMethods), out propertyOverride); + if (Optional.IsCollectionDefined(AllowedMethods) || hasPropertyOverride) + { + if (AllowedMethods.Any() || hasPropertyOverride) + { + builder.Append(" allowedMethods:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine(" ["); + foreach (var item in AllowedMethods) + { + builder.AppendLine($" '{item.ToString()}'"); + } + builder.AppendLine(" ]"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(MaxAgeInSeconds), out propertyOverride); + if (Optional.IsDefined(MaxAgeInSeconds) || hasPropertyOverride) + { + builder.Append(" maxAgeInSeconds:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" {MaxAgeInSeconds}"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ExposedHeaders), out propertyOverride); + if (Optional.IsCollectionDefined(ExposedHeaders) || hasPropertyOverride) + { + if (ExposedHeaders.Any() || hasPropertyOverride) + { + builder.Append(" exposedHeaders:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine(" ["); + foreach (var item in ExposedHeaders) + { + if (item == null) + { + builder.Append("null"); + continue; + } + if (item.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{item}'''"); + } + else + { + builder.AppendLine($" '{item}'"); + } + } + builder.AppendLine(" ]"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(AllowedHeaders), out propertyOverride); + if (Optional.IsCollectionDefined(AllowedHeaders) || hasPropertyOverride) + { + if (AllowedHeaders.Any() || hasPropertyOverride) + { + builder.Append(" allowedHeaders:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine(" ["); + foreach (var item in AllowedHeaders) + { + if (item == null) + { + builder.Append("null"); + continue; + } + if (item.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{item}'''"); + } + else + { + builder.AppendLine($" '{item}'"); + } + } + builder.AppendLine(" ]"); + } + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -165,6 +359,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOptions opt { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(StorageCorsRule)} does not support '{options.Format}' format."); } @@ -181,6 +377,8 @@ StorageCorsRule IPersistableModel.Create(BinaryData data, Model using JsonDocument document = JsonDocument.Parse(data); return DeserializeStorageCorsRule(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(StorageCorsRule)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageCorsRules.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageCorsRules.Serialization.cs index ec4fe03915aa9..2670b8ac0f238 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageCorsRules.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageCorsRules.Serialization.cs @@ -8,8 +8,11 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Linq; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -102,6 +105,78 @@ internal static StorageCorsRules DeserializeStorageCorsRules(JsonElement element return new StorageCorsRules(Optional.ToList(corsRules), serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(CorsRules), out propertyOverride); + if (Optional.IsCollectionDefined(CorsRules) || hasPropertyOverride) + { + if (CorsRules.Any() || hasPropertyOverride) + { + builder.Append(" corsRules:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine(" ["); + foreach (var item in CorsRules) + { + AppendChildObject(builder, item, options, 4, true); + } + builder.AppendLine(" ]"); + } + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -110,6 +185,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOptions op { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(StorageCorsRules)} does not support '{options.Format}' format."); } @@ -126,6 +203,8 @@ StorageCorsRules IPersistableModel.Create(BinaryData data, Mod using JsonDocument document = JsonDocument.Parse(data); return DeserializeStorageCorsRules(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(StorageCorsRules)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageCustomDomain.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageCustomDomain.Serialization.cs index 054b53efd0ec6..a37acd9865357 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageCustomDomain.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageCustomDomain.Serialization.cs @@ -8,8 +8,10 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -100,6 +102,93 @@ internal static StorageCustomDomain DeserializeStorageCustomDomain(JsonElement e return new StorageCustomDomain(name, Optional.ToNullable(useSubDomainName), serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Name), out propertyOverride); + if (Optional.IsDefined(Name) || hasPropertyOverride) + { + builder.Append(" name:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (Name.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{Name}'''"); + } + else + { + builder.AppendLine($" '{Name}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(IsUseSubDomainNameEnabled), out propertyOverride); + if (Optional.IsDefined(IsUseSubDomainNameEnabled) || hasPropertyOverride) + { + builder.Append(" useSubDomainName:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var boolValue = IsUseSubDomainNameEnabled.Value == true ? "true" : "false"; + builder.AppendLine($" {boolValue}"); + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -108,6 +197,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOptions { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(StorageCustomDomain)} does not support '{options.Format}' format."); } @@ -124,6 +215,8 @@ StorageCustomDomain IPersistableModel.Create(BinaryData dat using JsonDocument document = JsonDocument.Parse(data); return DeserializeStorageCustomDomain(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(StorageCustomDomain)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageEncryptionService.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageEncryptionService.Serialization.cs index 4a55e32a507b9..72d514be53918 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageEncryptionService.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageEncryptionService.Serialization.cs @@ -8,8 +8,10 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -122,6 +124,100 @@ internal static StorageEncryptionService DeserializeStorageEncryptionService(Jso return new StorageEncryptionService(Optional.ToNullable(enabled), Optional.ToNullable(lastEnabledTime), Optional.ToNullable(keyType), serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(IsEnabled), out propertyOverride); + if (Optional.IsDefined(IsEnabled) || hasPropertyOverride) + { + builder.Append(" enabled:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var boolValue = IsEnabled.Value == true ? "true" : "false"; + builder.AppendLine($" {boolValue}"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(LastEnabledOn), out propertyOverride); + if (Optional.IsDefined(LastEnabledOn) || hasPropertyOverride) + { + builder.Append(" lastEnabledTime:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var formattedDateTimeString = TypeFormatters.ToString(LastEnabledOn.Value, "o"); + builder.AppendLine($" '{formattedDateTimeString}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(KeyType), out propertyOverride); + if (Optional.IsDefined(KeyType) || hasPropertyOverride) + { + builder.Append(" keyType:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{KeyType.Value.ToString()}'"); + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -130,6 +226,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOp { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(StorageEncryptionService)} does not support '{options.Format}' format."); } @@ -146,6 +244,8 @@ StorageEncryptionService IPersistableModel.Create(Bina using JsonDocument document = JsonDocument.Parse(data); return DeserializeStorageEncryptionService(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(StorageEncryptionService)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StoragePermissionScope.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StoragePermissionScope.Serialization.cs index d1086e45d0924..5e900222d948e 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StoragePermissionScope.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StoragePermissionScope.Serialization.cs @@ -8,8 +8,10 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -101,6 +103,122 @@ internal static StoragePermissionScope DeserializeStoragePermissionScope(JsonEle return new StoragePermissionScope(permissions, service, resourceName, serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Permissions), out propertyOverride); + if (Optional.IsDefined(Permissions) || hasPropertyOverride) + { + builder.Append(" permissions:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (Permissions.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{Permissions}'''"); + } + else + { + builder.AppendLine($" '{Permissions}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Service), out propertyOverride); + if (Optional.IsDefined(Service) || hasPropertyOverride) + { + builder.Append(" service:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (Service.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{Service}'''"); + } + else + { + builder.AppendLine($" '{Service}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ResourceName), out propertyOverride); + if (Optional.IsDefined(ResourceName) || hasPropertyOverride) + { + builder.Append(" resourceName:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (ResourceName.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{ResourceName}'''"); + } + else + { + builder.AppendLine($" '{ResourceName}'"); + } + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -109,6 +227,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOpti { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(StoragePermissionScope)} does not support '{options.Format}' format."); } @@ -125,6 +245,8 @@ StoragePermissionScope IPersistableModel.Create(BinaryDa using JsonDocument document = JsonDocument.Parse(data); return DeserializeStoragePermissionScope(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(StoragePermissionScope)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StoragePrivateEndpointConnectionData.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StoragePrivateEndpointConnectionData.Serialization.cs index 3b96721d0d3eb..6c9ad363736af 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StoragePrivateEndpointConnectionData.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StoragePrivateEndpointConnectionData.Serialization.cs @@ -8,8 +8,10 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; using Azure.ResourceManager.Models; using Azure.ResourceManager.Resources.Models; using Azure.ResourceManager.Storage.Models; @@ -188,6 +190,151 @@ internal static StoragePrivateEndpointConnectionData DeserializeStoragePrivateEn return new StoragePrivateEndpointConnectionData(id, name, type, systemData.Value, privateEndpoint, privateLinkServiceConnectionState.Value, Optional.ToNullable(provisioningState), serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Name), out propertyOverride); + if (Optional.IsDefined(Name) || hasPropertyOverride) + { + builder.Append(" name:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (Name.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{Name}'''"); + } + else + { + builder.AppendLine($" '{Name}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Id), out propertyOverride); + if (Optional.IsDefined(Id) || hasPropertyOverride) + { + builder.Append(" id:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{Id.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(SystemData), out propertyOverride); + if (Optional.IsDefined(SystemData) || hasPropertyOverride) + { + builder.Append(" systemData:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{SystemData.ToString()}'"); + } + } + + builder.Append(" properties:"); + builder.AppendLine(" {"); + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(PrivateEndpoint), out propertyOverride); + if (Optional.IsDefined(PrivateEndpoint) || hasPropertyOverride) + { + builder.Append(" privateEndpoint:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, PrivateEndpoint, options, 4, false); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ConnectionState), out propertyOverride); + if (Optional.IsDefined(ConnectionState) || hasPropertyOverride) + { + builder.Append(" privateLinkServiceConnectionState:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, ConnectionState, options, 4, false); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ProvisioningState), out propertyOverride); + if (Optional.IsDefined(ProvisioningState) || hasPropertyOverride) + { + builder.Append(" provisioningState:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{ProvisioningState.Value.ToString()}'"); + } + } + + builder.AppendLine(" }"); + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -196,6 +343,8 @@ BinaryData IPersistableModel.Write(ModelRe { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(StoragePrivateEndpointConnectionData)} does not support '{options.Format}' format."); } @@ -212,6 +361,8 @@ StoragePrivateEndpointConnectionData IPersistableModel propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Value), out propertyOverride); + if (Optional.IsCollectionDefined(Value) || hasPropertyOverride) + { + if (Value.Any() || hasPropertyOverride) + { + builder.Append(" value:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine(" ["); + foreach (var item in Value) + { + AppendChildObject(builder, item, options, 4, true); + } + builder.AppendLine(" ]"); + } + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -111,6 +186,8 @@ BinaryData IPersistableModel.Write(M { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(StoragePrivateEndpointConnectionListResult)} does not support '{options.Format}' format."); } @@ -127,6 +204,8 @@ StoragePrivateEndpointConnectionListResult IPersistableModel propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Name), out propertyOverride); + if (Optional.IsDefined(Name) || hasPropertyOverride) + { + builder.Append(" name:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (Name.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{Name}'''"); + } + else + { + builder.AppendLine($" '{Name}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Id), out propertyOverride); + if (Optional.IsDefined(Id) || hasPropertyOverride) + { + builder.Append(" id:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{Id.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(SystemData), out propertyOverride); + if (Optional.IsDefined(SystemData) || hasPropertyOverride) + { + builder.Append(" systemData:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{SystemData.ToString()}'"); + } + } + + builder.Append(" properties:"); + builder.AppendLine(" {"); + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(GroupId), out propertyOverride); + if (Optional.IsDefined(GroupId) || hasPropertyOverride) + { + builder.Append(" groupId:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{GroupId.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(RequiredMembers), out propertyOverride); + if (Optional.IsCollectionDefined(RequiredMembers) || hasPropertyOverride) + { + if (RequiredMembers.Any() || hasPropertyOverride) + { + builder.Append(" requiredMembers:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine(" ["); + foreach (var item in RequiredMembers) + { + if (item == null) + { + builder.Append("null"); + continue; + } + if (item.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{item}'''"); + } + else + { + builder.AppendLine($" '{item}'"); + } + } + builder.AppendLine(" ]"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(RequiredZoneNames), out propertyOverride); + if (Optional.IsCollectionDefined(RequiredZoneNames) || hasPropertyOverride) + { + if (RequiredZoneNames.Any() || hasPropertyOverride) + { + builder.Append(" requiredZoneNames:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine(" ["); + foreach (var item in RequiredZoneNames) + { + if (item == null) + { + builder.Append("null"); + continue; + } + if (item.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{item}'''"); + } + else + { + builder.AppendLine($" '{item}'"); + } + } + builder.AppendLine(" ]"); + } + } + } + + builder.AppendLine(" }"); + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -214,6 +404,8 @@ BinaryData IPersistableModel.Write(ModelReaderWr { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(StoragePrivateLinkResourceData)} does not support '{options.Format}' format."); } @@ -230,6 +422,8 @@ StoragePrivateLinkResourceData IPersistableModel using JsonDocument document = JsonDocument.Parse(data); return DeserializeStoragePrivateLinkResourceData(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(StoragePrivateLinkResourceData)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StoragePrivateLinkResourceListResult.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StoragePrivateLinkResourceListResult.Serialization.cs index 7ff492f0d08fb..9408a6a6d5ff0 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StoragePrivateLinkResourceListResult.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StoragePrivateLinkResourceListResult.Serialization.cs @@ -8,8 +8,11 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Linq; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -102,6 +105,78 @@ internal static StoragePrivateLinkResourceListResult DeserializeStoragePrivateLi return new StoragePrivateLinkResourceListResult(Optional.ToList(value), serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Value), out propertyOverride); + if (Optional.IsCollectionDefined(Value) || hasPropertyOverride) + { + if (Value.Any() || hasPropertyOverride) + { + builder.Append(" value:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine(" ["); + foreach (var item in Value) + { + AppendChildObject(builder, item, options, 4, true); + } + builder.AppendLine(" ]"); + } + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -110,6 +185,8 @@ BinaryData IPersistableModel.Write(ModelRe { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(StoragePrivateLinkResourceListResult)} does not support '{options.Format}' format."); } @@ -126,6 +203,8 @@ StoragePrivateLinkResourceListResult IPersistableModel propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Status), out propertyOverride); + if (Optional.IsDefined(Status) || hasPropertyOverride) + { + builder.Append(" status:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{Status.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Description), out propertyOverride); + if (Optional.IsDefined(Description) || hasPropertyOverride) + { + builder.Append(" description:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (Description.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{Description}'''"); + } + else + { + builder.AppendLine($" '{Description}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ActionRequired), out propertyOverride); + if (Optional.IsDefined(ActionRequired) || hasPropertyOverride) + { + builder.Append(" actionRequired:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (ActionRequired.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{ActionRequired}'''"); + } + else + { + builder.AppendLine($" '{ActionRequired}'"); + } + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -122,6 +232,8 @@ BinaryData IPersistableModel.Write(Mod { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(StoragePrivateLinkServiceConnectionState)} does not support '{options.Format}' format."); } @@ -138,6 +250,8 @@ StoragePrivateLinkServiceConnectionState IPersistableModel propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Name), out propertyOverride); + if (Optional.IsDefined(Name) || hasPropertyOverride) + { + builder.Append(" name:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (Name.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{Name}'''"); + } + else + { + builder.AppendLine($" '{Name}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Id), out propertyOverride); + if (Optional.IsDefined(Id) || hasPropertyOverride) + { + builder.Append(" id:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{Id.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(SystemData), out propertyOverride); + if (Optional.IsDefined(SystemData) || hasPropertyOverride) + { + builder.Append(" systemData:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{SystemData.ToString()}'"); + } + } + + builder.Append(" properties:"); + builder.AppendLine(" {"); + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Metadata), out propertyOverride); + if (Optional.IsCollectionDefined(Metadata) || hasPropertyOverride) + { + if (Metadata.Any() || hasPropertyOverride) + { + builder.Append(" metadata:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine(" {"); + foreach (var item in Metadata) + { + builder.Append($" {item.Key}:"); + if (item.Value == null) + { + builder.Append("null"); + continue; + } + if (item.Value.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{item.Value}'''"); + } + else + { + builder.AppendLine($" '{item.Value}'"); + } + } + builder.AppendLine(" }"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ApproximateMessageCount), out propertyOverride); + if (Optional.IsDefined(ApproximateMessageCount) || hasPropertyOverride) + { + builder.Append(" approximateMessageCount:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" {ApproximateMessageCount.Value}"); + } + } + + builder.AppendLine(" }"); + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -190,6 +346,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOptions op { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(StorageQueueData)} does not support '{options.Format}' format."); } @@ -206,6 +364,8 @@ StorageQueueData IPersistableModel.Create(BinaryData data, Mod using JsonDocument document = JsonDocument.Parse(data); return DeserializeStorageQueueData(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(StorageQueueData)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageRoutingPreference.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageRoutingPreference.Serialization.cs index c9de2129925d1..53b9fcc6a529a 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageRoutingPreference.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageRoutingPreference.Serialization.cs @@ -8,8 +8,10 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -122,6 +124,100 @@ internal static StorageRoutingPreference DeserializeStorageRoutingPreference(Jso return new StorageRoutingPreference(Optional.ToNullable(routingChoice), Optional.ToNullable(publishMicrosoftEndpoints), Optional.ToNullable(publishInternetEndpoints), serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(RoutingChoice), out propertyOverride); + if (Optional.IsDefined(RoutingChoice) || hasPropertyOverride) + { + builder.Append(" routingChoice:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{RoutingChoice.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(IsMicrosoftEndpointsPublished), out propertyOverride); + if (Optional.IsDefined(IsMicrosoftEndpointsPublished) || hasPropertyOverride) + { + builder.Append(" publishMicrosoftEndpoints:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var boolValue = IsMicrosoftEndpointsPublished.Value == true ? "true" : "false"; + builder.AppendLine($" {boolValue}"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(IsInternetEndpointsPublished), out propertyOverride); + if (Optional.IsDefined(IsInternetEndpointsPublished) || hasPropertyOverride) + { + builder.Append(" publishInternetEndpoints:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var boolValue = IsInternetEndpointsPublished.Value == true ? "true" : "false"; + builder.AppendLine($" {boolValue}"); + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -130,6 +226,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOp { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(StorageRoutingPreference)} does not support '{options.Format}' format."); } @@ -146,6 +244,8 @@ StorageRoutingPreference IPersistableModel.Create(Bina using JsonDocument document = JsonDocument.Parse(data); return DeserializeStorageRoutingPreference(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(StorageRoutingPreference)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageServiceAccessPolicy.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageServiceAccessPolicy.Serialization.cs index b56c5be4b6573..2b16ad92928ae 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageServiceAccessPolicy.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageServiceAccessPolicy.Serialization.cs @@ -8,8 +8,10 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -118,6 +120,108 @@ internal static StorageServiceAccessPolicy DeserializeStorageServiceAccessPolicy return new StorageServiceAccessPolicy(Optional.ToNullable(startTime), Optional.ToNullable(expiryTime), permission.Value, serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(StartOn), out propertyOverride); + if (Optional.IsDefined(StartOn) || hasPropertyOverride) + { + builder.Append(" startTime:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var formattedDateTimeString = TypeFormatters.ToString(StartOn.Value, "o"); + builder.AppendLine($" '{formattedDateTimeString}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ExpireOn), out propertyOverride); + if (Optional.IsDefined(ExpireOn) || hasPropertyOverride) + { + builder.Append(" expiryTime:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var formattedDateTimeString = TypeFormatters.ToString(ExpireOn.Value, "o"); + builder.AppendLine($" '{formattedDateTimeString}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Permission), out propertyOverride); + if (Optional.IsDefined(Permission) || hasPropertyOverride) + { + builder.Append(" permission:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (Permission.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{Permission}'''"); + } + else + { + builder.AppendLine($" '{Permission}'"); + } + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -126,6 +230,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriter { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(StorageServiceAccessPolicy)} does not support '{options.Format}' format."); } @@ -142,6 +248,8 @@ StorageServiceAccessPolicy IPersistableModel.Create( using JsonDocument document = JsonDocument.Parse(data); return DeserializeStorageServiceAccessPolicy(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(StorageServiceAccessPolicy)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageSignedIdentifier.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageSignedIdentifier.Serialization.cs index a0d1d0f48cf28..cc3e85e3c797d 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageSignedIdentifier.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageSignedIdentifier.Serialization.cs @@ -8,8 +8,10 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -103,6 +105,92 @@ internal static StorageSignedIdentifier DeserializeStorageSignedIdentifier(JsonE return new StorageSignedIdentifier(id.Value, accessPolicy.Value, serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Id), out propertyOverride); + if (Optional.IsDefined(Id) || hasPropertyOverride) + { + builder.Append(" id:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (Id.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{Id}'''"); + } + else + { + builder.AppendLine($" '{Id}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(AccessPolicy), out propertyOverride); + if (Optional.IsDefined(AccessPolicy) || hasPropertyOverride) + { + builder.Append(" accessPolicy:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, AccessPolicy, options, 2, false); + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -111,6 +199,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOpt { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(StorageSignedIdentifier)} does not support '{options.Format}' format."); } @@ -127,6 +217,8 @@ StorageSignedIdentifier IPersistableModel.Create(Binary using JsonDocument document = JsonDocument.Parse(data); return DeserializeStorageSignedIdentifier(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(StorageSignedIdentifier)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageSku.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageSku.Serialization.cs index 6292f1bc3f559..da8239f737330 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageSku.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageSku.Serialization.cs @@ -8,8 +8,10 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -100,6 +102,84 @@ internal static StorageSku DeserializeStorageSku(JsonElement element, ModelReade return new StorageSku(name, Optional.ToNullable(tier), serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Name), out propertyOverride); + if (Optional.IsDefined(Name) || hasPropertyOverride) + { + builder.Append(" name:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{Name.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Tier), out propertyOverride); + if (Optional.IsDefined(Tier) || hasPropertyOverride) + { + builder.Append(" tier:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{Tier.Value.ToSerialString()}'"); + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -108,6 +188,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(StorageSku)} does not support '{options.Format}' format."); } @@ -124,6 +206,8 @@ StorageSku IPersistableModel.Create(BinaryData data, ModelReaderWrit using JsonDocument document = JsonDocument.Parse(data); return DeserializeStorageSku(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(StorageSku)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageSkuCapability.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageSkuCapability.Serialization.cs index 4a1b89a5a9d9d..06740d7f102db 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageSkuCapability.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageSkuCapability.Serialization.cs @@ -8,8 +8,10 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -99,6 +101,100 @@ internal static StorageSkuCapability DeserializeStorageSkuCapability(JsonElement return new StorageSkuCapability(name.Value, value.Value, serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Name), out propertyOverride); + if (Optional.IsDefined(Name) || hasPropertyOverride) + { + builder.Append(" name:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (Name.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{Name}'''"); + } + else + { + builder.AppendLine($" '{Name}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Value), out propertyOverride); + if (Optional.IsDefined(Value) || hasPropertyOverride) + { + builder.Append(" value:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (Value.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{Value}'''"); + } + else + { + builder.AppendLine($" '{Value}'"); + } + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -107,6 +203,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOption { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(StorageSkuCapability)} does not support '{options.Format}' format."); } @@ -123,6 +221,8 @@ StorageSkuCapability IPersistableModel.Create(BinaryData d using JsonDocument document = JsonDocument.Parse(data); return DeserializeStorageSkuCapability(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(StorageSkuCapability)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageSkuInformation.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageSkuInformation.Serialization.cs index 733e8f59dfdd2..68cf7688e45f4 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageSkuInformation.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageSkuInformation.Serialization.cs @@ -8,8 +8,11 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Linq; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -201,6 +204,199 @@ internal static StorageSkuInformation DeserializeStorageSkuInformation(JsonEleme return new StorageSkuInformation(name, Optional.ToNullable(tier), resourceType.Value, Optional.ToNullable(kind), Optional.ToList(locations), Optional.ToList(capabilities), Optional.ToList(restrictions), serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Name), out propertyOverride); + if (Optional.IsDefined(Name) || hasPropertyOverride) + { + builder.Append(" name:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{Name.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Tier), out propertyOverride); + if (Optional.IsDefined(Tier) || hasPropertyOverride) + { + builder.Append(" tier:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{Tier.Value.ToSerialString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ResourceType), out propertyOverride); + if (Optional.IsDefined(ResourceType) || hasPropertyOverride) + { + builder.Append(" resourceType:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (ResourceType.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{ResourceType}'''"); + } + else + { + builder.AppendLine($" '{ResourceType}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Kind), out propertyOverride); + if (Optional.IsDefined(Kind) || hasPropertyOverride) + { + builder.Append(" kind:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{Kind.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Locations), out propertyOverride); + if (Optional.IsCollectionDefined(Locations) || hasPropertyOverride) + { + if (Locations.Any() || hasPropertyOverride) + { + builder.Append(" locations:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine(" ["); + foreach (var item in Locations) + { + if (item == null) + { + builder.Append("null"); + continue; + } + if (item.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{item}'''"); + } + else + { + builder.AppendLine($" '{item}'"); + } + } + builder.AppendLine(" ]"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Capabilities), out propertyOverride); + if (Optional.IsCollectionDefined(Capabilities) || hasPropertyOverride) + { + if (Capabilities.Any() || hasPropertyOverride) + { + builder.Append(" capabilities:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine(" ["); + foreach (var item in Capabilities) + { + AppendChildObject(builder, item, options, 4, true); + } + builder.AppendLine(" ]"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Restrictions), out propertyOverride); + if (Optional.IsCollectionDefined(Restrictions) || hasPropertyOverride) + { + if (Restrictions.Any() || hasPropertyOverride) + { + builder.Append(" restrictions:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine(" ["); + foreach (var item in Restrictions) + { + AppendChildObject(builder, item, options, 4, true); + } + builder.AppendLine(" ]"); + } + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -209,6 +405,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOptio { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(StorageSkuInformation)} does not support '{options.Format}' format."); } @@ -225,6 +423,8 @@ StorageSkuInformation IPersistableModel.Create(BinaryData using JsonDocument document = JsonDocument.Parse(data); return DeserializeStorageSkuInformation(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(StorageSkuInformation)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageSkuListResult.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageSkuListResult.Serialization.cs index b5530b2e96f42..3a46cccc4fc74 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageSkuListResult.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageSkuListResult.Serialization.cs @@ -8,8 +8,11 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Linq; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -102,6 +105,78 @@ internal static StorageSkuListResult DeserializeStorageSkuListResult(JsonElement return new StorageSkuListResult(Optional.ToList(value), serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Value), out propertyOverride); + if (Optional.IsCollectionDefined(Value) || hasPropertyOverride) + { + if (Value.Any() || hasPropertyOverride) + { + builder.Append(" value:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine(" ["); + foreach (var item in Value) + { + AppendChildObject(builder, item, options, 4, true); + } + builder.AppendLine(" ]"); + } + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -110,6 +185,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOption { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(StorageSkuListResult)} does not support '{options.Format}' format."); } @@ -126,6 +203,8 @@ StorageSkuListResult IPersistableModel.Create(BinaryData d using JsonDocument document = JsonDocument.Parse(data); return DeserializeStorageSkuListResult(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(StorageSkuListResult)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageSkuRestriction.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageSkuRestriction.Serialization.cs index e16ccede6002a..8119ff76bdd3d 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageSkuRestriction.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageSkuRestriction.Serialization.cs @@ -8,8 +8,11 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Linq; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -128,6 +131,105 @@ internal static StorageSkuRestriction DeserializeStorageSkuRestriction(JsonEleme return new StorageSkuRestriction(type.Value, Optional.ToList(values), Optional.ToNullable(reasonCode), serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Values), out propertyOverride); + if (Optional.IsCollectionDefined(Values) || hasPropertyOverride) + { + if (Values.Any() || hasPropertyOverride) + { + builder.Append(" values:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine(" ["); + foreach (var item in Values) + { + if (item == null) + { + builder.Append("null"); + continue; + } + if (item.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{item}'''"); + } + else + { + builder.AppendLine($" '{item}'"); + } + } + builder.AppendLine(" ]"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ReasonCode), out propertyOverride); + if (Optional.IsDefined(ReasonCode) || hasPropertyOverride) + { + builder.Append(" reasonCode:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{ReasonCode.Value.ToString()}'"); + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -136,6 +238,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOptio { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(StorageSkuRestriction)} does not support '{options.Format}' format."); } @@ -152,6 +256,8 @@ StorageSkuRestriction IPersistableModel.Create(BinaryData using JsonDocument document = JsonDocument.Parse(data); return DeserializeStorageSkuRestriction(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(StorageSkuRestriction)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageSshPublicKey.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageSshPublicKey.Serialization.cs index 444feb7dacd6b..8d23aac1a6505 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageSshPublicKey.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageSshPublicKey.Serialization.cs @@ -8,8 +8,10 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -99,6 +101,100 @@ internal static StorageSshPublicKey DeserializeStorageSshPublicKey(JsonElement e return new StorageSshPublicKey(description.Value, key.Value, serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Description), out propertyOverride); + if (Optional.IsDefined(Description) || hasPropertyOverride) + { + builder.Append(" description:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (Description.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{Description}'''"); + } + else + { + builder.AppendLine($" '{Description}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Key), out propertyOverride); + if (Optional.IsDefined(Key) || hasPropertyOverride) + { + builder.Append(" key:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (Key.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{Key}'''"); + } + else + { + builder.AppendLine($" '{Key}'"); + } + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -107,6 +203,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOptions { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(StorageSshPublicKey)} does not support '{options.Format}' format."); } @@ -123,6 +221,8 @@ StorageSshPublicKey IPersistableModel.Create(BinaryData dat using JsonDocument document = JsonDocument.Parse(data); return DeserializeStorageSshPublicKey(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(StorageSshPublicKey)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageTableAccessPolicy.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageTableAccessPolicy.Serialization.cs index cc441155b792d..e3f21f320f42e 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageTableAccessPolicy.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageTableAccessPolicy.Serialization.cs @@ -8,8 +8,10 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -115,6 +117,108 @@ internal static StorageTableAccessPolicy DeserializeStorageTableAccessPolicy(Jso return new StorageTableAccessPolicy(Optional.ToNullable(startTime), Optional.ToNullable(expiryTime), permission, serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(StartOn), out propertyOverride); + if (Optional.IsDefined(StartOn) || hasPropertyOverride) + { + builder.Append(" startTime:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var formattedDateTimeString = TypeFormatters.ToString(StartOn.Value, "o"); + builder.AppendLine($" '{formattedDateTimeString}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ExpireOn), out propertyOverride); + if (Optional.IsDefined(ExpireOn) || hasPropertyOverride) + { + builder.Append(" expiryTime:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var formattedDateTimeString = TypeFormatters.ToString(ExpireOn.Value, "o"); + builder.AppendLine($" '{formattedDateTimeString}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Permission), out propertyOverride); + if (Optional.IsDefined(Permission) || hasPropertyOverride) + { + builder.Append(" permission:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (Permission.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{Permission}'''"); + } + else + { + builder.AppendLine($" '{Permission}'"); + } + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -123,6 +227,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOp { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(StorageTableAccessPolicy)} does not support '{options.Format}' format."); } @@ -139,6 +245,8 @@ StorageTableAccessPolicy IPersistableModel.Create(Bina using JsonDocument document = JsonDocument.Parse(data); return DeserializeStorageTableAccessPolicy(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(StorageTableAccessPolicy)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageTableSignedIdentifier.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageTableSignedIdentifier.Serialization.cs index d0cab0ddbf5d9..64171e5918b2a 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageTableSignedIdentifier.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageTableSignedIdentifier.Serialization.cs @@ -8,8 +8,10 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -100,6 +102,92 @@ internal static StorageTableSignedIdentifier DeserializeStorageTableSignedIdenti return new StorageTableSignedIdentifier(id, accessPolicy.Value, serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Id), out propertyOverride); + if (Optional.IsDefined(Id) || hasPropertyOverride) + { + builder.Append(" id:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (Id.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{Id}'''"); + } + else + { + builder.AppendLine($" '{Id}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(AccessPolicy), out propertyOverride); + if (Optional.IsDefined(AccessPolicy) || hasPropertyOverride) + { + builder.Append(" accessPolicy:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, AccessPolicy, options, 2, false); + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -108,6 +196,8 @@ BinaryData IPersistableModel.Write(ModelReaderWrit { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(StorageTableSignedIdentifier)} does not support '{options.Format}' format."); } @@ -124,6 +214,8 @@ StorageTableSignedIdentifier IPersistableModel.Cre using JsonDocument document = JsonDocument.Parse(data); return DeserializeStorageTableSignedIdentifier(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(StorageTableSignedIdentifier)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageUsage.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageUsage.Serialization.cs index 0d325d112bf4b..5d56ec483ada9 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageUsage.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageUsage.Serialization.cs @@ -8,8 +8,10 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -137,6 +139,112 @@ internal static StorageUsage DeserializeStorageUsage(JsonElement element, ModelR return new StorageUsage(Optional.ToNullable(unit), Optional.ToNullable(currentValue), Optional.ToNullable(limit), name.Value, serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Name), out propertyOverride); + if (Optional.IsDefined(Name) || hasPropertyOverride) + { + builder.Append(" name:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, Name, options, 2, false); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Unit), out propertyOverride); + if (Optional.IsDefined(Unit) || hasPropertyOverride) + { + builder.Append(" unit:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{Unit.Value.ToSerialString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(CurrentValue), out propertyOverride); + if (Optional.IsDefined(CurrentValue) || hasPropertyOverride) + { + builder.Append(" currentValue:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" {CurrentValue.Value}"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Limit), out propertyOverride); + if (Optional.IsDefined(Limit) || hasPropertyOverride) + { + builder.Append(" limit:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" {Limit.Value}"); + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -145,6 +253,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOptions option { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(StorageUsage)} does not support '{options.Format}' format."); } @@ -161,6 +271,8 @@ StorageUsage IPersistableModel.Create(BinaryData data, ModelReader using JsonDocument document = JsonDocument.Parse(data); return DeserializeStorageUsage(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(StorageUsage)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageUsageName.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageUsageName.Serialization.cs index ca4ace54ab02e..0a839bfcf53c4 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageUsageName.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/StorageUsageName.Serialization.cs @@ -8,8 +8,10 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -99,6 +101,100 @@ internal static StorageUsageName DeserializeStorageUsageName(JsonElement element return new StorageUsageName(value.Value, localizedValue.Value, serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Value), out propertyOverride); + if (Optional.IsDefined(Value) || hasPropertyOverride) + { + builder.Append(" value:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (Value.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{Value}'''"); + } + else + { + builder.AppendLine($" '{Value}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(LocalizedValue), out propertyOverride); + if (Optional.IsDefined(LocalizedValue) || hasPropertyOverride) + { + builder.Append(" localizedValue:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (LocalizedValue.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{LocalizedValue}'''"); + } + else + { + builder.AppendLine($" '{LocalizedValue}'"); + } + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -107,6 +203,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOptions op { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(StorageUsageName)} does not support '{options.Format}' format."); } @@ -123,6 +221,8 @@ StorageUsageName IPersistableModel.Create(BinaryData data, Mod using JsonDocument document = JsonDocument.Parse(data); return DeserializeStorageUsageName(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(StorageUsageName)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/TableData.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/TableData.Serialization.cs index 741aeb222dab5..eae39fa47257d 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/TableData.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/TableData.Serialization.cs @@ -8,8 +8,11 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Linq; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; using Azure.ResourceManager.Models; using Azure.ResourceManager.Storage.Models; @@ -178,6 +181,153 @@ internal static TableData DeserializeTableData(JsonElement element, ModelReaderW return new TableData(id, name, type, systemData.Value, tableName.Value, Optional.ToList(signedIdentifiers), serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Name), out propertyOverride); + if (Optional.IsDefined(Name) || hasPropertyOverride) + { + builder.Append(" name:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (Name.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{Name}'''"); + } + else + { + builder.AppendLine($" '{Name}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Id), out propertyOverride); + if (Optional.IsDefined(Id) || hasPropertyOverride) + { + builder.Append(" id:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{Id.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(SystemData), out propertyOverride); + if (Optional.IsDefined(SystemData) || hasPropertyOverride) + { + builder.Append(" systemData:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{SystemData.ToString()}'"); + } + } + + builder.Append(" properties:"); + builder.AppendLine(" {"); + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(TableName), out propertyOverride); + if (Optional.IsDefined(TableName) || hasPropertyOverride) + { + builder.Append(" tableName:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (TableName.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{TableName}'''"); + } + else + { + builder.AppendLine($" '{TableName}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(SignedIdentifiers), out propertyOverride); + if (Optional.IsCollectionDefined(SignedIdentifiers) || hasPropertyOverride) + { + if (SignedIdentifiers.Any() || hasPropertyOverride) + { + builder.Append(" signedIdentifiers:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine(" ["); + foreach (var item in SignedIdentifiers) + { + AppendChildObject(builder, item, options, 6, true); + } + builder.AppendLine(" ]"); + } + } + } + + builder.AppendLine(" }"); + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -186,6 +336,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(TableData)} does not support '{options.Format}' format."); } @@ -202,6 +354,8 @@ TableData IPersistableModel.Create(BinaryData data, ModelReaderWriter using JsonDocument document = JsonDocument.Parse(data); return DeserializeTableData(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(TableData)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/TableServiceData.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/TableServiceData.Serialization.cs index 4dc93230ff46a..d687c64c6c914 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/TableServiceData.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/TableServiceData.Serialization.cs @@ -8,8 +8,10 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; using Azure.ResourceManager.Models; using Azure.ResourceManager.Storage.Models; @@ -157,6 +159,123 @@ internal static TableServiceData DeserializeTableServiceData(JsonElement element return new TableServiceData(id, name, type, systemData.Value, cors.Value, serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Name), out propertyOverride); + if (Optional.IsDefined(Name) || hasPropertyOverride) + { + builder.Append(" name:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (Name.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{Name}'''"); + } + else + { + builder.AppendLine($" '{Name}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Id), out propertyOverride); + if (Optional.IsDefined(Id) || hasPropertyOverride) + { + builder.Append(" id:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{Id.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(SystemData), out propertyOverride); + if (Optional.IsDefined(SystemData) || hasPropertyOverride) + { + builder.Append(" systemData:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{SystemData.ToString()}'"); + } + } + + builder.Append(" properties:"); + builder.AppendLine(" {"); + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Cors), out propertyOverride); + if (Optional.IsDefined(Cors) || hasPropertyOverride) + { + builder.Append(" cors:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + AppendChildObject(builder, Cors, options, 4, false); + } + } + + builder.AppendLine(" }"); + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -165,6 +284,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOptions op { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(TableServiceData)} does not support '{options.Format}' format."); } @@ -181,6 +302,8 @@ TableServiceData IPersistableModel.Create(BinaryData data, Mod using JsonDocument document = JsonDocument.Parse(data); return DeserializeTableServiceData(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(TableServiceData)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/UpdateHistoryEntry.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/UpdateHistoryEntry.Serialization.cs index 36e02ea07c710..be64571bde3f5 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/UpdateHistoryEntry.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/UpdateHistoryEntry.Serialization.cs @@ -8,8 +8,10 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -189,6 +191,187 @@ internal static UpdateHistoryEntry DeserializeUpdateHistoryEntry(JsonElement ele return new UpdateHistoryEntry(Optional.ToNullable(update), Optional.ToNullable(immutabilityPeriodSinceCreationInDays), Optional.ToNullable(timestamp), objectIdentifier.Value, Optional.ToNullable(tenantId), upn.Value, Optional.ToNullable(allowProtectedAppendWrites), Optional.ToNullable(allowProtectedAppendWritesAll), serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(UpdateType), out propertyOverride); + if (Optional.IsDefined(UpdateType) || hasPropertyOverride) + { + builder.Append(" update:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{UpdateType.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ImmutabilityPeriodSinceCreationInDays), out propertyOverride); + if (Optional.IsDefined(ImmutabilityPeriodSinceCreationInDays) || hasPropertyOverride) + { + builder.Append(" immutabilityPeriodSinceCreationInDays:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" {ImmutabilityPeriodSinceCreationInDays.Value}"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Timestamp), out propertyOverride); + if (Optional.IsDefined(Timestamp) || hasPropertyOverride) + { + builder.Append(" timestamp:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var formattedDateTimeString = TypeFormatters.ToString(Timestamp.Value, "o"); + builder.AppendLine($" '{formattedDateTimeString}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ObjectIdentifier), out propertyOverride); + if (Optional.IsDefined(ObjectIdentifier) || hasPropertyOverride) + { + builder.Append(" objectIdentifier:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (ObjectIdentifier.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{ObjectIdentifier}'''"); + } + else + { + builder.AppendLine($" '{ObjectIdentifier}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(TenantId), out propertyOverride); + if (Optional.IsDefined(TenantId) || hasPropertyOverride) + { + builder.Append(" tenantId:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine($" '{TenantId.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Upn), out propertyOverride); + if (Optional.IsDefined(Upn) || hasPropertyOverride) + { + builder.Append(" upn:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + if (Upn.Contains(Environment.NewLine)) + { + builder.AppendLine(" '''"); + builder.AppendLine($"{Upn}'''"); + } + else + { + builder.AppendLine($" '{Upn}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(AllowProtectedAppendWrites), out propertyOverride); + if (Optional.IsDefined(AllowProtectedAppendWrites) || hasPropertyOverride) + { + builder.Append(" allowProtectedAppendWrites:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var boolValue = AllowProtectedAppendWrites.Value == true ? "true" : "false"; + builder.AppendLine($" {boolValue}"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(AllowProtectedAppendWritesAll), out propertyOverride); + if (Optional.IsDefined(AllowProtectedAppendWritesAll) || hasPropertyOverride) + { + builder.Append(" allowProtectedAppendWritesAll:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + var boolValue = AllowProtectedAppendWritesAll.Value == true ? "true" : "false"; + builder.AppendLine($" {boolValue}"); + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -197,6 +380,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOptions { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(UpdateHistoryEntry)} does not support '{options.Format}' format."); } @@ -213,6 +398,8 @@ UpdateHistoryEntry IPersistableModel.Create(BinaryData data, using JsonDocument document = JsonDocument.Parse(data); return DeserializeUpdateHistoryEntry(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(UpdateHistoryEntry)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/UsageListResult.Serialization.cs b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/UsageListResult.Serialization.cs index 67e58a07911c9..ff609ff6ce8e4 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/UsageListResult.Serialization.cs +++ b/sdk/storage/Azure.ResourceManager.Storage/src/Generated/Models/UsageListResult.Serialization.cs @@ -8,8 +8,11 @@ using System; using System.ClientModel.Primitives; using System.Collections.Generic; +using System.Linq; +using System.Text; using System.Text.Json; using Azure.Core; +using Azure.ResourceManager; namespace Azure.ResourceManager.Storage.Models { @@ -102,6 +105,78 @@ internal static UsageListResult DeserializeUsageListResult(JsonElement element, return new UsageListResult(Optional.ToList(value), serializedAdditionalRawData); } + private BinaryData SerializeBicep(ModelReaderWriterOptions options) + { + StringBuilder builder = new StringBuilder(); + BicepModelReaderWriterOptions bicepOptions = options as BicepModelReaderWriterOptions; + IDictionary propertyOverrides = null; + bool hasObjectOverride = bicepOptions != null && bicepOptions.ParameterOverrides.TryGetValue(this, out propertyOverrides); + bool hasPropertyOverride = false; + string propertyOverride = null; + + builder.AppendLine("{"); + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Value), out propertyOverride); + if (Optional.IsCollectionDefined(Value) || hasPropertyOverride) + { + if (Value.Any() || hasPropertyOverride) + { + builder.Append(" value:"); + if (hasPropertyOverride) + { + builder.AppendLine($" {propertyOverride}"); + } + else + { + builder.AppendLine(" ["); + foreach (var item in Value) + { + AppendChildObject(builder, item, options, 4, true); + } + builder.AppendLine(" ]"); + } + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine) + { + string indent = new string(' ', spaces); + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + bool inMultilineString = false; + for (int i = 0; i < lines.Length; i++) + { + string line = lines[i]; + if (inMultilineString) + { + if (line.Contains("'''")) + { + inMultilineString = false; + } + stringBuilder.AppendLine(line); + continue; + } + if (line.Contains("'''")) + { + inMultilineString = true; + stringBuilder.AppendLine($"{indent}{line}"); + continue; + } + if (i == 0 && !indentFirstLine) + { + stringBuilder.AppendLine($" {line}"); + } + else + { + stringBuilder.AppendLine($"{indent}{line}"); + } + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -110,6 +185,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOptions opt { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(UsageListResult)} does not support '{options.Format}' format."); } @@ -126,6 +203,8 @@ UsageListResult IPersistableModel.Create(BinaryData data, Model using JsonDocument document = JsonDocument.Parse(data); return DeserializeUsageListResult(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(UsageListResult)} does not support '{options.Format}' format."); } diff --git a/sdk/storage/Azure.ResourceManager.Storage/src/autorest.md b/sdk/storage/Azure.ResourceManager.Storage/src/autorest.md index 84ca2760cc3e4..13b2a9df89b93 100644 --- a/sdk/storage/Azure.ResourceManager.Storage/src/autorest.md +++ b/sdk/storage/Azure.ResourceManager.Storage/src/autorest.md @@ -17,6 +17,7 @@ skip-csproj: true modelerfour: flatten-payloads: false use-model-reader-writer: true +enable-bicep-serialization: true list-exception: - /subscriptions/{subscriptionId}/providers/Microsoft.Storage/locations/{location}/deletedAccounts/{deletedAccountName}