diff --git a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/AuthorizationProviderOperationsMetadataData.Serialization.cs b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/AuthorizationProviderOperationsMetadataData.Serialization.cs index bc9b425c2d5cc..297d1e7709703 100644 --- a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/AuthorizationProviderOperationsMetadataData.Serialization.cs +++ b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/AuthorizationProviderOperationsMetadataData.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.Authorization.Models; using Azure.ResourceManager.Models; @@ -136,7 +139,7 @@ internal static AuthorizationProviderOperationsMetadataData DeserializeAuthoriza List array = new List(); foreach (var item in property.Value.EnumerateArray()) { - array.Add(AuthorizationProviderResourceType.DeserializeAuthorizationProviderResourceType(item, options)); + array.Add(AuthorizationProviderResourceType.DeserializeAuthorizationProviderResourceType(item)); } resourceTypes = array; continue; @@ -150,7 +153,7 @@ internal static AuthorizationProviderOperationsMetadataData DeserializeAuthoriza List array = new List(); foreach (var item in property.Value.EnumerateArray()) { - array.Add(AuthorizationProviderOperationInfo.DeserializeAuthorizationProviderOperationInfo(item, options)); + array.Add(AuthorizationProviderOperationInfo.DeserializeAuthorizationProviderOperationInfo(item)); } operations = array; continue; @@ -188,6 +191,179 @@ internal static AuthorizationProviderOperationsMetadataData DeserializeAuthoriza return new AuthorizationProviderOperationsMetadataData(id, name, type, systemData.Value, displayName.Value, Optional.ToList(resourceTypes), Optional.ToList(operations), 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(DisplayName), out propertyOverride); + if (Optional.IsDefined(DisplayName) || hasPropertyOverride) + { + builder.Append(" displayName: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + if (DisplayName.Contains(Environment.NewLine)) + { + builder.AppendLine("'''"); + builder.AppendLine($"{DisplayName}'''"); + } + else + { + builder.AppendLine($"'{DisplayName}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ResourceTypes), out propertyOverride); + if (Optional.IsCollectionDefined(ResourceTypes) || hasPropertyOverride) + { + if (ResourceTypes.Any() || hasPropertyOverride) + { + builder.Append(" resourceTypes: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine("["); + foreach (var item in ResourceTypes) + { + AppendChildObject(builder, item, options, 4, true, " resourceTypes: "); + } + builder.AppendLine(" ]"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Operations), out propertyOverride); + if (Optional.IsCollectionDefined(Operations) || hasPropertyOverride) + { + if (Operations.Any() || hasPropertyOverride) + { + builder.Append(" operations: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine("["); + foreach (var item in Operations) + { + AppendChildObject(builder, item, options, 4, true, " operations: "); + } + builder.AppendLine(" ]"); + } + } + } + + 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.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine, string formattedPropertyName) + { + string indent = new string(' ', spaces); + int emptyObjectLength = 2 + spaces + Environment.NewLine.Length + Environment.NewLine.Length; + int length = stringBuilder.Length; + bool inMultilineString = false; + + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + 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}"); + } + } + if (stringBuilder.Length == length + emptyObjectLength) + { + stringBuilder.Length = stringBuilder.Length - emptyObjectLength - formattedPropertyName.Length; + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -196,6 +372,8 @@ BinaryData IPersistableModel.Write( { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(AuthorizationProviderOperationsMetadataData)} does not support '{options.Format}' format."); } @@ -212,6 +390,8 @@ AuthorizationProviderOperationsMetadataData IPersistableModel The provider display name. + [WirePath("displayName")] public string DisplayName { get; } /// The provider resource types. + [WirePath("resourceTypes")] public IReadOnlyList ResourceTypes { get; } /// The provider operations. + [WirePath("operations")] public IReadOnlyList Operations { get; } } } diff --git a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/AuthorizationRoleDefinitionData.Serialization.cs b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/AuthorizationRoleDefinitionData.Serialization.cs index effcc6a9b1153..812d5929d62dd 100644 --- a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/AuthorizationRoleDefinitionData.Serialization.cs +++ b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/AuthorizationRoleDefinitionData.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.Authorization.Models; using Azure.ResourceManager.Models; @@ -198,7 +201,7 @@ internal static AuthorizationRoleDefinitionData DeserializeAuthorizationRoleDefi List array = new List(); foreach (var item in property0.Value.EnumerateArray()) { - array.Add(RoleDefinitionPermission.DeserializeRoleDefinitionPermission(item, options)); + array.Add(RoleDefinitionPermission.DeserializeRoleDefinitionPermission(item)); } permissions = array; continue; @@ -229,6 +232,231 @@ internal static AuthorizationRoleDefinitionData DeserializeAuthorizationRoleDefi return new AuthorizationRoleDefinitionData(id, name, type, systemData.Value, roleName.Value, description.Value, Optional.ToNullable(type0), Optional.ToList(permissions), Optional.ToList(assignableScopes), 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(RoleName), out propertyOverride); + if (Optional.IsDefined(RoleName) || hasPropertyOverride) + { + builder.Append(" roleName: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + if (RoleName.Contains(Environment.NewLine)) + { + builder.AppendLine("'''"); + builder.AppendLine($"{RoleName}'''"); + } + else + { + builder.AppendLine($"'{RoleName}'"); + } + } + } + + 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(RoleType), out propertyOverride); + if (Optional.IsDefined(RoleType) || hasPropertyOverride) + { + builder.Append(" type: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{RoleType.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Permissions), out propertyOverride); + if (Optional.IsCollectionDefined(Permissions) || hasPropertyOverride) + { + if (Permissions.Any() || hasPropertyOverride) + { + builder.Append(" permissions: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine("["); + foreach (var item in Permissions) + { + AppendChildObject(builder, item, options, 6, true, " permissions: "); + } + builder.AppendLine(" ]"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(AssignableScopes), out propertyOverride); + if (Optional.IsCollectionDefined(AssignableScopes) || hasPropertyOverride) + { + if (AssignableScopes.Any() || hasPropertyOverride) + { + builder.Append(" assignableScopes: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine("["); + foreach (var item in AssignableScopes) + { + 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 formattedPropertyName) + { + string indent = new string(' ', spaces); + int emptyObjectLength = 2 + spaces + Environment.NewLine.Length + Environment.NewLine.Length; + int length = stringBuilder.Length; + bool inMultilineString = false; + + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + 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}"); + } + } + if (stringBuilder.Length == length + emptyObjectLength) + { + stringBuilder.Length = stringBuilder.Length - emptyObjectLength - formattedPropertyName.Length; + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -237,6 +465,8 @@ BinaryData IPersistableModel.Write(ModelReaderW { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(AuthorizationRoleDefinitionData)} does not support '{options.Format}' format."); } @@ -253,6 +483,8 @@ AuthorizationRoleDefinitionData IPersistableModel The role name. + [WirePath("properties.roleName")] public string RoleName { get; set; } /// The role definition description. + [WirePath("properties.description")] public string Description { get; set; } /// The role type. + [WirePath("properties.type")] public AuthorizationRoleType? RoleType { get; set; } /// Role definition permissions. + [WirePath("properties.permissions")] public IList Permissions { get; } /// Role definition assignable scopes. + [WirePath("properties.assignableScopes")] public IList AssignableScopes { get; } } } diff --git a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/DenyAssignmentData.Serialization.cs b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/DenyAssignmentData.Serialization.cs index 8d1f96d90234a..b003263489e0a 100644 --- a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/DenyAssignmentData.Serialization.cs +++ b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/DenyAssignmentData.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.Authorization.Models; using Azure.ResourceManager.Models; @@ -212,7 +215,7 @@ internal static DenyAssignmentData DeserializeDenyAssignmentData(JsonElement ele List array = new List(); foreach (var item in property0.Value.EnumerateArray()) { - array.Add(DenyAssignmentPermission.DeserializeDenyAssignmentPermission(item, options)); + array.Add(DenyAssignmentPermission.DeserializeDenyAssignmentPermission(item)); } permissions = array; continue; @@ -240,7 +243,7 @@ internal static DenyAssignmentData DeserializeDenyAssignmentData(JsonElement ele List array = new List(); foreach (var item in property0.Value.EnumerateArray()) { - array.Add(RoleManagementPrincipal.DeserializeRoleManagementPrincipal(item, options)); + array.Add(RoleManagementPrincipal.DeserializeRoleManagementPrincipal(item)); } principals = array; continue; @@ -254,7 +257,7 @@ internal static DenyAssignmentData DeserializeDenyAssignmentData(JsonElement ele List array = new List(); foreach (var item in property0.Value.EnumerateArray()) { - array.Add(RoleManagementPrincipal.DeserializeRoleManagementPrincipal(item, options)); + array.Add(RoleManagementPrincipal.DeserializeRoleManagementPrincipal(item)); } excludePrincipals = array; continue; @@ -280,6 +283,278 @@ internal static DenyAssignmentData DeserializeDenyAssignmentData(JsonElement ele return new DenyAssignmentData(id, name, type, systemData.Value, denyAssignmentName.Value, description.Value, Optional.ToList(permissions), scope.Value, Optional.ToNullable(doNotApplyToChildScopes), Optional.ToList(principals), Optional.ToList(excludePrincipals), Optional.ToNullable(isSystemProtected), 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(DenyAssignmentName), out propertyOverride); + if (Optional.IsDefined(DenyAssignmentName) || hasPropertyOverride) + { + builder.Append(" denyAssignmentName: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + if (DenyAssignmentName.Contains(Environment.NewLine)) + { + builder.AppendLine("'''"); + builder.AppendLine($"{DenyAssignmentName}'''"); + } + else + { + builder.AppendLine($"'{DenyAssignmentName}'"); + } + } + } + + 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(Permissions), out propertyOverride); + if (Optional.IsCollectionDefined(Permissions) || hasPropertyOverride) + { + if (Permissions.Any() || hasPropertyOverride) + { + builder.Append(" permissions: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine("["); + foreach (var item in Permissions) + { + AppendChildObject(builder, item, options, 6, true, " permissions: "); + } + builder.AppendLine(" ]"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Scope), out propertyOverride); + if (Optional.IsDefined(Scope) || hasPropertyOverride) + { + builder.Append(" scope: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + if (Scope.Contains(Environment.NewLine)) + { + builder.AppendLine("'''"); + builder.AppendLine($"{Scope}'''"); + } + else + { + builder.AppendLine($"'{Scope}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(IsAppliedToChildScopes), out propertyOverride); + if (Optional.IsDefined(IsAppliedToChildScopes) || hasPropertyOverride) + { + builder.Append(" doNotApplyToChildScopes: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + var boolValue = IsAppliedToChildScopes.Value == true ? "true" : "false"; + builder.AppendLine($"{boolValue}"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Principals), out propertyOverride); + if (Optional.IsCollectionDefined(Principals) || hasPropertyOverride) + { + if (Principals.Any() || hasPropertyOverride) + { + builder.Append(" principals: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine("["); + foreach (var item in Principals) + { + AppendChildObject(builder, item, options, 6, true, " principals: "); + } + builder.AppendLine(" ]"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ExcludePrincipals), out propertyOverride); + if (Optional.IsCollectionDefined(ExcludePrincipals) || hasPropertyOverride) + { + if (ExcludePrincipals.Any() || hasPropertyOverride) + { + builder.Append(" excludePrincipals: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine("["); + foreach (var item in ExcludePrincipals) + { + AppendChildObject(builder, item, options, 6, true, " excludePrincipals: "); + } + builder.AppendLine(" ]"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(IsSystemProtected), out propertyOverride); + if (Optional.IsDefined(IsSystemProtected) || hasPropertyOverride) + { + builder.Append(" isSystemProtected: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + var boolValue = IsSystemProtected.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 formattedPropertyName) + { + string indent = new string(' ', spaces); + int emptyObjectLength = 2 + spaces + Environment.NewLine.Length + Environment.NewLine.Length; + int length = stringBuilder.Length; + bool inMultilineString = false; + + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + 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}"); + } + } + if (stringBuilder.Length == length + emptyObjectLength) + { + stringBuilder.Length = stringBuilder.Length - emptyObjectLength - formattedPropertyName.Length; + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -288,6 +563,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOptions { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(DenyAssignmentData)} does not support '{options.Format}' format."); } @@ -304,6 +581,8 @@ DenyAssignmentData IPersistableModel.Create(BinaryData data, using JsonDocument document = JsonDocument.Parse(data); return DeserializeDenyAssignmentData(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(DenyAssignmentData)} does not support '{options.Format}' format."); } diff --git a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/DenyAssignmentData.cs b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/DenyAssignmentData.cs index faf3be26bf833..ca139f54c98b8 100644 --- a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/DenyAssignmentData.cs +++ b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/DenyAssignmentData.cs @@ -87,20 +87,28 @@ internal DenyAssignmentData(ResourceIdentifier id, string name, ResourceType res } /// The display name of the deny assignment. + [WirePath("properties.denyAssignmentName")] public string DenyAssignmentName { get; } /// The description of the deny assignment. + [WirePath("properties.description")] public string Description { get; } /// An array of permissions that are denied by the deny assignment. + [WirePath("properties.permissions")] public IReadOnlyList Permissions { get; } /// The deny assignment scope. + [WirePath("properties.scope")] public string Scope { get; } /// Determines if the deny assignment applies to child scopes. Default value is false. + [WirePath("properties.doNotApplyToChildScopes")] public bool? IsAppliedToChildScopes { get; } /// Array of principals to which the deny assignment applies. + [WirePath("properties.principals")] public IReadOnlyList Principals { get; } /// Array of principals to which the deny assignment does not apply. + [WirePath("properties.excludePrincipals")] public IReadOnlyList ExcludePrincipals { get; } /// Specifies whether this deny assignment was created by Azure and cannot be edited or deleted. + [WirePath("properties.isSystemProtected")] public bool? IsSystemProtected { get; } } } diff --git a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Internal/WirePathAttribute.cs b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Internal/WirePathAttribute.cs new file mode 100644 index 0000000000000..de664929d89b3 --- /dev/null +++ b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Internal/WirePathAttribute.cs @@ -0,0 +1,27 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; + +namespace Azure.ResourceManager.Authorization +{ + [AttributeUsage(AttributeTargets.Property)] + internal class WirePathAttribute : Attribute + { + private string _wirePath; + + public WirePathAttribute(string wirePath) + { + _wirePath = wirePath; + } + + public override string ToString() + { + return _wirePath; + } + } +} diff --git a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/AuthorizationClassicAdministrator.Serialization.cs b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/AuthorizationClassicAdministrator.Serialization.cs index 7409a45eb8b0e..570703f27c161 100644 --- a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/AuthorizationClassicAdministrator.Serialization.cs +++ b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/AuthorizationClassicAdministrator.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.Authorization.Models @@ -163,6 +165,160 @@ internal static AuthorizationClassicAdministrator DeserializeAuthorizationClassi return new AuthorizationClassicAdministrator(id, name, type, systemData.Value, emailAddress.Value, role.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(EmailAddress), out propertyOverride); + if (Optional.IsDefined(EmailAddress) || hasPropertyOverride) + { + builder.Append(" emailAddress: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + if (EmailAddress.Contains(Environment.NewLine)) + { + builder.AppendLine("'''"); + builder.AppendLine($"{EmailAddress}'''"); + } + else + { + builder.AppendLine($"'{EmailAddress}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Role), out propertyOverride); + if (Optional.IsDefined(Role) || hasPropertyOverride) + { + builder.Append(" role: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + if (Role.Contains(Environment.NewLine)) + { + builder.AppendLine("'''"); + builder.AppendLine($"{Role}'''"); + } + else + { + builder.AppendLine($"'{Role}'"); + } + } + } + + builder.AppendLine(" }"); + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine, string formattedPropertyName) + { + string indent = new string(' ', spaces); + int emptyObjectLength = 2 + spaces + Environment.NewLine.Length + Environment.NewLine.Length; + int length = stringBuilder.Length; + bool inMultilineString = false; + + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + 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}"); + } + } + if (stringBuilder.Length == length + emptyObjectLength) + { + stringBuilder.Length = stringBuilder.Length - emptyObjectLength - formattedPropertyName.Length; + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -171,6 +327,8 @@ BinaryData IPersistableModel.Write(ModelReade { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(AuthorizationClassicAdministrator)} does not support '{options.Format}' format."); } @@ -187,6 +345,8 @@ AuthorizationClassicAdministrator IPersistableModel The email address of the administrator. + [WirePath("properties.emailAddress")] public string EmailAddress { get; } /// The role of the administrator. + [WirePath("properties.role")] public string Role { get; } } } diff --git a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/AuthorizationClassicAdministratorListResult.Serialization.cs b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/AuthorizationClassicAdministratorListResult.Serialization.cs index aecbf5e6425fd..8be7b18aeeb65 100644 --- a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/AuthorizationClassicAdministratorListResult.Serialization.cs +++ b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/AuthorizationClassicAdministratorListResult.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.Authorization.Models { @@ -94,7 +97,7 @@ internal static AuthorizationClassicAdministratorListResult DeserializeAuthoriza List array = new List(); foreach (var item in property.Value.EnumerateArray()) { - array.Add(AuthorizationClassicAdministrator.DeserializeAuthorizationClassicAdministrator(item, options)); + array.Add(AuthorizationClassicAdministrator.DeserializeAuthorizationClassicAdministrator(item)); } value = array; continue; @@ -113,6 +116,107 @@ internal static AuthorizationClassicAdministratorListResult DeserializeAuthoriza return new AuthorizationClassicAdministratorListResult(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, " value: "); + } + 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 formattedPropertyName) + { + string indent = new string(' ', spaces); + int emptyObjectLength = 2 + spaces + Environment.NewLine.Length + Environment.NewLine.Length; + int length = stringBuilder.Length; + bool inMultilineString = false; + + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + 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}"); + } + } + if (stringBuilder.Length == length + emptyObjectLength) + { + stringBuilder.Length = stringBuilder.Length - emptyObjectLength - formattedPropertyName.Length; + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -121,6 +225,8 @@ BinaryData IPersistableModel.Write( { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(AuthorizationClassicAdministratorListResult)} does not support '{options.Format}' format."); } @@ -137,6 +243,8 @@ AuthorizationClassicAdministratorListResult 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(DisplayName), out propertyOverride); + if (Optional.IsDefined(DisplayName) || hasPropertyOverride) + { + builder.Append(" displayName: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + if (DisplayName.Contains(Environment.NewLine)) + { + builder.AppendLine("'''"); + builder.AppendLine($"{DisplayName}'''"); + } + else + { + builder.AppendLine($"'{DisplayName}'"); + } + } + } + + 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(Origin), out propertyOverride); + if (Optional.IsDefined(Origin) || hasPropertyOverride) + { + builder.Append(" origin: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + if (Origin.Contains(Environment.NewLine)) + { + builder.AppendLine("'''"); + builder.AppendLine($"{Origin}'''"); + } + else + { + builder.AppendLine($"'{Origin}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Properties), out propertyOverride); + if (Optional.IsDefined(Properties) || hasPropertyOverride) + { + builder.Append(" properties: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{Properties.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(IsDataAction), out propertyOverride); + if (Optional.IsDefined(IsDataAction) || hasPropertyOverride) + { + builder.Append(" isDataAction: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + var boolValue = IsDataAction.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 formattedPropertyName) + { + string indent = new string(' ', spaces); + int emptyObjectLength = 2 + spaces + Environment.NewLine.Length + Environment.NewLine.Length; + int length = stringBuilder.Length; + bool inMultilineString = false; + + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + 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}"); + } + } + if (stringBuilder.Length == length + emptyObjectLength) + { + stringBuilder.Length = stringBuilder.Length - emptyObjectLength - formattedPropertyName.Length; + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -174,6 +350,8 @@ BinaryData IPersistableModel.Write(ModelRead { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(AuthorizationProviderOperationInfo)} does not support '{options.Format}' format."); } @@ -190,6 +368,8 @@ AuthorizationProviderOperationInfo IPersistableModel The operation name. + [WirePath("name")] public string Name { get; } /// The operation display name. + [WirePath("displayName")] public string DisplayName { get; } /// The operation description. + [WirePath("description")] public string Description { get; } /// The operation origin. + [WirePath("origin")] public string Origin { get; } /// /// The operation properties. @@ -107,8 +111,10 @@ internal AuthorizationProviderOperationInfo(string name, string displayName, str /// /// /// + [WirePath("properties")] public BinaryData Properties { get; } /// The dataAction flag to specify the operation type. + [WirePath("isDataAction")] public bool? IsDataAction { get; } } } diff --git a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/AuthorizationProviderOperationsMetadataListResult.Serialization.cs b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/AuthorizationProviderOperationsMetadataListResult.Serialization.cs index 0fbf1cbd44c1d..66dbade0deb99 100644 --- a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/AuthorizationProviderOperationsMetadataListResult.Serialization.cs +++ b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/AuthorizationProviderOperationsMetadataListResult.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.Authorization; namespace Azure.ResourceManager.Authorization.Models @@ -95,7 +98,7 @@ internal static AuthorizationProviderOperationsMetadataListResult DeserializeAut List array = new List(); foreach (var item in property.Value.EnumerateArray()) { - array.Add(AuthorizationProviderOperationsMetadataData.DeserializeAuthorizationProviderOperationsMetadataData(item, options)); + array.Add(AuthorizationProviderOperationsMetadataData.DeserializeAuthorizationProviderOperationsMetadataData(item)); } value = array; continue; @@ -114,6 +117,107 @@ internal static AuthorizationProviderOperationsMetadataListResult DeserializeAut return new AuthorizationProviderOperationsMetadataListResult(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, " value: "); + } + 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 formattedPropertyName) + { + string indent = new string(' ', spaces); + int emptyObjectLength = 2 + spaces + Environment.NewLine.Length + Environment.NewLine.Length; + int length = stringBuilder.Length; + bool inMultilineString = false; + + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + 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}"); + } + } + if (stringBuilder.Length == length + emptyObjectLength) + { + stringBuilder.Length = stringBuilder.Length - emptyObjectLength - formattedPropertyName.Length; + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -122,6 +226,8 @@ BinaryData IPersistableModel. { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(AuthorizationProviderOperationsMetadataListResult)} does not support '{options.Format}' format."); } @@ -138,6 +244,8 @@ AuthorizationProviderOperationsMetadataListResult IPersistableModel array = new List(); foreach (var item in property.Value.EnumerateArray()) { - array.Add(AuthorizationProviderOperationInfo.DeserializeAuthorizationProviderOperationInfo(item, options)); + array.Add(AuthorizationProviderOperationInfo.DeserializeAuthorizationProviderOperationInfo(item)); } operations = array; continue; @@ -124,6 +127,129 @@ internal static AuthorizationProviderResourceType DeserializeAuthorizationProvid return new AuthorizationProviderResourceType(name.Value, displayName.Value, Optional.ToList(operations), 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(DisplayName), out propertyOverride); + if (Optional.IsDefined(DisplayName) || hasPropertyOverride) + { + builder.Append(" displayName: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + if (DisplayName.Contains(Environment.NewLine)) + { + builder.AppendLine("'''"); + builder.AppendLine($"{DisplayName}'''"); + } + else + { + builder.AppendLine($"'{DisplayName}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Operations), out propertyOverride); + if (Optional.IsCollectionDefined(Operations) || hasPropertyOverride) + { + if (Operations.Any() || hasPropertyOverride) + { + builder.Append(" operations: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine("["); + foreach (var item in Operations) + { + AppendChildObject(builder, item, options, 4, true, " operations: "); + } + builder.AppendLine(" ]"); + } + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine, string formattedPropertyName) + { + string indent = new string(' ', spaces); + int emptyObjectLength = 2 + spaces + Environment.NewLine.Length + Environment.NewLine.Length; + int length = stringBuilder.Length; + bool inMultilineString = false; + + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + 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}"); + } + } + if (stringBuilder.Length == length + emptyObjectLength) + { + stringBuilder.Length = stringBuilder.Length - emptyObjectLength - formattedPropertyName.Length; + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -132,6 +258,8 @@ BinaryData IPersistableModel.Write(ModelReade { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(AuthorizationProviderResourceType)} does not support '{options.Format}' format."); } @@ -148,6 +276,8 @@ AuthorizationProviderResourceType IPersistableModel The resource type name. + [WirePath("name")] public string Name { get; } /// The resource type display name. + [WirePath("displayName")] public string DisplayName { get; } /// The resource type operations. + [WirePath("operations")] public IReadOnlyList Operations { get; } } } diff --git a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/DenyAssignmentListResult.Serialization.cs b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/DenyAssignmentListResult.Serialization.cs index e3b3d57d5a868..67d78197ed021 100644 --- a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/DenyAssignmentListResult.Serialization.cs +++ b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/DenyAssignmentListResult.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.Authorization; namespace Azure.ResourceManager.Authorization.Models @@ -95,7 +98,7 @@ internal static DenyAssignmentListResult DeserializeDenyAssignmentListResult(Jso List array = new List(); foreach (var item in property.Value.EnumerateArray()) { - array.Add(DenyAssignmentData.DeserializeDenyAssignmentData(item, options)); + array.Add(DenyAssignmentData.DeserializeDenyAssignmentData(item)); } value = array; continue; @@ -114,6 +117,107 @@ internal static DenyAssignmentListResult DeserializeDenyAssignmentListResult(Jso return new DenyAssignmentListResult(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, " value: "); + } + 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 formattedPropertyName) + { + string indent = new string(' ', spaces); + int emptyObjectLength = 2 + spaces + Environment.NewLine.Length + Environment.NewLine.Length; + int length = stringBuilder.Length; + bool inMultilineString = false; + + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + 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}"); + } + } + if (stringBuilder.Length == length + emptyObjectLength) + { + stringBuilder.Length = stringBuilder.Length - emptyObjectLength - formattedPropertyName.Length; + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -122,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(DenyAssignmentListResult)} does not support '{options.Format}' format."); } @@ -138,6 +244,8 @@ DenyAssignmentListResult IPersistableModel.Create(Bina using JsonDocument document = JsonDocument.Parse(data); return DeserializeDenyAssignmentListResult(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(DenyAssignmentListResult)} does not support '{options.Format}' format."); } diff --git a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/DenyAssignmentPermission.Serialization.cs b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/DenyAssignmentPermission.Serialization.cs index 197ba1b0e7057..61849a0b6b3db 100644 --- a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/DenyAssignmentPermission.Serialization.cs +++ b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/DenyAssignmentPermission.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.Authorization.Models { @@ -199,6 +202,247 @@ internal static DenyAssignmentPermission DeserializeDenyAssignmentPermission(Jso return new DenyAssignmentPermission(Optional.ToList(actions), Optional.ToList(notActions), Optional.ToList(dataActions), Optional.ToList(notDataActions), condition.Value, conditionVersion.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.IsCollectionDefined(Actions) || hasPropertyOverride) + { + if (Actions.Any() || hasPropertyOverride) + { + builder.Append(" actions: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine("["); + foreach (var item in Actions) + { + 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(NotActions), out propertyOverride); + if (Optional.IsCollectionDefined(NotActions) || hasPropertyOverride) + { + if (NotActions.Any() || hasPropertyOverride) + { + builder.Append(" notActions: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine("["); + foreach (var item in NotActions) + { + 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(DataActions), out propertyOverride); + if (Optional.IsCollectionDefined(DataActions) || hasPropertyOverride) + { + if (DataActions.Any() || hasPropertyOverride) + { + builder.Append(" dataActions: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine("["); + foreach (var item in DataActions) + { + 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(NotDataActions), out propertyOverride); + if (Optional.IsCollectionDefined(NotDataActions) || hasPropertyOverride) + { + if (NotDataActions.Any() || hasPropertyOverride) + { + builder.Append(" notDataActions: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine("["); + foreach (var item in NotDataActions) + { + 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(Condition), out propertyOverride); + if (Optional.IsDefined(Condition) || hasPropertyOverride) + { + builder.Append(" condition: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + if (Condition.Contains(Environment.NewLine)) + { + builder.AppendLine("'''"); + builder.AppendLine($"{Condition}'''"); + } + else + { + builder.AppendLine($"'{Condition}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ConditionVersion), out propertyOverride); + if (Optional.IsDefined(ConditionVersion) || hasPropertyOverride) + { + builder.Append(" conditionVersion: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + if (ConditionVersion.Contains(Environment.NewLine)) + { + builder.AppendLine("'''"); + builder.AppendLine($"{ConditionVersion}'''"); + } + else + { + builder.AppendLine($"'{ConditionVersion}'"); + } + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine, string formattedPropertyName) + { + string indent = new string(' ', spaces); + int emptyObjectLength = 2 + spaces + Environment.NewLine.Length + Environment.NewLine.Length; + int length = stringBuilder.Length; + bool inMultilineString = false; + + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + 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}"); + } + } + if (stringBuilder.Length == length + emptyObjectLength) + { + stringBuilder.Length = stringBuilder.Length - emptyObjectLength - formattedPropertyName.Length; + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -207,6 +451,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOp { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(DenyAssignmentPermission)} does not support '{options.Format}' format."); } @@ -223,6 +469,8 @@ DenyAssignmentPermission IPersistableModel.Create(Bina using JsonDocument document = JsonDocument.Parse(data); return DeserializeDenyAssignmentPermission(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(DenyAssignmentPermission)} does not support '{options.Format}' format."); } diff --git a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/DenyAssignmentPermission.cs b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/DenyAssignmentPermission.cs index 2920ed9180490..67c93041dbcc6 100644 --- a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/DenyAssignmentPermission.cs +++ b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/DenyAssignmentPermission.cs @@ -75,16 +75,22 @@ internal DenyAssignmentPermission(IReadOnlyList actions, IReadOnlyList Actions to which the deny assignment does not grant access. + [WirePath("actions")] public IReadOnlyList Actions { get; } /// Actions to exclude from that the deny assignment does not grant access. + [WirePath("notActions")] public IReadOnlyList NotActions { get; } /// Data actions to which the deny assignment does not grant access. + [WirePath("dataActions")] public IReadOnlyList DataActions { get; } /// Data actions to exclude from that the deny assignment does not grant access. + [WirePath("notDataActions")] public IReadOnlyList NotDataActions { get; } /// The conditions on the Deny assignment permission. This limits the resources it applies to. + [WirePath("condition")] public string Condition { get; } /// Version of the condition. + [WirePath("conditionVersion")] public string ConditionVersion { get; } } } diff --git a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/EligibleChildResource.Serialization.cs b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/EligibleChildResource.Serialization.cs index 76bfda954b532..4db0b098b6fc2 100644 --- a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/EligibleChildResource.Serialization.cs +++ b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/EligibleChildResource.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.Authorization.Models { @@ -110,6 +112,107 @@ internal static EligibleChildResource DeserializeEligibleChildResource(JsonEleme return new EligibleChildResource(id.Value, name.Value, type.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 + { + if (Id.Contains(Environment.NewLine)) + { + builder.AppendLine("'''"); + builder.AppendLine($"{Id}'''"); + } + else + { + builder.AppendLine($"'{Id}'"); + } + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine, string formattedPropertyName) + { + string indent = new string(' ', spaces); + int emptyObjectLength = 2 + spaces + Environment.NewLine.Length + Environment.NewLine.Length; + int length = stringBuilder.Length; + bool inMultilineString = false; + + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + 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}"); + } + } + if (stringBuilder.Length == length + emptyObjectLength) + { + stringBuilder.Length = stringBuilder.Length - emptyObjectLength - formattedPropertyName.Length; + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -118,6 +221,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOptio { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(EligibleChildResource)} does not support '{options.Format}' format."); } @@ -134,6 +239,8 @@ EligibleChildResource IPersistableModel.Create(BinaryData using JsonDocument document = JsonDocument.Parse(data); return DeserializeEligibleChildResource(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(EligibleChildResource)} does not support '{options.Format}' format."); } diff --git a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/EligibleChildResource.cs b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/EligibleChildResource.cs index ada97cd4a7700..2cfba81500c75 100644 --- a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/EligibleChildResource.cs +++ b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/EligibleChildResource.cs @@ -64,10 +64,13 @@ internal EligibleChildResource(string id, string name, string resourceType, IDic } /// The resource scope Id. + [WirePath("id")] public string Id { get; } /// The resource name. + [WirePath("name")] public string Name { get; } /// The resource type. + [WirePath("type")] public string ResourceType { get; } } } diff --git a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/EligibleChildResourcesListResult.Serialization.cs b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/EligibleChildResourcesListResult.Serialization.cs index 63c71e1dcd164..0a7a09e56e753 100644 --- a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/EligibleChildResourcesListResult.Serialization.cs +++ b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/EligibleChildResourcesListResult.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.Authorization.Models { @@ -94,7 +97,7 @@ internal static EligibleChildResourcesListResult DeserializeEligibleChildResourc List array = new List(); foreach (var item in property.Value.EnumerateArray()) { - array.Add(EligibleChildResource.DeserializeEligibleChildResource(item, options)); + array.Add(EligibleChildResource.DeserializeEligibleChildResource(item)); } value = array; continue; @@ -113,6 +116,107 @@ internal static EligibleChildResourcesListResult DeserializeEligibleChildResourc return new EligibleChildResourcesListResult(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, " value: "); + } + 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 formattedPropertyName) + { + string indent = new string(' ', spaces); + int emptyObjectLength = 2 + spaces + Environment.NewLine.Length + Environment.NewLine.Length; + int length = stringBuilder.Length; + bool inMultilineString = false; + + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + 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}"); + } + } + if (stringBuilder.Length == length + emptyObjectLength) + { + stringBuilder.Length = stringBuilder.Length - emptyObjectLength - formattedPropertyName.Length; + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -121,6 +225,8 @@ BinaryData IPersistableModel.Write(ModelReader { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(EligibleChildResourcesListResult)} does not support '{options.Format}' format."); } @@ -137,6 +243,8 @@ EligibleChildResourcesListResult 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(" policy:"); + builder.AppendLine(" {"); + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(PolicyId), out propertyOverride); + if (Optional.IsDefined(PolicyId) || hasPropertyOverride) + { + builder.Append(" id: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{PolicyId.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(LastModifiedBy), out propertyOverride); + if (Optional.IsDefined(LastModifiedBy) || hasPropertyOverride) + { + builder.Append(" lastModifiedBy: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + AppendChildObject(builder, LastModifiedBy, options, 4, false, " lastModifiedBy: "); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(LastModifiedOn), out propertyOverride); + if (Optional.IsDefined(LastModifiedOn) || hasPropertyOverride) + { + builder.Append(" lastModifiedDateTime: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + var formattedDateTimeString = TypeFormatters.ToString(LastModifiedOn.Value, "o"); + builder.AppendLine($"'{formattedDateTimeString}'"); + } + } + + builder.AppendLine(" }"); + builder.Append(" roleDefinition:"); + builder.AppendLine(" {"); + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(RoleDefinitionId), out propertyOverride); + if (Optional.IsDefined(RoleDefinitionId) || hasPropertyOverride) + { + builder.Append(" id: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{RoleDefinitionId.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(RoleDefinitionDisplayName), out propertyOverride); + if (Optional.IsDefined(RoleDefinitionDisplayName) || hasPropertyOverride) + { + builder.Append(" displayName: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + if (RoleDefinitionDisplayName.Contains(Environment.NewLine)) + { + builder.AppendLine("'''"); + builder.AppendLine($"{RoleDefinitionDisplayName}'''"); + } + else + { + builder.AppendLine($"'{RoleDefinitionDisplayName}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(RoleType), out propertyOverride); + if (Optional.IsDefined(RoleType) || hasPropertyOverride) + { + builder.Append(" type: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{RoleType.Value.ToString()}'"); + } + } + + builder.AppendLine(" }"); + builder.Append(" scope:"); + builder.AppendLine(" {"); + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ScopeId), out propertyOverride); + if (Optional.IsDefined(ScopeId) || hasPropertyOverride) + { + builder.Append(" id: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{ScopeId.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ScopeDisplayName), out propertyOverride); + if (Optional.IsDefined(ScopeDisplayName) || hasPropertyOverride) + { + builder.Append(" displayName: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + if (ScopeDisplayName.Contains(Environment.NewLine)) + { + builder.AppendLine("'''"); + builder.AppendLine($"{ScopeDisplayName}'''"); + } + else + { + builder.AppendLine($"'{ScopeDisplayName}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ScopeType), out propertyOverride); + if (Optional.IsDefined(ScopeType) || hasPropertyOverride) + { + builder.Append(" type: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{ScopeType.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 formattedPropertyName) + { + string indent = new string(' ', spaces); + int emptyObjectLength = 2 + spaces + Environment.NewLine.Length + Environment.NewLine.Length; + int length = stringBuilder.Length; + bool inMultilineString = false; + + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + 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}"); + } + } + if (stringBuilder.Length == length + emptyObjectLength) + { + stringBuilder.Length = stringBuilder.Length - emptyObjectLength - formattedPropertyName.Length; + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -306,6 +567,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriter { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(PolicyAssignmentProperties)} does not support '{options.Format}' format."); } @@ -322,6 +585,8 @@ PolicyAssignmentProperties IPersistableModel.Create( using JsonDocument document = JsonDocument.Parse(data); return DeserializePolicyAssignmentProperties(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(PolicyAssignmentProperties)} does not support '{options.Format}' format."); } diff --git a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/PolicyAssignmentProperties.cs b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/PolicyAssignmentProperties.cs index 2b7f19c231b49..0bd08e00b0a10 100644 --- a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/PolicyAssignmentProperties.cs +++ b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/PolicyAssignmentProperties.cs @@ -82,22 +82,31 @@ internal PolicyAssignmentProperties(ResourceIdentifier id, string name, Resource } /// Id of the policy. + [WirePath("policy.id")] public ResourceIdentifier PolicyId { get; } /// The name of the entity last modified it. + [WirePath("policy.lastModifiedBy")] public RoleManagementPrincipal LastModifiedBy { get; } /// The last modified date time. + [WirePath("policy.lastModifiedDateTime")] public DateTimeOffset? LastModifiedOn { get; } /// Id of the role definition. + [WirePath("roleDefinition.id")] public ResourceIdentifier RoleDefinitionId { get; } /// Display name of the role definition. + [WirePath("roleDefinition.displayName")] public string RoleDefinitionDisplayName { get; } /// The role type. + [WirePath("roleDefinition.type")] public AuthorizationRoleType? RoleType { get; } /// Scope id of the resource. + [WirePath("scope.id")] public ResourceIdentifier ScopeId { get; } /// Display name of the resource. + [WirePath("scope.displayName")] public string ScopeDisplayName { get; } /// Type of the scope. + [WirePath("scope.type")] public RoleManagementScopeType? ScopeType { get; } } } diff --git a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleAssignmentCreateOrUpdateContent.cs b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleAssignmentCreateOrUpdateContent.cs index 0990aa080b78b..24671a303ee97 100644 --- a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleAssignmentCreateOrUpdateContent.cs +++ b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleAssignmentCreateOrUpdateContent.cs @@ -98,28 +98,40 @@ internal RoleAssignmentCreateOrUpdateContent() } /// The role assignment scope. + [WirePath("properties.scope")] public string Scope { get; } /// The role definition ID. + [WirePath("properties.roleDefinitionId")] public ResourceIdentifier RoleDefinitionId { get; } /// The principal ID. + [WirePath("properties.principalId")] public Guid PrincipalId { get; } /// The principal type of the assigned principal ID. + [WirePath("properties.principalType")] public RoleManagementPrincipalType? PrincipalType { get; set; } /// Description of role assignment. + [WirePath("properties.description")] public string Description { get; set; } /// The conditions on the role assignment. This limits the resources it can be assigned to. e.g.: @Resource[Microsoft.Storage/storageAccounts/blobServices/containers:ContainerName] StringEqualsIgnoreCase 'foo_storage_container'. + [WirePath("properties.condition")] public string Condition { get; set; } /// Version of the condition. Currently the only accepted value is '2.0'. + [WirePath("properties.conditionVersion")] public string ConditionVersion { get; set; } /// Time it was created. + [WirePath("properties.createdOn")] public DateTimeOffset? CreatedOn { get; } /// Time it was updated. + [WirePath("properties.updatedOn")] public DateTimeOffset? UpdatedOn { get; } /// Id of the user who created the assignment. + [WirePath("properties.createdBy")] public string CreatedBy { get; } /// Id of the user who updated the assignment. + [WirePath("properties.updatedBy")] public string UpdatedBy { get; } /// Id of the delegated managed identity resource. + [WirePath("properties.delegatedManagedIdentityResourceId")] public ResourceIdentifier DelegatedManagedIdentityResourceId { get; set; } } } diff --git a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleAssignmentListResult.Serialization.cs b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleAssignmentListResult.Serialization.cs index 1774495a9303a..7a89668e59330 100644 --- a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleAssignmentListResult.Serialization.cs +++ b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleAssignmentListResult.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.Authorization; namespace Azure.ResourceManager.Authorization.Models @@ -95,7 +98,7 @@ internal static RoleAssignmentListResult DeserializeRoleAssignmentListResult(Jso List array = new List(); foreach (var item in property.Value.EnumerateArray()) { - array.Add(RoleAssignmentData.DeserializeRoleAssignmentData(item, options)); + array.Add(RoleAssignmentData.DeserializeRoleAssignmentData(item)); } value = array; continue; @@ -114,6 +117,107 @@ internal static RoleAssignmentListResult DeserializeRoleAssignmentListResult(Jso return new RoleAssignmentListResult(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, " value: "); + } + 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 formattedPropertyName) + { + string indent = new string(' ', spaces); + int emptyObjectLength = 2 + spaces + Environment.NewLine.Length + Environment.NewLine.Length; + int length = stringBuilder.Length; + bool inMultilineString = false; + + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + 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}"); + } + } + if (stringBuilder.Length == length + emptyObjectLength) + { + stringBuilder.Length = stringBuilder.Length - emptyObjectLength - formattedPropertyName.Length; + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -122,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(RoleAssignmentListResult)} does not support '{options.Format}' format."); } @@ -138,6 +244,8 @@ RoleAssignmentListResult IPersistableModel.Create(Bina using JsonDocument document = JsonDocument.Parse(data); return DeserializeRoleAssignmentListResult(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(RoleAssignmentListResult)} does not support '{options.Format}' format."); } diff --git a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleAssignmentScheduleInstanceListResult.Serialization.cs b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleAssignmentScheduleInstanceListResult.Serialization.cs index 7f38e6c12d714..46b3c40e11707 100644 --- a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleAssignmentScheduleInstanceListResult.Serialization.cs +++ b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleAssignmentScheduleInstanceListResult.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.Authorization; namespace Azure.ResourceManager.Authorization.Models @@ -95,7 +98,7 @@ internal static RoleAssignmentScheduleInstanceListResult DeserializeRoleAssignme List array = new List(); foreach (var item in property.Value.EnumerateArray()) { - array.Add(RoleAssignmentScheduleInstanceData.DeserializeRoleAssignmentScheduleInstanceData(item, options)); + array.Add(RoleAssignmentScheduleInstanceData.DeserializeRoleAssignmentScheduleInstanceData(item)); } value = array; continue; @@ -114,6 +117,107 @@ internal static RoleAssignmentScheduleInstanceListResult DeserializeRoleAssignme return new RoleAssignmentScheduleInstanceListResult(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, " value: "); + } + 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 formattedPropertyName) + { + string indent = new string(' ', spaces); + int emptyObjectLength = 2 + spaces + Environment.NewLine.Length + Environment.NewLine.Length; + int length = stringBuilder.Length; + bool inMultilineString = false; + + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + 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}"); + } + } + if (stringBuilder.Length == length + emptyObjectLength) + { + stringBuilder.Length = stringBuilder.Length - emptyObjectLength - formattedPropertyName.Length; + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -122,6 +226,8 @@ BinaryData IPersistableModel.Write(Mod { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(RoleAssignmentScheduleInstanceListResult)} does not support '{options.Format}' format."); } @@ -138,6 +244,8 @@ RoleAssignmentScheduleInstanceListResult IPersistableModel array = new List(); foreach (var item in property.Value.EnumerateArray()) { - array.Add(RoleAssignmentScheduleData.DeserializeRoleAssignmentScheduleData(item, options)); + array.Add(RoleAssignmentScheduleData.DeserializeRoleAssignmentScheduleData(item)); } value = array; continue; @@ -114,6 +117,107 @@ internal static RoleAssignmentScheduleListResult DeserializeRoleAssignmentSchedu return new RoleAssignmentScheduleListResult(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, " value: "); + } + 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 formattedPropertyName) + { + string indent = new string(' ', spaces); + int emptyObjectLength = 2 + spaces + Environment.NewLine.Length + Environment.NewLine.Length; + int length = stringBuilder.Length; + bool inMultilineString = false; + + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + 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}"); + } + } + if (stringBuilder.Length == length + emptyObjectLength) + { + stringBuilder.Length = stringBuilder.Length - emptyObjectLength - formattedPropertyName.Length; + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -122,6 +226,8 @@ BinaryData IPersistableModel.Write(ModelReader { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(RoleAssignmentScheduleListResult)} does not support '{options.Format}' format."); } @@ -138,6 +244,8 @@ RoleAssignmentScheduleListResult IPersistableModel array = new List(); foreach (var item in property.Value.EnumerateArray()) { - array.Add(RoleAssignmentScheduleRequestData.DeserializeRoleAssignmentScheduleRequestData(item, options)); + array.Add(RoleAssignmentScheduleRequestData.DeserializeRoleAssignmentScheduleRequestData(item)); } value = array; continue; @@ -114,6 +117,107 @@ internal static RoleAssignmentScheduleRequestListResult DeserializeRoleAssignmen return new RoleAssignmentScheduleRequestListResult(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, " value: "); + } + 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 formattedPropertyName) + { + string indent = new string(' ', spaces); + int emptyObjectLength = 2 + spaces + Environment.NewLine.Length + Environment.NewLine.Length; + int length = stringBuilder.Length; + bool inMultilineString = false; + + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + 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}"); + } + } + if (stringBuilder.Length == length + emptyObjectLength) + { + stringBuilder.Length = stringBuilder.Length - emptyObjectLength - formattedPropertyName.Length; + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -122,6 +226,8 @@ BinaryData IPersistableModel.Write(Mode { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(RoleAssignmentScheduleRequestListResult)} does not support '{options.Format}' format."); } @@ -138,6 +244,8 @@ RoleAssignmentScheduleRequestListResult 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(TicketNumber), out propertyOverride); + if (Optional.IsDefined(TicketNumber) || hasPropertyOverride) + { + builder.Append(" ticketNumber: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + if (TicketNumber.Contains(Environment.NewLine)) + { + builder.AppendLine("'''"); + builder.AppendLine($"{TicketNumber}'''"); + } + else + { + builder.AppendLine($"'{TicketNumber}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(TicketSystem), out propertyOverride); + if (Optional.IsDefined(TicketSystem) || hasPropertyOverride) + { + builder.Append(" ticketSystem: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + if (TicketSystem.Contains(Environment.NewLine)) + { + builder.AppendLine("'''"); + builder.AppendLine($"{TicketSystem}'''"); + } + else + { + builder.AppendLine($"'{TicketSystem}'"); + } + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine, string formattedPropertyName) + { + string indent = new string(' ', spaces); + int emptyObjectLength = 2 + spaces + Environment.NewLine.Length + Environment.NewLine.Length; + int length = stringBuilder.Length; + bool inMultilineString = false; + + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + 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}"); + } + } + if (stringBuilder.Length == length + emptyObjectLength) + { + stringBuilder.Length = stringBuilder.Length - emptyObjectLength - formattedPropertyName.Length; + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -107,6 +210,8 @@ BinaryData IPersistableModel.Write(ModelReader { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(RoleAssignmentScheduleTicketInfo)} does not support '{options.Format}' format."); } @@ -123,6 +228,8 @@ RoleAssignmentScheduleTicketInfo IPersistableModel Ticket number for the role assignment. + [WirePath("ticketNumber")] public string TicketNumber { get; set; } /// Ticket system name for the role assignment. + [WirePath("ticketSystem")] public string TicketSystem { get; set; } } } diff --git a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleDefinitionListResult.Serialization.cs b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleDefinitionListResult.Serialization.cs index 3e0355b3498e8..bb5d395b29060 100644 --- a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleDefinitionListResult.Serialization.cs +++ b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleDefinitionListResult.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.Authorization; namespace Azure.ResourceManager.Authorization.Models @@ -95,7 +98,7 @@ internal static RoleDefinitionListResult DeserializeRoleDefinitionListResult(Jso List array = new List(); foreach (var item in property.Value.EnumerateArray()) { - array.Add(AuthorizationRoleDefinitionData.DeserializeAuthorizationRoleDefinitionData(item, options)); + array.Add(AuthorizationRoleDefinitionData.DeserializeAuthorizationRoleDefinitionData(item)); } value = array; continue; @@ -114,6 +117,107 @@ internal static RoleDefinitionListResult DeserializeRoleDefinitionListResult(Jso return new RoleDefinitionListResult(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, " value: "); + } + 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 formattedPropertyName) + { + string indent = new string(' ', spaces); + int emptyObjectLength = 2 + spaces + Environment.NewLine.Length + Environment.NewLine.Length; + int length = stringBuilder.Length; + bool inMultilineString = false; + + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + 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}"); + } + } + if (stringBuilder.Length == length + emptyObjectLength) + { + stringBuilder.Length = stringBuilder.Length - emptyObjectLength - formattedPropertyName.Length; + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -122,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(RoleDefinitionListResult)} does not support '{options.Format}' format."); } @@ -138,6 +244,8 @@ RoleDefinitionListResult IPersistableModel.Create(Bina using JsonDocument document = JsonDocument.Parse(data); return DeserializeRoleDefinitionListResult(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(RoleDefinitionListResult)} does not support '{options.Format}' format."); } diff --git a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleDefinitionPermission.Serialization.cs b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleDefinitionPermission.Serialization.cs index ec75982624ef9..d33103d3ad907 100644 --- a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleDefinitionPermission.Serialization.cs +++ b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleDefinitionPermission.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.Authorization.Models { @@ -177,6 +180,203 @@ internal static RoleDefinitionPermission DeserializeRoleDefinitionPermission(Jso return new RoleDefinitionPermission(Optional.ToList(actions), Optional.ToList(notActions), Optional.ToList(dataActions), Optional.ToList(notDataActions), 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.IsCollectionDefined(Actions) || hasPropertyOverride) + { + if (Actions.Any() || hasPropertyOverride) + { + builder.Append(" actions: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine("["); + foreach (var item in Actions) + { + 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(NotActions), out propertyOverride); + if (Optional.IsCollectionDefined(NotActions) || hasPropertyOverride) + { + if (NotActions.Any() || hasPropertyOverride) + { + builder.Append(" notActions: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine("["); + foreach (var item in NotActions) + { + 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(DataActions), out propertyOverride); + if (Optional.IsCollectionDefined(DataActions) || hasPropertyOverride) + { + if (DataActions.Any() || hasPropertyOverride) + { + builder.Append(" dataActions: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine("["); + foreach (var item in DataActions) + { + 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(NotDataActions), out propertyOverride); + if (Optional.IsCollectionDefined(NotDataActions) || hasPropertyOverride) + { + if (NotDataActions.Any() || hasPropertyOverride) + { + builder.Append(" notDataActions: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine("["); + foreach (var item in NotDataActions) + { + 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 formattedPropertyName) + { + string indent = new string(' ', spaces); + int emptyObjectLength = 2 + spaces + Environment.NewLine.Length + Environment.NewLine.Length; + int length = stringBuilder.Length; + bool inMultilineString = false; + + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + 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}"); + } + } + if (stringBuilder.Length == length + emptyObjectLength) + { + stringBuilder.Length = stringBuilder.Length - emptyObjectLength - formattedPropertyName.Length; + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -185,6 +385,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOp { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(RoleDefinitionPermission)} does not support '{options.Format}' format."); } @@ -201,6 +403,8 @@ RoleDefinitionPermission IPersistableModel.Create(Bina using JsonDocument document = JsonDocument.Parse(data); return DeserializeRoleDefinitionPermission(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(RoleDefinitionPermission)} does not support '{options.Format}' format."); } diff --git a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleDefinitionPermission.cs b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleDefinitionPermission.cs index 1b33a9b67d5fc..6a7047083a8d9 100644 --- a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleDefinitionPermission.cs +++ b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleDefinitionPermission.cs @@ -71,12 +71,16 @@ internal RoleDefinitionPermission(IList actions, IList notAction } /// Allowed actions. + [WirePath("actions")] public IList Actions { get; } /// Denied actions. + [WirePath("notActions")] public IList NotActions { get; } /// Allowed Data actions. + [WirePath("dataActions")] public IList DataActions { get; } /// Denied Data actions. + [WirePath("notDataActions")] public IList NotDataActions { get; } } } diff --git a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleDefinitionPermissionListResult.Serialization.cs b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleDefinitionPermissionListResult.Serialization.cs index 4d293ed458b40..4e619f32405b7 100644 --- a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleDefinitionPermissionListResult.Serialization.cs +++ b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleDefinitionPermissionListResult.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.Authorization.Models { @@ -94,7 +97,7 @@ internal static RoleDefinitionPermissionListResult DeserializeRoleDefinitionPerm List array = new List(); foreach (var item in property.Value.EnumerateArray()) { - array.Add(RoleDefinitionPermission.DeserializeRoleDefinitionPermission(item, options)); + array.Add(RoleDefinitionPermission.DeserializeRoleDefinitionPermission(item)); } value = array; continue; @@ -113,6 +116,107 @@ internal static RoleDefinitionPermissionListResult DeserializeRoleDefinitionPerm return new RoleDefinitionPermissionListResult(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, " value: "); + } + 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 formattedPropertyName) + { + string indent = new string(' ', spaces); + int emptyObjectLength = 2 + spaces + Environment.NewLine.Length + Environment.NewLine.Length; + int length = stringBuilder.Length; + bool inMultilineString = false; + + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + 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}"); + } + } + if (stringBuilder.Length == length + emptyObjectLength) + { + stringBuilder.Length = stringBuilder.Length - emptyObjectLength - formattedPropertyName.Length; + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -121,6 +225,8 @@ BinaryData IPersistableModel.Write(ModelRead { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(RoleDefinitionPermissionListResult)} does not support '{options.Format}' format."); } @@ -137,6 +243,8 @@ RoleDefinitionPermissionListResult IPersistableModel array = new List(); foreach (var item in property.Value.EnumerateArray()) { - array.Add(RoleEligibilityScheduleInstanceData.DeserializeRoleEligibilityScheduleInstanceData(item, options)); + array.Add(RoleEligibilityScheduleInstanceData.DeserializeRoleEligibilityScheduleInstanceData(item)); } value = array; continue; @@ -114,6 +117,107 @@ internal static RoleEligibilityScheduleInstanceListResult DeserializeRoleEligibi return new RoleEligibilityScheduleInstanceListResult(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, " value: "); + } + 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 formattedPropertyName) + { + string indent = new string(' ', spaces); + int emptyObjectLength = 2 + spaces + Environment.NewLine.Length + Environment.NewLine.Length; + int length = stringBuilder.Length; + bool inMultilineString = false; + + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + 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}"); + } + } + if (stringBuilder.Length == length + emptyObjectLength) + { + stringBuilder.Length = stringBuilder.Length - emptyObjectLength - formattedPropertyName.Length; + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -122,6 +226,8 @@ BinaryData IPersistableModel.Write(Mo { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(RoleEligibilityScheduleInstanceListResult)} does not support '{options.Format}' format."); } @@ -138,6 +244,8 @@ RoleEligibilityScheduleInstanceListResult IPersistableModel array = new List(); foreach (var item in property.Value.EnumerateArray()) { - array.Add(RoleEligibilityScheduleData.DeserializeRoleEligibilityScheduleData(item, options)); + array.Add(RoleEligibilityScheduleData.DeserializeRoleEligibilityScheduleData(item)); } value = array; continue; @@ -114,6 +117,107 @@ internal static RoleEligibilityScheduleListResult DeserializeRoleEligibilitySche return new RoleEligibilityScheduleListResult(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, " value: "); + } + 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 formattedPropertyName) + { + string indent = new string(' ', spaces); + int emptyObjectLength = 2 + spaces + Environment.NewLine.Length + Environment.NewLine.Length; + int length = stringBuilder.Length; + bool inMultilineString = false; + + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + 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}"); + } + } + if (stringBuilder.Length == length + emptyObjectLength) + { + stringBuilder.Length = stringBuilder.Length - emptyObjectLength - formattedPropertyName.Length; + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -122,6 +226,8 @@ BinaryData IPersistableModel.Write(ModelReade { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(RoleEligibilityScheduleListResult)} does not support '{options.Format}' format."); } @@ -138,6 +244,8 @@ RoleEligibilityScheduleListResult IPersistableModel array = new List(); foreach (var item in property.Value.EnumerateArray()) { - array.Add(RoleEligibilityScheduleRequestData.DeserializeRoleEligibilityScheduleRequestData(item, options)); + array.Add(RoleEligibilityScheduleRequestData.DeserializeRoleEligibilityScheduleRequestData(item)); } value = array; continue; @@ -114,6 +117,107 @@ internal static RoleEligibilityScheduleRequestListResult DeserializeRoleEligibil return new RoleEligibilityScheduleRequestListResult(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, " value: "); + } + 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 formattedPropertyName) + { + string indent = new string(' ', spaces); + int emptyObjectLength = 2 + spaces + Environment.NewLine.Length + Environment.NewLine.Length; + int length = stringBuilder.Length; + bool inMultilineString = false; + + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + 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}"); + } + } + if (stringBuilder.Length == length + emptyObjectLength) + { + stringBuilder.Length = stringBuilder.Length - emptyObjectLength - formattedPropertyName.Length; + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -122,6 +226,8 @@ BinaryData IPersistableModel.Write(Mod { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(RoleEligibilityScheduleRequestListResult)} does not support '{options.Format}' format."); } @@ -138,6 +244,8 @@ RoleEligibilityScheduleRequestListResult 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(TicketNumber), out propertyOverride); + if (Optional.IsDefined(TicketNumber) || hasPropertyOverride) + { + builder.Append(" ticketNumber: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + if (TicketNumber.Contains(Environment.NewLine)) + { + builder.AppendLine("'''"); + builder.AppendLine($"{TicketNumber}'''"); + } + else + { + builder.AppendLine($"'{TicketNumber}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(TicketSystem), out propertyOverride); + if (Optional.IsDefined(TicketSystem) || hasPropertyOverride) + { + builder.Append(" ticketSystem: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + if (TicketSystem.Contains(Environment.NewLine)) + { + builder.AppendLine("'''"); + builder.AppendLine($"{TicketSystem}'''"); + } + else + { + builder.AppendLine($"'{TicketSystem}'"); + } + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine, string formattedPropertyName) + { + string indent = new string(' ', spaces); + int emptyObjectLength = 2 + spaces + Environment.NewLine.Length + Environment.NewLine.Length; + int length = stringBuilder.Length; + bool inMultilineString = false; + + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + 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}"); + } + } + if (stringBuilder.Length == length + emptyObjectLength) + { + stringBuilder.Length = stringBuilder.Length - emptyObjectLength - formattedPropertyName.Length; + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -107,6 +210,8 @@ BinaryData IPersistableModel { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(RoleEligibilityScheduleRequestPropertiesTicketInfo)} does not support '{options.Format}' format."); } @@ -123,6 +228,8 @@ RoleEligibilityScheduleRequestPropertiesTicketInfo IPersistableModel Ticket number for the role eligibility. + [WirePath("ticketNumber")] public string TicketNumber { get; set; } /// Ticket system name for the role eligibility. + [WirePath("ticketSystem")] public string TicketSystem { get; set; } } } diff --git a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementApprovalSettings.Serialization.cs b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementApprovalSettings.Serialization.cs index a52bb5ad1df5c..10dc7bb840aaf 100644 --- a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementApprovalSettings.Serialization.cs +++ b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementApprovalSettings.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.Authorization.Models { @@ -148,7 +151,7 @@ internal static RoleManagementApprovalSettings DeserializeRoleManagementApproval List array = new List(); foreach (var item in property.Value.EnumerateArray()) { - array.Add(RoleManagementApprovalStage.DeserializeRoleManagementApprovalStage(item, options)); + array.Add(RoleManagementApprovalStage.DeserializeRoleManagementApprovalStage(item)); } approvalStages = array; continue; @@ -162,6 +165,144 @@ internal static RoleManagementApprovalSettings DeserializeRoleManagementApproval return new RoleManagementApprovalSettings(Optional.ToNullable(isApprovalRequired), Optional.ToNullable(isApprovalRequiredForExtension), Optional.ToNullable(isRequestorJustificationRequired), Optional.ToNullable(approvalMode), Optional.ToList(approvalStages), 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(IsApprovalRequired), out propertyOverride); + if (Optional.IsDefined(IsApprovalRequired) || hasPropertyOverride) + { + builder.Append(" isApprovalRequired: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + var boolValue = IsApprovalRequired.Value == true ? "true" : "false"; + builder.AppendLine($"{boolValue}"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(IsApprovalRequiredForExtension), out propertyOverride); + if (Optional.IsDefined(IsApprovalRequiredForExtension) || hasPropertyOverride) + { + builder.Append(" isApprovalRequiredForExtension: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + var boolValue = IsApprovalRequiredForExtension.Value == true ? "true" : "false"; + builder.AppendLine($"{boolValue}"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(IsRequestorJustificationRequired), out propertyOverride); + if (Optional.IsDefined(IsRequestorJustificationRequired) || hasPropertyOverride) + { + builder.Append(" isRequestorJustificationRequired: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + var boolValue = IsRequestorJustificationRequired.Value == true ? "true" : "false"; + builder.AppendLine($"{boolValue}"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ApprovalMode), out propertyOverride); + if (Optional.IsDefined(ApprovalMode) || hasPropertyOverride) + { + builder.Append(" approvalMode: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{ApprovalMode.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ApprovalStages), out propertyOverride); + if (Optional.IsCollectionDefined(ApprovalStages) || hasPropertyOverride) + { + if (ApprovalStages.Any() || hasPropertyOverride) + { + builder.Append(" approvalStages: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine("["); + foreach (var item in ApprovalStages) + { + AppendChildObject(builder, item, options, 4, true, " approvalStages: "); + } + builder.AppendLine(" ]"); + } + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine, string formattedPropertyName) + { + string indent = new string(' ', spaces); + int emptyObjectLength = 2 + spaces + Environment.NewLine.Length + Environment.NewLine.Length; + int length = stringBuilder.Length; + bool inMultilineString = false; + + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + 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}"); + } + } + if (stringBuilder.Length == length + emptyObjectLength) + { + stringBuilder.Length = stringBuilder.Length - emptyObjectLength - formattedPropertyName.Length; + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -170,6 +311,8 @@ BinaryData IPersistableModel.Write(ModelReaderWr { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(RoleManagementApprovalSettings)} does not support '{options.Format}' format."); } @@ -186,6 +329,8 @@ RoleManagementApprovalSettings IPersistableModel using JsonDocument document = JsonDocument.Parse(data); return DeserializeRoleManagementApprovalSettings(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(RoleManagementApprovalSettings)} does not support '{options.Format}' format."); } diff --git a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementApprovalSettings.cs b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementApprovalSettings.cs index 1f51f32387720..ee3bcb0ba63b2 100644 --- a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementApprovalSettings.cs +++ b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementApprovalSettings.cs @@ -70,14 +70,19 @@ internal RoleManagementApprovalSettings(bool? isApprovalRequired, bool? isApprov } /// Determines whether approval is required or not. + [WirePath("isApprovalRequired")] public bool? IsApprovalRequired { get; set; } /// Determines whether approval is required for assignment extension. + [WirePath("isApprovalRequiredForExtension")] public bool? IsApprovalRequiredForExtension { get; set; } /// Determine whether requestor justification is required. + [WirePath("isRequestorJustificationRequired")] public bool? IsRequestorJustificationRequired { get; set; } /// The type of rule. + [WirePath("approvalMode")] public RoleManagementApprovalMode? ApprovalMode { get; set; } /// The approval stages of the request. + [WirePath("approvalStages")] public IList ApprovalStages { get; } } } diff --git a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementApprovalStage.Serialization.cs b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementApprovalStage.Serialization.cs index c6bbd9a38d016..6291c16314155 100644 --- a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementApprovalStage.Serialization.cs +++ b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementApprovalStage.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.Authorization.Models { @@ -150,7 +153,7 @@ internal static RoleManagementApprovalStage DeserializeRoleManagementApprovalSta List array = new List(); foreach (var item in property.Value.EnumerateArray()) { - array.Add(RoleManagementUserInfo.DeserializeRoleManagementUserInfo(item, options)); + array.Add(RoleManagementUserInfo.DeserializeRoleManagementUserInfo(item)); } primaryApprovers = array; continue; @@ -173,7 +176,7 @@ internal static RoleManagementApprovalStage DeserializeRoleManagementApprovalSta List array = new List(); foreach (var item in property.Value.EnumerateArray()) { - array.Add(RoleManagementUserInfo.DeserializeRoleManagementUserInfo(item, options)); + array.Add(RoleManagementUserInfo.DeserializeRoleManagementUserInfo(item)); } escalationApprovers = array; continue; @@ -187,6 +190,165 @@ internal static RoleManagementApprovalStage DeserializeRoleManagementApprovalSta return new RoleManagementApprovalStage(Optional.ToNullable(approvalStageTimeOutInDays), Optional.ToNullable(isApproverJustificationRequired), Optional.ToNullable(escalationTimeInMinutes), Optional.ToList(primaryApprovers), Optional.ToNullable(isEscalationEnabled), Optional.ToList(escalationApprovers), 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(ApprovalStageTimeOutInDays), out propertyOverride); + if (Optional.IsDefined(ApprovalStageTimeOutInDays) || hasPropertyOverride) + { + builder.Append(" approvalStageTimeOutInDays: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"{ApprovalStageTimeOutInDays.Value}"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(IsApproverJustificationRequired), out propertyOverride); + if (Optional.IsDefined(IsApproverJustificationRequired) || hasPropertyOverride) + { + builder.Append(" isApproverJustificationRequired: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + var boolValue = IsApproverJustificationRequired.Value == true ? "true" : "false"; + builder.AppendLine($"{boolValue}"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(EscalationTimeInMinutes), out propertyOverride); + if (Optional.IsDefined(EscalationTimeInMinutes) || hasPropertyOverride) + { + builder.Append(" escalationTimeInMinutes: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"{EscalationTimeInMinutes.Value}"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(PrimaryApprovers), out propertyOverride); + if (Optional.IsCollectionDefined(PrimaryApprovers) || hasPropertyOverride) + { + if (PrimaryApprovers.Any() || hasPropertyOverride) + { + builder.Append(" primaryApprovers: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine("["); + foreach (var item in PrimaryApprovers) + { + AppendChildObject(builder, item, options, 4, true, " primaryApprovers: "); + } + builder.AppendLine(" ]"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(IsEscalationEnabled), out propertyOverride); + if (Optional.IsDefined(IsEscalationEnabled) || hasPropertyOverride) + { + builder.Append(" isEscalationEnabled: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + var boolValue = IsEscalationEnabled.Value == true ? "true" : "false"; + builder.AppendLine($"{boolValue}"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(EscalationApprovers), out propertyOverride); + if (Optional.IsCollectionDefined(EscalationApprovers) || hasPropertyOverride) + { + if (EscalationApprovers.Any() || hasPropertyOverride) + { + builder.Append(" escalationApprovers: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine("["); + foreach (var item in EscalationApprovers) + { + AppendChildObject(builder, item, options, 4, true, " escalationApprovers: "); + } + builder.AppendLine(" ]"); + } + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine, string formattedPropertyName) + { + string indent = new string(' ', spaces); + int emptyObjectLength = 2 + spaces + Environment.NewLine.Length + Environment.NewLine.Length; + int length = stringBuilder.Length; + bool inMultilineString = false; + + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + 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}"); + } + } + if (stringBuilder.Length == length + emptyObjectLength) + { + stringBuilder.Length = stringBuilder.Length - emptyObjectLength - formattedPropertyName.Length; + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -195,6 +357,8 @@ BinaryData IPersistableModel.Write(ModelReaderWrite { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(RoleManagementApprovalStage)} does not support '{options.Format}' format."); } @@ -211,6 +375,8 @@ RoleManagementApprovalStage IPersistableModel.Creat using JsonDocument document = JsonDocument.Parse(data); return DeserializeRoleManagementApprovalStage(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(RoleManagementApprovalStage)} does not support '{options.Format}' format."); } diff --git a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementApprovalStage.cs b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementApprovalStage.cs index 0d5c9f3115a92..fb48821cb4c7a 100644 --- a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementApprovalStage.cs +++ b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementApprovalStage.cs @@ -73,16 +73,22 @@ internal RoleManagementApprovalStage(int? approvalStageTimeOutInDays, bool? isAp } /// The time in days when approval request would be timed out. + [WirePath("approvalStageTimeOutInDays")] public int? ApprovalStageTimeOutInDays { get; set; } /// Determines whether approver need to provide justification for his decision. + [WirePath("isApproverJustificationRequired")] public bool? IsApproverJustificationRequired { get; set; } /// The time in minutes when the approval request would be escalated if the primary approver does not approve. + [WirePath("escalationTimeInMinutes")] public int? EscalationTimeInMinutes { get; set; } /// The primary approver of the request. + [WirePath("primaryApprovers")] public IList PrimaryApprovers { get; } /// The value determine whether escalation feature is enabled. + [WirePath("isEscalationEnabled")] public bool? IsEscalationEnabled { get; set; } /// The escalation approver of the request. + [WirePath("escalationApprovers")] public IList EscalationApprovers { get; } } } diff --git a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementExpandedProperties.Serialization.cs b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementExpandedProperties.Serialization.cs index bbdb6821ee6cd..919021ff8410b 100644 --- a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementExpandedProperties.Serialization.cs +++ b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementExpandedProperties.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.Authorization.Models { @@ -256,6 +258,244 @@ internal static RoleManagementExpandedProperties DeserializeRoleManagementExpand return new RoleManagementExpandedProperties(Optional.ToNullable(id), displayName.Value, email.Value, Optional.ToNullable(type), id0.Value, displayName0.Value, Optional.ToNullable(type0), id1.Value, displayName1.Value, Optional.ToNullable(type1), 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("{"); + + builder.Append(" principal:"); + builder.AppendLine(" {"); + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(PrincipalId), out propertyOverride); + if (Optional.IsDefined(PrincipalId) || hasPropertyOverride) + { + builder.Append(" id: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{PrincipalId.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(PrincipalDisplayName), out propertyOverride); + if (Optional.IsDefined(PrincipalDisplayName) || hasPropertyOverride) + { + builder.Append(" displayName: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + if (PrincipalDisplayName.Contains(Environment.NewLine)) + { + builder.AppendLine("'''"); + builder.AppendLine($"{PrincipalDisplayName}'''"); + } + else + { + builder.AppendLine($"'{PrincipalDisplayName}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Email), out propertyOverride); + if (Optional.IsDefined(Email) || hasPropertyOverride) + { + builder.Append(" email: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + if (Email.Contains(Environment.NewLine)) + { + builder.AppendLine("'''"); + builder.AppendLine($"{Email}'''"); + } + else + { + builder.AppendLine($"'{Email}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(PrincipalType), out propertyOverride); + if (Optional.IsDefined(PrincipalType) || hasPropertyOverride) + { + builder.Append(" type: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{PrincipalType.Value.ToString()}'"); + } + } + + builder.AppendLine(" }"); + builder.Append(" roleDefinition:"); + builder.AppendLine(" {"); + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(RoleDefinitionId), out propertyOverride); + if (Optional.IsDefined(RoleDefinitionId) || hasPropertyOverride) + { + builder.Append(" id: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{RoleDefinitionId.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(RoleDefinitionDisplayName), out propertyOverride); + if (Optional.IsDefined(RoleDefinitionDisplayName) || hasPropertyOverride) + { + builder.Append(" displayName: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + if (RoleDefinitionDisplayName.Contains(Environment.NewLine)) + { + builder.AppendLine("'''"); + builder.AppendLine($"{RoleDefinitionDisplayName}'''"); + } + else + { + builder.AppendLine($"'{RoleDefinitionDisplayName}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(RoleType), out propertyOverride); + if (Optional.IsDefined(RoleType) || hasPropertyOverride) + { + builder.Append(" type: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{RoleType.Value.ToString()}'"); + } + } + + builder.AppendLine(" }"); + builder.Append(" scope:"); + builder.AppendLine(" {"); + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ScopeId), out propertyOverride); + if (Optional.IsDefined(ScopeId) || hasPropertyOverride) + { + builder.Append(" id: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{ScopeId.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ScopeDisplayName), out propertyOverride); + if (Optional.IsDefined(ScopeDisplayName) || hasPropertyOverride) + { + builder.Append(" displayName: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + if (ScopeDisplayName.Contains(Environment.NewLine)) + { + builder.AppendLine("'''"); + builder.AppendLine($"{ScopeDisplayName}'''"); + } + else + { + builder.AppendLine($"'{ScopeDisplayName}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ScopeType), out propertyOverride); + if (Optional.IsDefined(ScopeType) || hasPropertyOverride) + { + builder.Append(" type: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{ScopeType.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 formattedPropertyName) + { + string indent = new string(' ', spaces); + int emptyObjectLength = 2 + spaces + Environment.NewLine.Length + Environment.NewLine.Length; + int length = stringBuilder.Length; + bool inMultilineString = false; + + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + 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}"); + } + } + if (stringBuilder.Length == length + emptyObjectLength) + { + stringBuilder.Length = stringBuilder.Length - emptyObjectLength - formattedPropertyName.Length; + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -264,6 +504,8 @@ BinaryData IPersistableModel.Write(ModelReader { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(RoleManagementExpandedProperties)} does not support '{options.Format}' format."); } @@ -280,6 +522,8 @@ RoleManagementExpandedProperties IPersistableModel Id of the principal. + [WirePath("principal.id")] public Guid? PrincipalId { get; } /// Display name of the principal. + [WirePath("principal.displayName")] public string PrincipalDisplayName { get; } /// Email id of the principal. + [WirePath("principal.email")] public string Email { get; } /// Type of the principal. + [WirePath("principal.type")] public RoleManagementPrincipalType? PrincipalType { get; } /// Id of the role definition. + [WirePath("roleDefinition.id")] public ResourceIdentifier RoleDefinitionId { get; } /// Display name of the role definition. + [WirePath("roleDefinition.displayName")] public string RoleDefinitionDisplayName { get; } /// The role type. + [WirePath("roleDefinition.type")] public AuthorizationRoleType? RoleType { get; } /// Scope id of the resource. + [WirePath("scope.id")] public ResourceIdentifier ScopeId { get; } /// Display name of the resource. + [WirePath("scope.displayName")] public string ScopeDisplayName { get; } /// Type of the scope. + [WirePath("scope.type")] public RoleManagementScopeType? ScopeType { get; } } } diff --git a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementPolicyApprovalRule.Serialization.cs b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementPolicyApprovalRule.Serialization.cs index c721209ae1a2f..1e43b1fbe587f 100644 --- a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementPolicyApprovalRule.Serialization.cs +++ b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementPolicyApprovalRule.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.Authorization.Models { @@ -95,7 +97,7 @@ internal static RoleManagementPolicyApprovalRule DeserializeRoleManagementPolicy { continue; } - setting = RoleManagementApprovalSettings.DeserializeRoleManagementApprovalSettings(property.Value, options); + setting = RoleManagementApprovalSettings.DeserializeRoleManagementApprovalSettings(property.Value); continue; } if (property.NameEquals("id"u8)) @@ -114,7 +116,7 @@ internal static RoleManagementPolicyApprovalRule DeserializeRoleManagementPolicy { continue; } - target = RoleManagementPolicyRuleTarget.DeserializeRoleManagementPolicyRuleTarget(property.Value, options); + target = RoleManagementPolicyRuleTarget.DeserializeRoleManagementPolicyRuleTarget(property.Value); continue; } if (options.Format != "W") @@ -126,6 +128,127 @@ internal static RoleManagementPolicyApprovalRule DeserializeRoleManagementPolicy return new RoleManagementPolicyApprovalRule(id.Value, ruleType, target.Value, serializedAdditionalRawData, setting.Value); } + 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(Settings), out propertyOverride); + if (Optional.IsDefined(Settings) || hasPropertyOverride) + { + builder.Append(" setting: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + AppendChildObject(builder, Settings, options, 2, false, " setting: "); + } + } + + 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(RuleType), out propertyOverride); + if (Optional.IsDefined(RuleType) || hasPropertyOverride) + { + builder.Append(" ruleType: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{RuleType.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Target), out propertyOverride); + if (Optional.IsDefined(Target) || hasPropertyOverride) + { + builder.Append(" target: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + AppendChildObject(builder, Target, options, 2, false, " target: "); + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine, string formattedPropertyName) + { + string indent = new string(' ', spaces); + int emptyObjectLength = 2 + spaces + Environment.NewLine.Length + Environment.NewLine.Length; + int length = stringBuilder.Length; + bool inMultilineString = false; + + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + 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}"); + } + } + if (stringBuilder.Length == length + emptyObjectLength) + { + stringBuilder.Length = stringBuilder.Length - emptyObjectLength - formattedPropertyName.Length; + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -134,6 +257,8 @@ BinaryData IPersistableModel.Write(ModelReader { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(RoleManagementPolicyApprovalRule)} does not support '{options.Format}' format."); } @@ -150,6 +275,8 @@ RoleManagementPolicyApprovalRule IPersistableModel The approval setting. + [WirePath("setting")] public RoleManagementApprovalSettings Settings { get; set; } } } diff --git a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementPolicyAssignmentListResult.Serialization.cs b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementPolicyAssignmentListResult.Serialization.cs index be09c90a11eb7..f6fa9e5d3c111 100644 --- a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementPolicyAssignmentListResult.Serialization.cs +++ b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementPolicyAssignmentListResult.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.Authorization; namespace Azure.ResourceManager.Authorization.Models @@ -95,7 +98,7 @@ internal static RoleManagementPolicyAssignmentListResult DeserializeRoleManageme List array = new List(); foreach (var item in property.Value.EnumerateArray()) { - array.Add(RoleManagementPolicyAssignmentData.DeserializeRoleManagementPolicyAssignmentData(item, options)); + array.Add(RoleManagementPolicyAssignmentData.DeserializeRoleManagementPolicyAssignmentData(item)); } value = array; continue; @@ -114,6 +117,107 @@ internal static RoleManagementPolicyAssignmentListResult DeserializeRoleManageme return new RoleManagementPolicyAssignmentListResult(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, " value: "); + } + 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 formattedPropertyName) + { + string indent = new string(' ', spaces); + int emptyObjectLength = 2 + spaces + Environment.NewLine.Length + Environment.NewLine.Length; + int length = stringBuilder.Length; + bool inMultilineString = false; + + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + 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}"); + } + } + if (stringBuilder.Length == length + emptyObjectLength) + { + stringBuilder.Length = stringBuilder.Length - emptyObjectLength - formattedPropertyName.Length; + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -122,6 +226,8 @@ BinaryData IPersistableModel.Write(Mod { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(RoleManagementPolicyAssignmentListResult)} does not support '{options.Format}' format."); } @@ -138,6 +244,8 @@ RoleManagementPolicyAssignmentListResult 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(IsEnabled), out propertyOverride); + if (Optional.IsDefined(IsEnabled) || hasPropertyOverride) + { + builder.Append(" isEnabled: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + var boolValue = IsEnabled.Value == true ? "true" : "false"; + builder.AppendLine($"{boolValue}"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ClaimValue), out propertyOverride); + if (Optional.IsDefined(ClaimValue) || hasPropertyOverride) + { + builder.Append(" claimValue: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + if (ClaimValue.Contains(Environment.NewLine)) + { + builder.AppendLine("'''"); + builder.AppendLine($"{ClaimValue}'''"); + } + else + { + builder.AppendLine($"'{ClaimValue}'"); + } + } + } + + 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(RuleType), out propertyOverride); + if (Optional.IsDefined(RuleType) || hasPropertyOverride) + { + builder.Append(" ruleType: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{RuleType.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Target), out propertyOverride); + if (Optional.IsDefined(Target) || hasPropertyOverride) + { + builder.Append(" target: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + AppendChildObject(builder, Target, options, 2, false, " target: "); + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine, string formattedPropertyName) + { + string indent = new string(' ', spaces); + int emptyObjectLength = 2 + spaces + Environment.NewLine.Length + Environment.NewLine.Length; + int length = stringBuilder.Length; + bool inMultilineString = false; + + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + 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}"); + } + } + if (stringBuilder.Length == length + emptyObjectLength) + { + stringBuilder.Length = stringBuilder.Length - emptyObjectLength - formattedPropertyName.Length; + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -145,6 +291,8 @@ BinaryData IPersistableModel.Writ { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(RoleManagementPolicyAuthenticationContextRule)} does not support '{options.Format}' format."); } @@ -161,6 +309,8 @@ RoleManagementPolicyAuthenticationContextRule IPersistableModel The value indicating if rule is enabled. + [WirePath("isEnabled")] public bool? IsEnabled { get; set; } /// The claim value. + [WirePath("claimValue")] public string ClaimValue { get; set; } } } diff --git a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementPolicyEnablementRule.Serialization.cs b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementPolicyEnablementRule.Serialization.cs index acd6a04f7fcf3..1fe5bf95874d7 100644 --- a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementPolicyEnablementRule.Serialization.cs +++ b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementPolicyEnablementRule.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.Authorization.Models { @@ -124,7 +127,7 @@ internal static RoleManagementPolicyEnablementRule DeserializeRoleManagementPoli { continue; } - target = RoleManagementPolicyRuleTarget.DeserializeRoleManagementPolicyRuleTarget(property.Value, options); + target = RoleManagementPolicyRuleTarget.DeserializeRoleManagementPolicyRuleTarget(property.Value); continue; } if (options.Format != "W") @@ -136,6 +139,135 @@ internal static RoleManagementPolicyEnablementRule DeserializeRoleManagementPoli return new RoleManagementPolicyEnablementRule(id.Value, ruleType, target.Value, serializedAdditionalRawData, Optional.ToList(enabledRules)); } + 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(EnablementRules), out propertyOverride); + if (Optional.IsCollectionDefined(EnablementRules) || hasPropertyOverride) + { + if (EnablementRules.Any() || hasPropertyOverride) + { + builder.Append(" enabledRules: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine("["); + foreach (var item in EnablementRules) + { + builder.AppendLine($" '{item.ToString()}'"); + } + 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(RuleType), out propertyOverride); + if (Optional.IsDefined(RuleType) || hasPropertyOverride) + { + builder.Append(" ruleType: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{RuleType.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Target), out propertyOverride); + if (Optional.IsDefined(Target) || hasPropertyOverride) + { + builder.Append(" target: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + AppendChildObject(builder, Target, options, 2, false, " target: "); + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine, string formattedPropertyName) + { + string indent = new string(' ', spaces); + int emptyObjectLength = 2 + spaces + Environment.NewLine.Length + Environment.NewLine.Length; + int length = stringBuilder.Length; + bool inMultilineString = false; + + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + 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}"); + } + } + if (stringBuilder.Length == length + emptyObjectLength) + { + stringBuilder.Length = stringBuilder.Length - emptyObjectLength - formattedPropertyName.Length; + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -144,6 +276,8 @@ BinaryData IPersistableModel.Write(ModelRead { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(RoleManagementPolicyEnablementRule)} does not support '{options.Format}' format."); } @@ -160,6 +294,8 @@ RoleManagementPolicyEnablementRule IPersistableModel The list of enabled rules. + [WirePath("enabledRules")] public IList EnablementRules { get; } } } diff --git a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementPolicyExpirationRule.Serialization.cs b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementPolicyExpirationRule.Serialization.cs index 34812af728f67..809d2c1430696 100644 --- a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementPolicyExpirationRule.Serialization.cs +++ b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementPolicyExpirationRule.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.Authorization.Models { @@ -129,7 +131,7 @@ internal static RoleManagementPolicyExpirationRule DeserializeRoleManagementPoli { continue; } - target = RoleManagementPolicyRuleTarget.DeserializeRoleManagementPolicyRuleTarget(property.Value, options); + target = RoleManagementPolicyRuleTarget.DeserializeRoleManagementPolicyRuleTarget(property.Value); continue; } if (options.Format != "W") @@ -141,6 +143,143 @@ internal static RoleManagementPolicyExpirationRule DeserializeRoleManagementPoli return new RoleManagementPolicyExpirationRule(id.Value, ruleType, target.Value, serializedAdditionalRawData, Optional.ToNullable(isExpirationRequired), Optional.ToNullable(maximumDuration)); } + 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(IsExpirationRequired), out propertyOverride); + if (Optional.IsDefined(IsExpirationRequired) || hasPropertyOverride) + { + builder.Append(" isExpirationRequired: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + var boolValue = IsExpirationRequired.Value == true ? "true" : "false"; + builder.AppendLine($"{boolValue}"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(MaximumDuration), out propertyOverride); + if (Optional.IsDefined(MaximumDuration) || hasPropertyOverride) + { + builder.Append(" maximumDuration: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + var formattedTimeSpan = TypeFormatters.ToString(MaximumDuration.Value, "P"); + builder.AppendLine($"'{formattedTimeSpan}'"); + } + } + + 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(RuleType), out propertyOverride); + if (Optional.IsDefined(RuleType) || hasPropertyOverride) + { + builder.Append(" ruleType: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{RuleType.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Target), out propertyOverride); + if (Optional.IsDefined(Target) || hasPropertyOverride) + { + builder.Append(" target: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + AppendChildObject(builder, Target, options, 2, false, " target: "); + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine, string formattedPropertyName) + { + string indent = new string(' ', spaces); + int emptyObjectLength = 2 + spaces + Environment.NewLine.Length + Environment.NewLine.Length; + int length = stringBuilder.Length; + bool inMultilineString = false; + + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + 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}"); + } + } + if (stringBuilder.Length == length + emptyObjectLength) + { + stringBuilder.Length = stringBuilder.Length - emptyObjectLength - formattedPropertyName.Length; + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -149,6 +288,8 @@ BinaryData IPersistableModel.Write(ModelRead { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(RoleManagementPolicyExpirationRule)} does not support '{options.Format}' format."); } @@ -165,6 +306,8 @@ RoleManagementPolicyExpirationRule IPersistableModel The value indicating whether expiration is required. + [WirePath("isExpirationRequired")] public bool? IsExpirationRequired { get; set; } /// The maximum duration of expiration in timespan. + [WirePath("maximumDuration")] public TimeSpan? MaximumDuration { get; set; } } } diff --git a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementPolicyListResult.Serialization.cs b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementPolicyListResult.Serialization.cs index a27ef81039dda..ab4f01f08fd6a 100644 --- a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementPolicyListResult.Serialization.cs +++ b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementPolicyListResult.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.Authorization; namespace Azure.ResourceManager.Authorization.Models @@ -95,7 +98,7 @@ internal static RoleManagementPolicyListResult DeserializeRoleManagementPolicyLi List array = new List(); foreach (var item in property.Value.EnumerateArray()) { - array.Add(RoleManagementPolicyData.DeserializeRoleManagementPolicyData(item, options)); + array.Add(RoleManagementPolicyData.DeserializeRoleManagementPolicyData(item)); } value = array; continue; @@ -114,6 +117,107 @@ internal static RoleManagementPolicyListResult DeserializeRoleManagementPolicyLi return new RoleManagementPolicyListResult(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, " value: "); + } + 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 formattedPropertyName) + { + string indent = new string(' ', spaces); + int emptyObjectLength = 2 + spaces + Environment.NewLine.Length + Environment.NewLine.Length; + int length = stringBuilder.Length; + bool inMultilineString = false; + + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + 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}"); + } + } + if (stringBuilder.Length == length + emptyObjectLength) + { + stringBuilder.Length = stringBuilder.Length - emptyObjectLength - formattedPropertyName.Length; + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -122,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(RoleManagementPolicyListResult)} does not support '{options.Format}' format."); } @@ -138,6 +244,8 @@ RoleManagementPolicyListResult IPersistableModel using JsonDocument document = JsonDocument.Parse(data); return DeserializeRoleManagementPolicyListResult(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(RoleManagementPolicyListResult)} does not support '{options.Format}' format."); } diff --git a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementPolicyNotificationRule.Serialization.cs b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementPolicyNotificationRule.Serialization.cs index d7fc5d826f854..22c783c32db4d 100644 --- a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementPolicyNotificationRule.Serialization.cs +++ b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementPolicyNotificationRule.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.Authorization.Models { @@ -184,7 +187,7 @@ internal static RoleManagementPolicyNotificationRule DeserializeRoleManagementPo { continue; } - target = RoleManagementPolicyRuleTarget.DeserializeRoleManagementPolicyRuleTarget(property.Value, options); + target = RoleManagementPolicyRuleTarget.DeserializeRoleManagementPolicyRuleTarget(property.Value); continue; } if (options.Format != "W") @@ -196,6 +199,205 @@ internal static RoleManagementPolicyNotificationRule DeserializeRoleManagementPo return new RoleManagementPolicyNotificationRule(id.Value, ruleType, target.Value, serializedAdditionalRawData, Optional.ToNullable(notificationType), Optional.ToNullable(notificationLevel), Optional.ToNullable(recipientType), Optional.ToList(notificationRecipients), Optional.ToNullable(isDefaultRecipientsEnabled)); } + 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(NotificationDeliveryType), out propertyOverride); + if (Optional.IsDefined(NotificationDeliveryType) || hasPropertyOverride) + { + builder.Append(" notificationType: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{NotificationDeliveryType.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(NotificationLevel), out propertyOverride); + if (Optional.IsDefined(NotificationLevel) || hasPropertyOverride) + { + builder.Append(" notificationLevel: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{NotificationLevel.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(RecipientType), out propertyOverride); + if (Optional.IsDefined(RecipientType) || hasPropertyOverride) + { + builder.Append(" recipientType: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{RecipientType.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(NotificationRecipients), out propertyOverride); + if (Optional.IsCollectionDefined(NotificationRecipients) || hasPropertyOverride) + { + if (NotificationRecipients.Any() || hasPropertyOverride) + { + builder.Append(" notificationRecipients: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine("["); + foreach (var item in NotificationRecipients) + { + 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(AreDefaultRecipientsEnabled), out propertyOverride); + if (Optional.IsDefined(AreDefaultRecipientsEnabled) || hasPropertyOverride) + { + builder.Append(" isDefaultRecipientsEnabled: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + var boolValue = AreDefaultRecipientsEnabled.Value == true ? "true" : "false"; + builder.AppendLine($"{boolValue}"); + } + } + + 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(RuleType), out propertyOverride); + if (Optional.IsDefined(RuleType) || hasPropertyOverride) + { + builder.Append(" ruleType: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{RuleType.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Target), out propertyOverride); + if (Optional.IsDefined(Target) || hasPropertyOverride) + { + builder.Append(" target: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + AppendChildObject(builder, Target, options, 2, false, " target: "); + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine, string formattedPropertyName) + { + string indent = new string(' ', spaces); + int emptyObjectLength = 2 + spaces + Environment.NewLine.Length + Environment.NewLine.Length; + int length = stringBuilder.Length; + bool inMultilineString = false; + + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + 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}"); + } + } + if (stringBuilder.Length == length + emptyObjectLength) + { + stringBuilder.Length = stringBuilder.Length - emptyObjectLength - formattedPropertyName.Length; + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -204,6 +406,8 @@ BinaryData IPersistableModel.Write(ModelRe { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(RoleManagementPolicyNotificationRule)} does not support '{options.Format}' format."); } @@ -220,6 +424,8 @@ RoleManagementPolicyNotificationRule IPersistableModel The type of notification. + [WirePath("notificationType")] public NotificationDeliveryType? NotificationDeliveryType { get; set; } /// The notification level. + [WirePath("notificationLevel")] public RoleManagementPolicyNotificationLevel? NotificationLevel { get; set; } /// The recipient type. + [WirePath("recipientType")] public RoleManagementPolicyRecipientType? RecipientType { get; set; } /// The list of notification recipients. + [WirePath("notificationRecipients")] public IList NotificationRecipients { get; } /// Determines if the notification will be sent to the recipient type specified in the policy rule. + [WirePath("isDefaultRecipientsEnabled")] public bool? AreDefaultRecipientsEnabled { get; set; } } } diff --git a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementPolicyProperties.Serialization.cs b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementPolicyProperties.Serialization.cs index 0064f75a95883..4dffb331a9ce9 100644 --- a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementPolicyProperties.Serialization.cs +++ b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementPolicyProperties.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.Authorization.Models { @@ -133,6 +135,116 @@ internal static RoleManagementPolicyProperties DeserializeRoleManagementPolicyPr return new RoleManagementPolicyProperties(id.Value, displayName.Value, Optional.ToNullable(type), 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("{"); + + builder.Append(" scope:"); + builder.AppendLine(" {"); + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ScopeId), out propertyOverride); + if (Optional.IsDefined(ScopeId) || hasPropertyOverride) + { + builder.Append(" id: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{ScopeId.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ScopeDisplayName), out propertyOverride); + if (Optional.IsDefined(ScopeDisplayName) || hasPropertyOverride) + { + builder.Append(" displayName: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + if (ScopeDisplayName.Contains(Environment.NewLine)) + { + builder.AppendLine("'''"); + builder.AppendLine($"{ScopeDisplayName}'''"); + } + else + { + builder.AppendLine($"'{ScopeDisplayName}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ScopeType), out propertyOverride); + if (Optional.IsDefined(ScopeType) || hasPropertyOverride) + { + builder.Append(" type: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{ScopeType.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 formattedPropertyName) + { + string indent = new string(' ', spaces); + int emptyObjectLength = 2 + spaces + Environment.NewLine.Length + Environment.NewLine.Length; + int length = stringBuilder.Length; + bool inMultilineString = false; + + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + 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}"); + } + } + if (stringBuilder.Length == length + emptyObjectLength) + { + stringBuilder.Length = stringBuilder.Length - emptyObjectLength - formattedPropertyName.Length; + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -141,6 +253,8 @@ BinaryData IPersistableModel.Write(ModelReaderWr { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(RoleManagementPolicyProperties)} does not support '{options.Format}' format."); } @@ -157,6 +271,8 @@ RoleManagementPolicyProperties IPersistableModel using JsonDocument document = JsonDocument.Parse(data); return DeserializeRoleManagementPolicyProperties(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(RoleManagementPolicyProperties)} does not support '{options.Format}' format."); } diff --git a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementPolicyProperties.cs b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementPolicyProperties.cs index 02e1cc5b014f2..f54889eb0cec2 100644 --- a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementPolicyProperties.cs +++ b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementPolicyProperties.cs @@ -65,10 +65,13 @@ internal RoleManagementPolicyProperties(ResourceIdentifier scopeId, string scope } /// Scope id of the resource. + [WirePath("scope.id")] public ResourceIdentifier ScopeId { get; } /// Display name of the resource. + [WirePath("scope.displayName")] public string ScopeDisplayName { get; } /// Type of the scope. + [WirePath("scope.type")] public RoleManagementScopeType? ScopeType { get; } } } diff --git a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementPolicyRule.Serialization.cs b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementPolicyRule.Serialization.cs index 4710bda3f189f..89e358a4e92b8 100644 --- a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementPolicyRule.Serialization.cs +++ b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementPolicyRule.Serialization.cs @@ -7,8 +7,11 @@ 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.Authorization.Models { @@ -80,14 +83,121 @@ internal static RoleManagementPolicyRule DeserializeRoleManagementPolicyRule(Jso { switch (discriminator.GetString()) { - case "RoleManagementPolicyApprovalRule": return RoleManagementPolicyApprovalRule.DeserializeRoleManagementPolicyApprovalRule(element, options); - case "RoleManagementPolicyAuthenticationContextRule": return RoleManagementPolicyAuthenticationContextRule.DeserializeRoleManagementPolicyAuthenticationContextRule(element, options); - case "RoleManagementPolicyEnablementRule": return RoleManagementPolicyEnablementRule.DeserializeRoleManagementPolicyEnablementRule(element, options); - case "RoleManagementPolicyExpirationRule": return RoleManagementPolicyExpirationRule.DeserializeRoleManagementPolicyExpirationRule(element, options); - case "RoleManagementPolicyNotificationRule": return RoleManagementPolicyNotificationRule.DeserializeRoleManagementPolicyNotificationRule(element, options); + case "RoleManagementPolicyApprovalRule": return RoleManagementPolicyApprovalRule.DeserializeRoleManagementPolicyApprovalRule(element); + case "RoleManagementPolicyAuthenticationContextRule": return RoleManagementPolicyAuthenticationContextRule.DeserializeRoleManagementPolicyAuthenticationContextRule(element); + case "RoleManagementPolicyEnablementRule": return RoleManagementPolicyEnablementRule.DeserializeRoleManagementPolicyEnablementRule(element); + case "RoleManagementPolicyExpirationRule": return RoleManagementPolicyExpirationRule.DeserializeRoleManagementPolicyExpirationRule(element); + case "RoleManagementPolicyNotificationRule": return RoleManagementPolicyNotificationRule.DeserializeRoleManagementPolicyNotificationRule(element); } } - return UnknownRoleManagementPolicyRule.DeserializeUnknownRoleManagementPolicyRule(element, options); + return UnknownRoleManagementPolicyRule.DeserializeUnknownRoleManagementPolicyRule(element); + } + + 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(RuleType), out propertyOverride); + if (Optional.IsDefined(RuleType) || hasPropertyOverride) + { + builder.Append(" ruleType: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{RuleType.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Target), out propertyOverride); + if (Optional.IsDefined(Target) || hasPropertyOverride) + { + builder.Append(" target: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + AppendChildObject(builder, Target, options, 2, false, " target: "); + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine, string formattedPropertyName) + { + string indent = new string(' ', spaces); + int emptyObjectLength = 2 + spaces + Environment.NewLine.Length + Environment.NewLine.Length; + int length = stringBuilder.Length; + bool inMultilineString = false; + + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + 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}"); + } + } + if (stringBuilder.Length == length + emptyObjectLength) + { + stringBuilder.Length = stringBuilder.Length - emptyObjectLength - formattedPropertyName.Length; + } } BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) @@ -98,6 +208,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOp { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(RoleManagementPolicyRule)} does not support '{options.Format}' format."); } @@ -114,6 +226,8 @@ RoleManagementPolicyRule IPersistableModel.Create(Bina using JsonDocument document = JsonDocument.Parse(data); return DeserializeRoleManagementPolicyRule(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(RoleManagementPolicyRule)} does not support '{options.Format}' format."); } diff --git a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementPolicyRule.cs b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementPolicyRule.cs index b60413c9ed65e..49307706a7a71 100644 --- a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementPolicyRule.cs +++ b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementPolicyRule.cs @@ -68,10 +68,12 @@ internal RoleManagementPolicyRule(string id, RoleManagementPolicyRuleType ruleTy } /// The id of the rule. + [WirePath("id")] public string Id { get; set; } /// The type of rule. internal RoleManagementPolicyRuleType RuleType { get; set; } /// The target of the current rule. + [WirePath("target")] public RoleManagementPolicyRuleTarget Target { get; set; } } } diff --git a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementPolicyRuleTarget.Serialization.cs b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementPolicyRuleTarget.Serialization.cs index 46235d3eb9b68..2cea2478a5f95 100644 --- a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementPolicyRuleTarget.Serialization.cs +++ b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementPolicyRuleTarget.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.Authorization.Models { @@ -203,6 +206,239 @@ internal static RoleManagementPolicyRuleTarget DeserializeRoleManagementPolicyRu return new RoleManagementPolicyRuleTarget(caller.Value, Optional.ToList(operations), Optional.ToNullable(level), Optional.ToList(targetObjects), Optional.ToList(inheritableSettings), Optional.ToList(enforcedSettings), 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(Caller), out propertyOverride); + if (Optional.IsDefined(Caller) || hasPropertyOverride) + { + builder.Append(" caller: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + if (Caller.Contains(Environment.NewLine)) + { + builder.AppendLine("'''"); + builder.AppendLine($"{Caller}'''"); + } + else + { + builder.AppendLine($"'{Caller}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Operations), out propertyOverride); + if (Optional.IsCollectionDefined(Operations) || hasPropertyOverride) + { + if (Operations.Any() || hasPropertyOverride) + { + builder.Append(" operations: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine("["); + foreach (var item in Operations) + { + 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(Level), out propertyOverride); + if (Optional.IsDefined(Level) || hasPropertyOverride) + { + builder.Append(" level: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{Level.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(TargetObjects), out propertyOverride); + if (Optional.IsCollectionDefined(TargetObjects) || hasPropertyOverride) + { + if (TargetObjects.Any() || hasPropertyOverride) + { + builder.Append(" targetObjects: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine("["); + foreach (var item in TargetObjects) + { + 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(InheritableSettings), out propertyOverride); + if (Optional.IsCollectionDefined(InheritableSettings) || hasPropertyOverride) + { + if (InheritableSettings.Any() || hasPropertyOverride) + { + builder.Append(" inheritableSettings: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine("["); + foreach (var item in InheritableSettings) + { + 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(EnforcedSettings), out propertyOverride); + if (Optional.IsCollectionDefined(EnforcedSettings) || hasPropertyOverride) + { + if (EnforcedSettings.Any() || hasPropertyOverride) + { + builder.Append(" enforcedSettings: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine("["); + foreach (var item in EnforcedSettings) + { + 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 formattedPropertyName) + { + string indent = new string(' ', spaces); + int emptyObjectLength = 2 + spaces + Environment.NewLine.Length + Environment.NewLine.Length; + int length = stringBuilder.Length; + bool inMultilineString = false; + + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + 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}"); + } + } + if (stringBuilder.Length == length + emptyObjectLength) + { + stringBuilder.Length = stringBuilder.Length - emptyObjectLength - formattedPropertyName.Length; + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -211,6 +447,8 @@ BinaryData IPersistableModel.Write(ModelReaderWr { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(RoleManagementPolicyRuleTarget)} does not support '{options.Format}' format."); } @@ -227,6 +465,8 @@ RoleManagementPolicyRuleTarget IPersistableModel using JsonDocument document = JsonDocument.Parse(data); return DeserializeRoleManagementPolicyRuleTarget(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(RoleManagementPolicyRuleTarget)} does not support '{options.Format}' format."); } diff --git a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementPolicyRuleTarget.cs b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementPolicyRuleTarget.cs index 982fc6a7e870c..53b3cd3e2b6e2 100644 --- a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementPolicyRuleTarget.cs +++ b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementPolicyRuleTarget.cs @@ -75,16 +75,22 @@ internal RoleManagementPolicyRuleTarget(string caller, IList operations, } /// The caller of the setting. + [WirePath("caller")] public string Caller { get; set; } /// The type of operation. + [WirePath("operations")] public IList Operations { get; } /// The assignment level to which rule is applied. + [WirePath("level")] public RoleManagementAssignmentLevel? Level { get; set; } /// The list of target objects. + [WirePath("targetObjects")] public IList TargetObjects { get; } /// The list of inheritable settings. + [WirePath("inheritableSettings")] public IList InheritableSettings { get; } /// The list of enforced settings. + [WirePath("enforcedSettings")] public IList EnforcedSettings { get; } } } diff --git a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementPrincipal.Serialization.cs b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementPrincipal.Serialization.cs index 75fe1eddf36a0..0d95d3280781b 100644 --- a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementPrincipal.Serialization.cs +++ b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementPrincipal.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.Authorization.Models { @@ -125,6 +127,129 @@ internal static RoleManagementPrincipal DeserializeRoleManagementPrincipal(JsonE return new RoleManagementPrincipal(id.Value, displayName.Value, Optional.ToNullable(type), email.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(DisplayName), out propertyOverride); + if (Optional.IsDefined(DisplayName) || hasPropertyOverride) + { + builder.Append(" displayName: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + if (DisplayName.Contains(Environment.NewLine)) + { + builder.AppendLine("'''"); + builder.AppendLine($"{DisplayName}'''"); + } + else + { + builder.AppendLine($"'{DisplayName}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Email), out propertyOverride); + if (Optional.IsDefined(Email) || hasPropertyOverride) + { + builder.Append(" email: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + if (Email.Contains(Environment.NewLine)) + { + builder.AppendLine("'''"); + builder.AppendLine($"{Email}'''"); + } + else + { + builder.AppendLine($"'{Email}'"); + } + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine, string formattedPropertyName) + { + string indent = new string(' ', spaces); + int emptyObjectLength = 2 + spaces + Environment.NewLine.Length + Environment.NewLine.Length; + int length = stringBuilder.Length; + bool inMultilineString = false; + + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + 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}"); + } + } + if (stringBuilder.Length == length + emptyObjectLength) + { + stringBuilder.Length = stringBuilder.Length - emptyObjectLength - formattedPropertyName.Length; + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -133,6 +258,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOpt { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(RoleManagementPrincipal)} does not support '{options.Format}' format."); } @@ -149,6 +276,8 @@ RoleManagementPrincipal IPersistableModel.Create(Binary using JsonDocument document = JsonDocument.Parse(data); return DeserializeRoleManagementPrincipal(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(RoleManagementPrincipal)} does not support '{options.Format}' format."); } diff --git a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementPrincipal.cs b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementPrincipal.cs index e9d6dd8e155e5..11db5b3bfed8d 100644 --- a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementPrincipal.cs +++ b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementPrincipal.cs @@ -66,12 +66,16 @@ internal RoleManagementPrincipal(string id, string displayName, RoleManagementPr } /// The id of the principal made changes. + [WirePath("id")] public string Id { get; } /// The name of the principal made changes. + [WirePath("displayName")] public string DisplayName { get; } /// Type of the principal. + [WirePath("type")] public RoleManagementPrincipalType? PrincipalType { get; } /// Email of principal. + [WirePath("email")] public string Email { get; } } } diff --git a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementUserInfo.Serialization.cs b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementUserInfo.Serialization.cs index 06a95199807aa..bc5c2a101909a 100644 --- a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementUserInfo.Serialization.cs +++ b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementUserInfo.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.Authorization.Models { @@ -129,6 +131,136 @@ internal static RoleManagementUserInfo DeserializeRoleManagementUserInfo(JsonEle return new RoleManagementUserInfo(Optional.ToNullable(userType), Optional.ToNullable(isBackup), id.Value, description.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(UserType), out propertyOverride); + if (Optional.IsDefined(UserType) || hasPropertyOverride) + { + builder.Append(" userType: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{UserType.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(IsBackup), out propertyOverride); + if (Optional.IsDefined(IsBackup) || hasPropertyOverride) + { + builder.Append(" isBackup: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + var boolValue = IsBackup.Value == true ? "true" : "false"; + builder.AppendLine($"{boolValue}"); + } + } + + 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(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}'"); + } + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine, string formattedPropertyName) + { + string indent = new string(' ', spaces); + int emptyObjectLength = 2 + spaces + Environment.NewLine.Length + Environment.NewLine.Length; + int length = stringBuilder.Length; + bool inMultilineString = false; + + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + 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}"); + } + } + if (stringBuilder.Length == length + emptyObjectLength) + { + stringBuilder.Length = stringBuilder.Length - emptyObjectLength - formattedPropertyName.Length; + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -137,6 +269,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOpti { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(RoleManagementUserInfo)} does not support '{options.Format}' format."); } @@ -153,6 +287,8 @@ RoleManagementUserInfo IPersistableModel.Create(BinaryDa using JsonDocument document = JsonDocument.Parse(data); return DeserializeRoleManagementUserInfo(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(RoleManagementUserInfo)} does not support '{options.Format}' format."); } diff --git a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementUserInfo.cs b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementUserInfo.cs index d76c72440bea6..d6c49b292a6c1 100644 --- a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementUserInfo.cs +++ b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/RoleManagementUserInfo.cs @@ -66,12 +66,16 @@ internal RoleManagementUserInfo(RoleManagementUserType? userType, bool? isBackup } /// The type of user. + [WirePath("userType")] public RoleManagementUserType? UserType { get; set; } /// The value indicating whether the user is a backup fallback approver. + [WirePath("isBackup")] public bool? IsBackup { get; set; } /// The object id of the user. + [WirePath("id")] public string Id { get; set; } /// The description of the user. + [WirePath("description")] public string Description { get; set; } } } diff --git a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/UnknownRoleManagementPolicyRule.Serialization.cs b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/UnknownRoleManagementPolicyRule.Serialization.cs index 049a463d23d3a..5868f63b6600d 100644 --- a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/UnknownRoleManagementPolicyRule.Serialization.cs +++ b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/Models/UnknownRoleManagementPolicyRule.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.Authorization.Models { @@ -65,7 +67,7 @@ RoleManagementPolicyRule IJsonModel.Create(ref Utf8Jso } using JsonDocument document = JsonDocument.ParseValue(ref reader); - return DeserializeRoleManagementPolicyRule(document.RootElement, options); + return DeserializeUnknownRoleManagementPolicyRule(document.RootElement, options); } internal static UnknownRoleManagementPolicyRule DeserializeUnknownRoleManagementPolicyRule(JsonElement element, ModelReaderWriterOptions options = null) @@ -99,7 +101,7 @@ internal static UnknownRoleManagementPolicyRule DeserializeUnknownRoleManagement { continue; } - target = RoleManagementPolicyRuleTarget.DeserializeRoleManagementPolicyRuleTarget(property.Value, options); + target = RoleManagementPolicyRuleTarget.DeserializeRoleManagementPolicyRuleTarget(property.Value); continue; } if (options.Format != "W") @@ -111,6 +113,113 @@ internal static UnknownRoleManagementPolicyRule DeserializeUnknownRoleManagement return new UnknownRoleManagementPolicyRule(id.Value, ruleType, target.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(RuleType), out propertyOverride); + if (Optional.IsDefined(RuleType) || hasPropertyOverride) + { + builder.Append(" ruleType: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{RuleType.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Target), out propertyOverride); + if (Optional.IsDefined(Target) || hasPropertyOverride) + { + builder.Append(" target: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + AppendChildObject(builder, Target, options, 2, false, " target: "); + } + } + + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine, string formattedPropertyName) + { + string indent = new string(' ', spaces); + int emptyObjectLength = 2 + spaces + Environment.NewLine.Length + Environment.NewLine.Length; + int length = stringBuilder.Length; + bool inMultilineString = false; + + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + 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}"); + } + } + if (stringBuilder.Length == length + emptyObjectLength) + { + stringBuilder.Length = stringBuilder.Length - emptyObjectLength - formattedPropertyName.Length; + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -119,6 +228,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOp { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(RoleManagementPolicyRule)} does not support '{options.Format}' format."); } @@ -133,8 +244,10 @@ RoleManagementPolicyRule IPersistableModel.Create(Bina case "J": { using JsonDocument document = JsonDocument.Parse(data); - return DeserializeRoleManagementPolicyRule(document.RootElement, options); + return DeserializeUnknownRoleManagementPolicyRule(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(RoleManagementPolicyRule)} does not support '{options.Format}' format."); } diff --git a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/RoleAssignmentData.Serialization.cs b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/RoleAssignmentData.Serialization.cs index 659cdd12150f3..44820cbfb57a3 100644 --- a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/RoleAssignmentData.Serialization.cs +++ b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/RoleAssignmentData.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.Authorization.Models; using Azure.ResourceManager.Models; @@ -306,6 +308,334 @@ internal static RoleAssignmentData DeserializeRoleAssignmentData(JsonElement ele return new RoleAssignmentData(id, name, type, systemData.Value, scope.Value, roleDefinitionId.Value, Optional.ToNullable(principalId), Optional.ToNullable(principalType), description.Value, condition.Value, conditionVersion.Value, Optional.ToNullable(createdOn), Optional.ToNullable(updatedOn), createdBy.Value, updatedBy.Value, delegatedManagedIdentityResourceId.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(Scope), out propertyOverride); + if (Optional.IsDefined(Scope) || hasPropertyOverride) + { + builder.Append(" scope: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + if (Scope.Contains(Environment.NewLine)) + { + builder.AppendLine("'''"); + builder.AppendLine($"{Scope}'''"); + } + else + { + builder.AppendLine($"'{Scope}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(RoleDefinitionId), out propertyOverride); + if (Optional.IsDefined(RoleDefinitionId) || hasPropertyOverride) + { + builder.Append(" roleDefinitionId: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{RoleDefinitionId.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(PrincipalId), out propertyOverride); + if (Optional.IsDefined(PrincipalId) || hasPropertyOverride) + { + builder.Append(" principalId: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{PrincipalId.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(PrincipalType), out propertyOverride); + if (Optional.IsDefined(PrincipalType) || hasPropertyOverride) + { + builder.Append(" principalType: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{PrincipalType.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(Condition), out propertyOverride); + if (Optional.IsDefined(Condition) || hasPropertyOverride) + { + builder.Append(" condition: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + if (Condition.Contains(Environment.NewLine)) + { + builder.AppendLine("'''"); + builder.AppendLine($"{Condition}'''"); + } + else + { + builder.AppendLine($"'{Condition}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ConditionVersion), out propertyOverride); + if (Optional.IsDefined(ConditionVersion) || hasPropertyOverride) + { + builder.Append(" conditionVersion: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + if (ConditionVersion.Contains(Environment.NewLine)) + { + builder.AppendLine("'''"); + builder.AppendLine($"{ConditionVersion}'''"); + } + else + { + builder.AppendLine($"'{ConditionVersion}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(CreatedOn), out propertyOverride); + if (Optional.IsDefined(CreatedOn) || hasPropertyOverride) + { + builder.Append(" createdOn: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + var formattedDateTimeString = TypeFormatters.ToString(CreatedOn.Value, "o"); + builder.AppendLine($"'{formattedDateTimeString}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(UpdatedOn), out propertyOverride); + if (Optional.IsDefined(UpdatedOn) || hasPropertyOverride) + { + builder.Append(" updatedOn: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + var formattedDateTimeString = TypeFormatters.ToString(UpdatedOn.Value, "o"); + builder.AppendLine($"'{formattedDateTimeString}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(CreatedBy), out propertyOverride); + if (Optional.IsDefined(CreatedBy) || hasPropertyOverride) + { + builder.Append(" createdBy: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + if (CreatedBy.Contains(Environment.NewLine)) + { + builder.AppendLine("'''"); + builder.AppendLine($"{CreatedBy}'''"); + } + else + { + builder.AppendLine($"'{CreatedBy}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(UpdatedBy), out propertyOverride); + if (Optional.IsDefined(UpdatedBy) || hasPropertyOverride) + { + builder.Append(" updatedBy: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + if (UpdatedBy.Contains(Environment.NewLine)) + { + builder.AppendLine("'''"); + builder.AppendLine($"{UpdatedBy}'''"); + } + else + { + builder.AppendLine($"'{UpdatedBy}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(DelegatedManagedIdentityResourceId), out propertyOverride); + if (Optional.IsDefined(DelegatedManagedIdentityResourceId) || hasPropertyOverride) + { + builder.Append(" delegatedManagedIdentityResourceId: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{DelegatedManagedIdentityResourceId.ToString()}'"); + } + } + + builder.AppendLine(" }"); + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine, string formattedPropertyName) + { + string indent = new string(' ', spaces); + int emptyObjectLength = 2 + spaces + Environment.NewLine.Length + Environment.NewLine.Length; + int length = stringBuilder.Length; + bool inMultilineString = false; + + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + 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}"); + } + } + if (stringBuilder.Length == length + emptyObjectLength) + { + stringBuilder.Length = stringBuilder.Length - emptyObjectLength - formattedPropertyName.Length; + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -314,6 +644,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOptions { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(RoleAssignmentData)} does not support '{options.Format}' format."); } @@ -330,6 +662,8 @@ RoleAssignmentData IPersistableModel.Create(BinaryData data, using JsonDocument document = JsonDocument.Parse(data); return DeserializeRoleAssignmentData(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(RoleAssignmentData)} does not support '{options.Format}' format."); } diff --git a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/RoleAssignmentData.cs b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/RoleAssignmentData.cs index 2f2a9d8537762..d8ceb2df72539 100644 --- a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/RoleAssignmentData.cs +++ b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/RoleAssignmentData.cs @@ -92,28 +92,40 @@ internal RoleAssignmentData(ResourceIdentifier id, string name, ResourceType res } /// The role assignment scope. + [WirePath("properties.scope")] public string Scope { get; } /// The role definition ID. + [WirePath("properties.roleDefinitionId")] public ResourceIdentifier RoleDefinitionId { get; } /// The principal ID. + [WirePath("properties.principalId")] public Guid? PrincipalId { get; } /// The principal type of the assigned principal ID. + [WirePath("properties.principalType")] public RoleManagementPrincipalType? PrincipalType { get; } /// Description of role assignment. + [WirePath("properties.description")] public string Description { get; } /// The conditions on the role assignment. This limits the resources it can be assigned to. e.g.: @Resource[Microsoft.Storage/storageAccounts/blobServices/containers:ContainerName] StringEqualsIgnoreCase 'foo_storage_container'. + [WirePath("properties.condition")] public string Condition { get; } /// Version of the condition. Currently the only accepted value is '2.0'. + [WirePath("properties.conditionVersion")] public string ConditionVersion { get; } /// Time it was created. + [WirePath("properties.createdOn")] public DateTimeOffset? CreatedOn { get; } /// Time it was updated. + [WirePath("properties.updatedOn")] public DateTimeOffset? UpdatedOn { get; } /// Id of the user who created the assignment. + [WirePath("properties.createdBy")] public string CreatedBy { get; } /// Id of the user who updated the assignment. + [WirePath("properties.updatedBy")] public string UpdatedBy { get; } /// Id of the delegated managed identity resource. + [WirePath("properties.delegatedManagedIdentityResourceId")] public ResourceIdentifier DelegatedManagedIdentityResourceId { get; } } } diff --git a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/RoleAssignmentScheduleData.Serialization.cs b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/RoleAssignmentScheduleData.Serialization.cs index 5c7000b829f55..e25d5581bb572 100644 --- a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/RoleAssignmentScheduleData.Serialization.cs +++ b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/RoleAssignmentScheduleData.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.Authorization.Models; using Azure.ResourceManager.Models; @@ -355,7 +357,7 @@ internal static RoleAssignmentScheduleData DeserializeRoleAssignmentScheduleData { continue; } - expandedProperties = RoleManagementExpandedProperties.DeserializeRoleManagementExpandedProperties(property0.Value, options); + expandedProperties = RoleManagementExpandedProperties.DeserializeRoleManagementExpandedProperties(property0.Value); continue; } } @@ -370,6 +372,368 @@ internal static RoleAssignmentScheduleData DeserializeRoleAssignmentScheduleData return new RoleAssignmentScheduleData(id, name, type, systemData.Value, scope.Value, roleDefinitionId.Value, Optional.ToNullable(principalId), Optional.ToNullable(principalType), roleAssignmentScheduleRequestId.Value, linkedRoleEligibilityScheduleId.Value, Optional.ToNullable(assignmentType), Optional.ToNullable(memberType), Optional.ToNullable(status), Optional.ToNullable(startDateTime), Optional.ToNullable(endDateTime), condition.Value, conditionVersion.Value, Optional.ToNullable(createdOn), Optional.ToNullable(updatedOn), expandedProperties.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(Scope), out propertyOverride); + if (Optional.IsDefined(Scope) || hasPropertyOverride) + { + builder.Append(" scope: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + if (Scope.Contains(Environment.NewLine)) + { + builder.AppendLine("'''"); + builder.AppendLine($"{Scope}'''"); + } + else + { + builder.AppendLine($"'{Scope}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(RoleDefinitionId), out propertyOverride); + if (Optional.IsDefined(RoleDefinitionId) || hasPropertyOverride) + { + builder.Append(" roleDefinitionId: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{RoleDefinitionId.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(PrincipalId), out propertyOverride); + if (Optional.IsDefined(PrincipalId) || hasPropertyOverride) + { + builder.Append(" principalId: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{PrincipalId.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(PrincipalType), out propertyOverride); + if (Optional.IsDefined(PrincipalType) || hasPropertyOverride) + { + builder.Append(" principalType: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{PrincipalType.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(RoleAssignmentScheduleRequestId), out propertyOverride); + if (Optional.IsDefined(RoleAssignmentScheduleRequestId) || hasPropertyOverride) + { + builder.Append(" roleAssignmentScheduleRequestId: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{RoleAssignmentScheduleRequestId.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(LinkedRoleEligibilityScheduleId), out propertyOverride); + if (Optional.IsDefined(LinkedRoleEligibilityScheduleId) || hasPropertyOverride) + { + builder.Append(" linkedRoleEligibilityScheduleId: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{LinkedRoleEligibilityScheduleId.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(AssignmentType), out propertyOverride); + if (Optional.IsDefined(AssignmentType) || hasPropertyOverride) + { + builder.Append(" assignmentType: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{AssignmentType.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(MemberType), out propertyOverride); + if (Optional.IsDefined(MemberType) || hasPropertyOverride) + { + builder.Append(" memberType: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{MemberType.Value.ToString()}'"); + } + } + + 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(StartOn), out propertyOverride); + if (Optional.IsDefined(StartOn) || hasPropertyOverride) + { + builder.Append(" startDateTime: "); + 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(" endDateTime: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + var formattedDateTimeString = TypeFormatters.ToString(EndOn.Value, "o"); + builder.AppendLine($"'{formattedDateTimeString}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Condition), out propertyOverride); + if (Optional.IsDefined(Condition) || hasPropertyOverride) + { + builder.Append(" condition: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + if (Condition.Contains(Environment.NewLine)) + { + builder.AppendLine("'''"); + builder.AppendLine($"{Condition}'''"); + } + else + { + builder.AppendLine($"'{Condition}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ConditionVersion), out propertyOverride); + if (Optional.IsDefined(ConditionVersion) || hasPropertyOverride) + { + builder.Append(" conditionVersion: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + if (ConditionVersion.Contains(Environment.NewLine)) + { + builder.AppendLine("'''"); + builder.AppendLine($"{ConditionVersion}'''"); + } + else + { + builder.AppendLine($"'{ConditionVersion}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(CreatedOn), out propertyOverride); + if (Optional.IsDefined(CreatedOn) || hasPropertyOverride) + { + builder.Append(" createdOn: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + var formattedDateTimeString = TypeFormatters.ToString(CreatedOn.Value, "o"); + builder.AppendLine($"'{formattedDateTimeString}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(UpdatedOn), out propertyOverride); + if (Optional.IsDefined(UpdatedOn) || hasPropertyOverride) + { + builder.Append(" updatedOn: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + var formattedDateTimeString = TypeFormatters.ToString(UpdatedOn.Value, "o"); + builder.AppendLine($"'{formattedDateTimeString}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ExpandedProperties), out propertyOverride); + if (Optional.IsDefined(ExpandedProperties) || hasPropertyOverride) + { + builder.Append(" expandedProperties: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + AppendChildObject(builder, ExpandedProperties, options, 4, false, " expandedProperties: "); + } + } + + builder.AppendLine(" }"); + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine, string formattedPropertyName) + { + string indent = new string(' ', spaces); + int emptyObjectLength = 2 + spaces + Environment.NewLine.Length + Environment.NewLine.Length; + int length = stringBuilder.Length; + bool inMultilineString = false; + + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + 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}"); + } + } + if (stringBuilder.Length == length + emptyObjectLength) + { + stringBuilder.Length = stringBuilder.Length - emptyObjectLength - formattedPropertyName.Length; + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -378,6 +742,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriter { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(RoleAssignmentScheduleData)} does not support '{options.Format}' format."); } @@ -394,6 +760,8 @@ RoleAssignmentScheduleData IPersistableModel.Create( using JsonDocument document = JsonDocument.Parse(data); return DeserializeRoleAssignmentScheduleData(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(RoleAssignmentScheduleData)} does not support '{options.Format}' format."); } diff --git a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/RoleAssignmentScheduleData.cs b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/RoleAssignmentScheduleData.cs index 511eada8f0a0d..df90af33b8e1d 100644 --- a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/RoleAssignmentScheduleData.cs +++ b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/RoleAssignmentScheduleData.cs @@ -100,36 +100,52 @@ internal RoleAssignmentScheduleData(ResourceIdentifier id, string name, Resource } /// The role assignment schedule scope. + [WirePath("properties.scope")] public string Scope { get; } /// The role definition ID. + [WirePath("properties.roleDefinitionId")] public ResourceIdentifier RoleDefinitionId { get; } /// The principal ID. + [WirePath("properties.principalId")] public Guid? PrincipalId { get; } /// The principal type of the assigned principal ID. + [WirePath("properties.principalType")] public RoleManagementPrincipalType? PrincipalType { get; } /// The id of roleAssignmentScheduleRequest used to create this roleAssignmentSchedule. + [WirePath("properties.roleAssignmentScheduleRequestId")] public ResourceIdentifier RoleAssignmentScheduleRequestId { get; } /// The id of roleEligibilitySchedule used to activated this roleAssignmentSchedule. + [WirePath("properties.linkedRoleEligibilityScheduleId")] public ResourceIdentifier LinkedRoleEligibilityScheduleId { get; } /// Assignment type of the role assignment schedule. + [WirePath("properties.assignmentType")] public RoleAssignmentScheduleAssignmentType? AssignmentType { get; } /// Membership type of the role assignment schedule. + [WirePath("properties.memberType")] public RoleManagementScheduleMemberType? MemberType { get; } /// The status of the role assignment schedule. + [WirePath("properties.status")] public RoleManagementScheduleStatus? Status { get; } /// Start DateTime when role assignment schedule. + [WirePath("properties.startDateTime")] public DateTimeOffset? StartOn { get; } /// End DateTime when role assignment schedule. + [WirePath("properties.endDateTime")] public DateTimeOffset? EndOn { get; } /// The conditions on the role assignment. This limits the resources it can be assigned to. e.g.: @Resource[Microsoft.Storage/storageAccounts/blobServices/containers:ContainerName] StringEqualsIgnoreCase 'foo_storage_container'. + [WirePath("properties.condition")] public string Condition { get; } /// Version of the condition. Currently accepted value is '2.0'. + [WirePath("properties.conditionVersion")] public string ConditionVersion { get; } /// DateTime when role assignment schedule was created. + [WirePath("properties.createdOn")] public DateTimeOffset? CreatedOn { get; } /// DateTime when role assignment schedule was modified. + [WirePath("properties.updatedOn")] public DateTimeOffset? UpdatedOn { get; } /// Additional properties of principal, scope and role definition. + [WirePath("properties.expandedProperties")] public RoleManagementExpandedProperties ExpandedProperties { get; } } } diff --git a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/RoleAssignmentScheduleInstanceData.Serialization.cs b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/RoleAssignmentScheduleInstanceData.Serialization.cs index f7da4dbe495aa..598fda6d6be63 100644 --- a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/RoleAssignmentScheduleInstanceData.Serialization.cs +++ b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/RoleAssignmentScheduleInstanceData.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.Authorization.Models; using Azure.ResourceManager.Models; @@ -370,7 +372,7 @@ internal static RoleAssignmentScheduleInstanceData DeserializeRoleAssignmentSche { continue; } - expandedProperties = RoleManagementExpandedProperties.DeserializeRoleManagementExpandedProperties(property0.Value, options); + expandedProperties = RoleManagementExpandedProperties.DeserializeRoleManagementExpandedProperties(property0.Value); continue; } } @@ -385,6 +387,381 @@ internal static RoleAssignmentScheduleInstanceData DeserializeRoleAssignmentSche return new RoleAssignmentScheduleInstanceData(id, name, type, systemData.Value, scope.Value, roleDefinitionId.Value, Optional.ToNullable(principalId), Optional.ToNullable(principalType), roleAssignmentScheduleId.Value, originRoleAssignmentId.Value, Optional.ToNullable(status), Optional.ToNullable(startDateTime), Optional.ToNullable(endDateTime), linkedRoleEligibilityScheduleId.Value, linkedRoleEligibilityScheduleInstanceId.Value, Optional.ToNullable(assignmentType), Optional.ToNullable(memberType), condition.Value, conditionVersion.Value, Optional.ToNullable(createdOn), expandedProperties.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(Scope), out propertyOverride); + if (Optional.IsDefined(Scope) || hasPropertyOverride) + { + builder.Append(" scope: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + if (Scope.Contains(Environment.NewLine)) + { + builder.AppendLine("'''"); + builder.AppendLine($"{Scope}'''"); + } + else + { + builder.AppendLine($"'{Scope}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(RoleDefinitionId), out propertyOverride); + if (Optional.IsDefined(RoleDefinitionId) || hasPropertyOverride) + { + builder.Append(" roleDefinitionId: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{RoleDefinitionId.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(PrincipalId), out propertyOverride); + if (Optional.IsDefined(PrincipalId) || hasPropertyOverride) + { + builder.Append(" principalId: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{PrincipalId.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(PrincipalType), out propertyOverride); + if (Optional.IsDefined(PrincipalType) || hasPropertyOverride) + { + builder.Append(" principalType: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{PrincipalType.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(RoleAssignmentScheduleId), out propertyOverride); + if (Optional.IsDefined(RoleAssignmentScheduleId) || hasPropertyOverride) + { + builder.Append(" roleAssignmentScheduleId: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{RoleAssignmentScheduleId.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(OriginRoleAssignmentId), out propertyOverride); + if (Optional.IsDefined(OriginRoleAssignmentId) || hasPropertyOverride) + { + builder.Append(" originRoleAssignmentId: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{OriginRoleAssignmentId.ToString()}'"); + } + } + + 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(StartOn), out propertyOverride); + if (Optional.IsDefined(StartOn) || hasPropertyOverride) + { + builder.Append(" startDateTime: "); + 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(" endDateTime: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + var formattedDateTimeString = TypeFormatters.ToString(EndOn.Value, "o"); + builder.AppendLine($"'{formattedDateTimeString}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(LinkedRoleEligibilityScheduleId), out propertyOverride); + if (Optional.IsDefined(LinkedRoleEligibilityScheduleId) || hasPropertyOverride) + { + builder.Append(" linkedRoleEligibilityScheduleId: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{LinkedRoleEligibilityScheduleId.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(LinkedRoleEligibilityScheduleInstanceId), out propertyOverride); + if (Optional.IsDefined(LinkedRoleEligibilityScheduleInstanceId) || hasPropertyOverride) + { + builder.Append(" linkedRoleEligibilityScheduleInstanceId: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{LinkedRoleEligibilityScheduleInstanceId.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(AssignmentType), out propertyOverride); + if (Optional.IsDefined(AssignmentType) || hasPropertyOverride) + { + builder.Append(" assignmentType: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{AssignmentType.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(MemberType), out propertyOverride); + if (Optional.IsDefined(MemberType) || hasPropertyOverride) + { + builder.Append(" memberType: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{MemberType.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Condition), out propertyOverride); + if (Optional.IsDefined(Condition) || hasPropertyOverride) + { + builder.Append(" condition: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + if (Condition.Contains(Environment.NewLine)) + { + builder.AppendLine("'''"); + builder.AppendLine($"{Condition}'''"); + } + else + { + builder.AppendLine($"'{Condition}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ConditionVersion), out propertyOverride); + if (Optional.IsDefined(ConditionVersion) || hasPropertyOverride) + { + builder.Append(" conditionVersion: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + if (ConditionVersion.Contains(Environment.NewLine)) + { + builder.AppendLine("'''"); + builder.AppendLine($"{ConditionVersion}'''"); + } + else + { + builder.AppendLine($"'{ConditionVersion}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(CreatedOn), out propertyOverride); + if (Optional.IsDefined(CreatedOn) || hasPropertyOverride) + { + builder.Append(" createdOn: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + var formattedDateTimeString = TypeFormatters.ToString(CreatedOn.Value, "o"); + builder.AppendLine($"'{formattedDateTimeString}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ExpandedProperties), out propertyOverride); + if (Optional.IsDefined(ExpandedProperties) || hasPropertyOverride) + { + builder.Append(" expandedProperties: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + AppendChildObject(builder, ExpandedProperties, options, 4, false, " expandedProperties: "); + } + } + + builder.AppendLine(" }"); + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine, string formattedPropertyName) + { + string indent = new string(' ', spaces); + int emptyObjectLength = 2 + spaces + Environment.NewLine.Length + Environment.NewLine.Length; + int length = stringBuilder.Length; + bool inMultilineString = false; + + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + 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}"); + } + } + if (stringBuilder.Length == length + emptyObjectLength) + { + stringBuilder.Length = stringBuilder.Length - emptyObjectLength - formattedPropertyName.Length; + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -393,6 +770,8 @@ BinaryData IPersistableModel.Write(ModelRead { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(RoleAssignmentScheduleInstanceData)} does not support '{options.Format}' format."); } @@ -409,6 +788,8 @@ RoleAssignmentScheduleInstanceData IPersistableModel The role assignment schedule scope. + [WirePath("properties.scope")] public string Scope { get; } /// The role definition ID. + [WirePath("properties.roleDefinitionId")] public ResourceIdentifier RoleDefinitionId { get; } /// The principal ID. + [WirePath("properties.principalId")] public Guid? PrincipalId { get; } /// The principal type of the assigned principal ID. + [WirePath("properties.principalType")] public RoleManagementPrincipalType? PrincipalType { get; } /// Id of the master role assignment schedule. + [WirePath("properties.roleAssignmentScheduleId")] public ResourceIdentifier RoleAssignmentScheduleId { get; } /// Role Assignment Id in external system. + [WirePath("properties.originRoleAssignmentId")] public ResourceIdentifier OriginRoleAssignmentId { get; } /// The status of the role assignment schedule instance. + [WirePath("properties.status")] public RoleManagementScheduleStatus? Status { get; } /// The startDateTime of the role assignment schedule instance. + [WirePath("properties.startDateTime")] public DateTimeOffset? StartOn { get; } /// The endDateTime of the role assignment schedule instance. + [WirePath("properties.endDateTime")] public DateTimeOffset? EndOn { get; } /// roleEligibilityScheduleId used to activate. + [WirePath("properties.linkedRoleEligibilityScheduleId")] public ResourceIdentifier LinkedRoleEligibilityScheduleId { get; } /// roleEligibilityScheduleInstanceId linked to this roleAssignmentScheduleInstance. + [WirePath("properties.linkedRoleEligibilityScheduleInstanceId")] public ResourceIdentifier LinkedRoleEligibilityScheduleInstanceId { get; } /// Assignment type of the role assignment schedule. + [WirePath("properties.assignmentType")] public RoleAssignmentScheduleAssignmentType? AssignmentType { get; } /// Membership type of the role assignment schedule. + [WirePath("properties.memberType")] public RoleManagementScheduleMemberType? MemberType { get; } /// The conditions on the role assignment. This limits the resources it can be assigned to. e.g.: @Resource[Microsoft.Storage/storageAccounts/blobServices/containers:ContainerName] StringEqualsIgnoreCase 'foo_storage_container'. + [WirePath("properties.condition")] public string Condition { get; } /// Version of the condition. Currently accepted value is '2.0'. + [WirePath("properties.conditionVersion")] public string ConditionVersion { get; } /// DateTime when role assignment schedule was created. + [WirePath("properties.createdOn")] public DateTimeOffset? CreatedOn { get; } /// Additional properties of principal, scope and role definition. + [WirePath("properties.expandedProperties")] public RoleManagementExpandedProperties ExpandedProperties { get; } } } diff --git a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/RoleAssignmentScheduleRequestData.Serialization.cs b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/RoleAssignmentScheduleRequestData.Serialization.cs index 086ab3912bd8c..4ec4cb9e3805b 100644 --- a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/RoleAssignmentScheduleRequestData.Serialization.cs +++ b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/RoleAssignmentScheduleRequestData.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.Authorization.Models; using Azure.ResourceManager.Models; @@ -355,7 +357,7 @@ internal static RoleAssignmentScheduleRequestData DeserializeRoleAssignmentSched { continue; } - ticketInfo = RoleAssignmentScheduleTicketInfo.DeserializeRoleAssignmentScheduleTicketInfo(property0.Value, options); + ticketInfo = RoleAssignmentScheduleTicketInfo.DeserializeRoleAssignmentScheduleTicketInfo(property0.Value); continue; } if (property0.NameEquals("condition"u8)) @@ -392,7 +394,7 @@ internal static RoleAssignmentScheduleRequestData DeserializeRoleAssignmentSched { continue; } - expandedProperties = RoleManagementExpandedProperties.DeserializeRoleManagementExpandedProperties(property0.Value, options); + expandedProperties = RoleManagementExpandedProperties.DeserializeRoleManagementExpandedProperties(property0.Value); continue; } if (property0.NameEquals("scheduleInfo"u8)) @@ -467,6 +469,460 @@ internal static RoleAssignmentScheduleRequestData DeserializeRoleAssignmentSched return new RoleAssignmentScheduleRequestData(id, name, type, systemData.Value, scope.Value, roleDefinitionId.Value, Optional.ToNullable(principalId), Optional.ToNullable(principalType), Optional.ToNullable(requestType), Optional.ToNullable(status), approvalId.Value, targetRoleAssignmentScheduleId.Value, targetRoleAssignmentScheduleInstanceId.Value, linkedRoleEligibilityScheduleId.Value, justification.Value, ticketInfo.Value, condition.Value, conditionVersion.Value, Optional.ToNullable(createdOn), Optional.ToNullable(requestorId), expandedProperties.Value, Optional.ToNullable(startDateTime), Optional.ToNullable(type0), Optional.ToNullable(endDateTime), Optional.ToNullable(duration), 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(Scope), out propertyOverride); + if (Optional.IsDefined(Scope) || hasPropertyOverride) + { + builder.Append(" scope: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + if (Scope.Contains(Environment.NewLine)) + { + builder.AppendLine("'''"); + builder.AppendLine($"{Scope}'''"); + } + else + { + builder.AppendLine($"'{Scope}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(RoleDefinitionId), out propertyOverride); + if (Optional.IsDefined(RoleDefinitionId) || hasPropertyOverride) + { + builder.Append(" roleDefinitionId: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{RoleDefinitionId.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(PrincipalId), out propertyOverride); + if (Optional.IsDefined(PrincipalId) || hasPropertyOverride) + { + builder.Append(" principalId: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{PrincipalId.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(PrincipalType), out propertyOverride); + if (Optional.IsDefined(PrincipalType) || hasPropertyOverride) + { + builder.Append(" principalType: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{PrincipalType.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(RequestType), out propertyOverride); + if (Optional.IsDefined(RequestType) || hasPropertyOverride) + { + builder.Append(" requestType: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{RequestType.Value.ToString()}'"); + } + } + + 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(ApprovalId), out propertyOverride); + if (Optional.IsDefined(ApprovalId) || hasPropertyOverride) + { + builder.Append(" approvalId: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + if (ApprovalId.Contains(Environment.NewLine)) + { + builder.AppendLine("'''"); + builder.AppendLine($"{ApprovalId}'''"); + } + else + { + builder.AppendLine($"'{ApprovalId}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(TargetRoleAssignmentScheduleId), out propertyOverride); + if (Optional.IsDefined(TargetRoleAssignmentScheduleId) || hasPropertyOverride) + { + builder.Append(" targetRoleAssignmentScheduleId: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{TargetRoleAssignmentScheduleId.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(TargetRoleAssignmentScheduleInstanceId), out propertyOverride); + if (Optional.IsDefined(TargetRoleAssignmentScheduleInstanceId) || hasPropertyOverride) + { + builder.Append(" targetRoleAssignmentScheduleInstanceId: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{TargetRoleAssignmentScheduleInstanceId.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(LinkedRoleEligibilityScheduleId), out propertyOverride); + if (Optional.IsDefined(LinkedRoleEligibilityScheduleId) || hasPropertyOverride) + { + builder.Append(" linkedRoleEligibilityScheduleId: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{LinkedRoleEligibilityScheduleId.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Justification), out propertyOverride); + if (Optional.IsDefined(Justification) || hasPropertyOverride) + { + builder.Append(" justification: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + if (Justification.Contains(Environment.NewLine)) + { + builder.AppendLine("'''"); + builder.AppendLine($"{Justification}'''"); + } + else + { + builder.AppendLine($"'{Justification}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(TicketInfo), out propertyOverride); + if (Optional.IsDefined(TicketInfo) || hasPropertyOverride) + { + builder.Append(" ticketInfo: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + AppendChildObject(builder, TicketInfo, options, 4, false, " ticketInfo: "); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Condition), out propertyOverride); + if (Optional.IsDefined(Condition) || hasPropertyOverride) + { + builder.Append(" condition: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + if (Condition.Contains(Environment.NewLine)) + { + builder.AppendLine("'''"); + builder.AppendLine($"{Condition}'''"); + } + else + { + builder.AppendLine($"'{Condition}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ConditionVersion), out propertyOverride); + if (Optional.IsDefined(ConditionVersion) || hasPropertyOverride) + { + builder.Append(" conditionVersion: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + if (ConditionVersion.Contains(Environment.NewLine)) + { + builder.AppendLine("'''"); + builder.AppendLine($"{ConditionVersion}'''"); + } + else + { + builder.AppendLine($"'{ConditionVersion}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(CreatedOn), out propertyOverride); + if (Optional.IsDefined(CreatedOn) || hasPropertyOverride) + { + builder.Append(" createdOn: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + var formattedDateTimeString = TypeFormatters.ToString(CreatedOn.Value, "o"); + builder.AppendLine($"'{formattedDateTimeString}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(RequestorId), out propertyOverride); + if (Optional.IsDefined(RequestorId) || hasPropertyOverride) + { + builder.Append(" requestorId: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{RequestorId.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ExpandedProperties), out propertyOverride); + if (Optional.IsDefined(ExpandedProperties) || hasPropertyOverride) + { + builder.Append(" expandedProperties: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + AppendChildObject(builder, ExpandedProperties, options, 4, false, " expandedProperties: "); + } + } + + builder.Append(" scheduleInfo:"); + builder.AppendLine(" {"); + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(StartOn), out propertyOverride); + if (Optional.IsDefined(StartOn) || hasPropertyOverride) + { + builder.Append(" startDateTime: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + var formattedDateTimeString = TypeFormatters.ToString(StartOn.Value, "o"); + builder.AppendLine($"'{formattedDateTimeString}'"); + } + } + + builder.Append(" expiration:"); + builder.AppendLine(" {"); + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ExpirationType), out propertyOverride); + if (Optional.IsDefined(ExpirationType) || hasPropertyOverride) + { + builder.Append(" type: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{ExpirationType.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(EndOn), out propertyOverride); + if (Optional.IsDefined(EndOn) || hasPropertyOverride) + { + builder.Append(" endDateTime: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + var formattedDateTimeString = TypeFormatters.ToString(EndOn.Value, "o"); + builder.AppendLine($"'{formattedDateTimeString}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Duration), out propertyOverride); + if (Optional.IsDefined(Duration) || hasPropertyOverride) + { + builder.Append(" duration: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + var formattedTimeSpan = TypeFormatters.ToString(Duration.Value, "P"); + builder.AppendLine($"'{formattedTimeSpan}'"); + } + } + + builder.AppendLine(" }"); + 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 formattedPropertyName) + { + string indent = new string(' ', spaces); + int emptyObjectLength = 2 + spaces + Environment.NewLine.Length + Environment.NewLine.Length; + int length = stringBuilder.Length; + bool inMultilineString = false; + + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + 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}"); + } + } + if (stringBuilder.Length == length + emptyObjectLength) + { + stringBuilder.Length = stringBuilder.Length - emptyObjectLength - formattedPropertyName.Length; + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -475,6 +931,8 @@ BinaryData IPersistableModel.Write(ModelReade { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(RoleAssignmentScheduleRequestData)} does not support '{options.Format}' format."); } @@ -491,6 +949,8 @@ RoleAssignmentScheduleRequestData IPersistableModel The role assignment schedule request scope. + [WirePath("properties.scope")] public string Scope { get; } /// The role definition ID. + [WirePath("properties.roleDefinitionId")] public ResourceIdentifier RoleDefinitionId { get; set; } /// The principal ID. + [WirePath("properties.principalId")] public Guid? PrincipalId { get; set; } /// The principal type of the assigned principal ID. + [WirePath("properties.principalType")] public RoleManagementPrincipalType? PrincipalType { get; } /// The type of the role assignment schedule request. Eg: SelfActivate, AdminAssign etc. + [WirePath("properties.requestType")] public RoleManagementScheduleRequestType? RequestType { get; set; } /// The status of the role assignment schedule request. + [WirePath("properties.status")] public RoleManagementScheduleStatus? Status { get; } /// The approvalId of the role assignment schedule request. + [WirePath("properties.approvalId")] public string ApprovalId { get; } /// The resultant role assignment schedule id or the role assignment schedule id being updated. + [WirePath("properties.targetRoleAssignmentScheduleId")] public ResourceIdentifier TargetRoleAssignmentScheduleId { get; set; } /// The role assignment schedule instance id being updated. + [WirePath("properties.targetRoleAssignmentScheduleInstanceId")] public ResourceIdentifier TargetRoleAssignmentScheduleInstanceId { get; set; } /// The linked role eligibility schedule id - to activate an eligibility. + [WirePath("properties.linkedRoleEligibilityScheduleId")] public ResourceIdentifier LinkedRoleEligibilityScheduleId { get; set; } /// Justification for the role assignment. + [WirePath("properties.justification")] public string Justification { get; set; } /// Ticket Info of the role assignment. + [WirePath("properties.ticketInfo")] public RoleAssignmentScheduleTicketInfo TicketInfo { get; set; } /// The conditions on the role assignment. This limits the resources it can be assigned to. e.g.: @Resource[Microsoft.Storage/storageAccounts/blobServices/containers:ContainerName] StringEqualsIgnoreCase 'foo_storage_container'. + [WirePath("properties.condition")] public string Condition { get; set; } /// Version of the condition. Currently accepted value is '2.0'. + [WirePath("properties.conditionVersion")] public string ConditionVersion { get; set; } /// DateTime when role assignment schedule request was created. + [WirePath("properties.createdOn")] public DateTimeOffset? CreatedOn { get; } /// Id of the user who created this request. + [WirePath("properties.requestorId")] public Guid? RequestorId { get; } /// Additional properties of principal, scope and role definition. + [WirePath("properties.expandedProperties")] public RoleManagementExpandedProperties ExpandedProperties { get; } /// Start DateTime of the role assignment schedule. + [WirePath("properties.startDateTime")] public DateTimeOffset? StartOn { get; set; } /// Type of the role assignment schedule expiration. + [WirePath("properties.type")] public RoleManagementScheduleExpirationType? ExpirationType { get; set; } /// End DateTime of the role assignment schedule. + [WirePath("properties.endDateTime")] public DateTimeOffset? EndOn { get; set; } /// Duration of the role assignment schedule in TimeSpan. + [WirePath("properties.duration")] public TimeSpan? Duration { get; set; } } } diff --git a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/RoleEligibilityScheduleData.Serialization.cs b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/RoleEligibilityScheduleData.Serialization.cs index 0a90b563b3365..69012ef002f49 100644 --- a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/RoleEligibilityScheduleData.Serialization.cs +++ b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/RoleEligibilityScheduleData.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.Authorization.Models; using Azure.ResourceManager.Models; @@ -325,7 +327,7 @@ internal static RoleEligibilityScheduleData DeserializeRoleEligibilityScheduleDa { continue; } - expandedProperties = RoleManagementExpandedProperties.DeserializeRoleManagementExpandedProperties(property0.Value, options); + expandedProperties = RoleManagementExpandedProperties.DeserializeRoleManagementExpandedProperties(property0.Value); continue; } } @@ -340,6 +342,340 @@ internal static RoleEligibilityScheduleData DeserializeRoleEligibilityScheduleDa return new RoleEligibilityScheduleData(id, name, type, systemData.Value, scope.Value, roleDefinitionId.Value, Optional.ToNullable(principalId), Optional.ToNullable(principalType), roleEligibilityScheduleRequestId.Value, Optional.ToNullable(memberType), Optional.ToNullable(status), Optional.ToNullable(startDateTime), Optional.ToNullable(endDateTime), condition.Value, conditionVersion.Value, Optional.ToNullable(createdOn), Optional.ToNullable(updatedOn), expandedProperties.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(Scope), out propertyOverride); + if (Optional.IsDefined(Scope) || hasPropertyOverride) + { + builder.Append(" scope: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + if (Scope.Contains(Environment.NewLine)) + { + builder.AppendLine("'''"); + builder.AppendLine($"{Scope}'''"); + } + else + { + builder.AppendLine($"'{Scope}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(RoleDefinitionId), out propertyOverride); + if (Optional.IsDefined(RoleDefinitionId) || hasPropertyOverride) + { + builder.Append(" roleDefinitionId: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{RoleDefinitionId.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(PrincipalId), out propertyOverride); + if (Optional.IsDefined(PrincipalId) || hasPropertyOverride) + { + builder.Append(" principalId: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{PrincipalId.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(PrincipalType), out propertyOverride); + if (Optional.IsDefined(PrincipalType) || hasPropertyOverride) + { + builder.Append(" principalType: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{PrincipalType.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(RoleEligibilityScheduleRequestId), out propertyOverride); + if (Optional.IsDefined(RoleEligibilityScheduleRequestId) || hasPropertyOverride) + { + builder.Append(" roleEligibilityScheduleRequestId: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{RoleEligibilityScheduleRequestId.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(MemberType), out propertyOverride); + if (Optional.IsDefined(MemberType) || hasPropertyOverride) + { + builder.Append(" memberType: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{MemberType.Value.ToString()}'"); + } + } + + 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(StartOn), out propertyOverride); + if (Optional.IsDefined(StartOn) || hasPropertyOverride) + { + builder.Append(" startDateTime: "); + 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(" endDateTime: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + var formattedDateTimeString = TypeFormatters.ToString(EndOn.Value, "o"); + builder.AppendLine($"'{formattedDateTimeString}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Condition), out propertyOverride); + if (Optional.IsDefined(Condition) || hasPropertyOverride) + { + builder.Append(" condition: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + if (Condition.Contains(Environment.NewLine)) + { + builder.AppendLine("'''"); + builder.AppendLine($"{Condition}'''"); + } + else + { + builder.AppendLine($"'{Condition}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ConditionVersion), out propertyOverride); + if (Optional.IsDefined(ConditionVersion) || hasPropertyOverride) + { + builder.Append(" conditionVersion: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + if (ConditionVersion.Contains(Environment.NewLine)) + { + builder.AppendLine("'''"); + builder.AppendLine($"{ConditionVersion}'''"); + } + else + { + builder.AppendLine($"'{ConditionVersion}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(CreatedOn), out propertyOverride); + if (Optional.IsDefined(CreatedOn) || hasPropertyOverride) + { + builder.Append(" createdOn: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + var formattedDateTimeString = TypeFormatters.ToString(CreatedOn.Value, "o"); + builder.AppendLine($"'{formattedDateTimeString}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(UpdatedOn), out propertyOverride); + if (Optional.IsDefined(UpdatedOn) || hasPropertyOverride) + { + builder.Append(" updatedOn: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + var formattedDateTimeString = TypeFormatters.ToString(UpdatedOn.Value, "o"); + builder.AppendLine($"'{formattedDateTimeString}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ExpandedProperties), out propertyOverride); + if (Optional.IsDefined(ExpandedProperties) || hasPropertyOverride) + { + builder.Append(" expandedProperties: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + AppendChildObject(builder, ExpandedProperties, options, 4, false, " expandedProperties: "); + } + } + + builder.AppendLine(" }"); + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine, string formattedPropertyName) + { + string indent = new string(' ', spaces); + int emptyObjectLength = 2 + spaces + Environment.NewLine.Length + Environment.NewLine.Length; + int length = stringBuilder.Length; + bool inMultilineString = false; + + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + 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}"); + } + } + if (stringBuilder.Length == length + emptyObjectLength) + { + stringBuilder.Length = stringBuilder.Length - emptyObjectLength - formattedPropertyName.Length; + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -348,6 +684,8 @@ BinaryData IPersistableModel.Write(ModelReaderWrite { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(RoleEligibilityScheduleData)} does not support '{options.Format}' format."); } @@ -364,6 +702,8 @@ RoleEligibilityScheduleData IPersistableModel.Creat using JsonDocument document = JsonDocument.Parse(data); return DeserializeRoleEligibilityScheduleData(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(RoleEligibilityScheduleData)} does not support '{options.Format}' format."); } diff --git a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/RoleEligibilityScheduleData.cs b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/RoleEligibilityScheduleData.cs index 09bf6d2f46803..b70eae85b0677 100644 --- a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/RoleEligibilityScheduleData.cs +++ b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/RoleEligibilityScheduleData.cs @@ -96,32 +96,46 @@ internal RoleEligibilityScheduleData(ResourceIdentifier id, string name, Resourc } /// The role eligibility schedule scope. + [WirePath("properties.scope")] public string Scope { get; } /// The role definition ID. + [WirePath("properties.roleDefinitionId")] public ResourceIdentifier RoleDefinitionId { get; } /// The principal ID. + [WirePath("properties.principalId")] public Guid? PrincipalId { get; } /// The principal type of the assigned principal ID. + [WirePath("properties.principalType")] public RoleManagementPrincipalType? PrincipalType { get; } /// The id of roleEligibilityScheduleRequest used to create this roleAssignmentSchedule. + [WirePath("properties.roleEligibilityScheduleRequestId")] public ResourceIdentifier RoleEligibilityScheduleRequestId { get; } /// Membership type of the role eligibility schedule. + [WirePath("properties.memberType")] public RoleManagementScheduleMemberType? MemberType { get; } /// The status of the role eligibility schedule. + [WirePath("properties.status")] public RoleManagementScheduleStatus? Status { get; } /// Start DateTime when role eligibility schedule. + [WirePath("properties.startDateTime")] public DateTimeOffset? StartOn { get; } /// End DateTime when role eligibility schedule. + [WirePath("properties.endDateTime")] public DateTimeOffset? EndOn { get; } /// The conditions on the role assignment. This limits the resources it can be assigned to. e.g.: @Resource[Microsoft.Storage/storageAccounts/blobServices/containers:ContainerName] StringEqualsIgnoreCase 'foo_storage_container'. + [WirePath("properties.condition")] public string Condition { get; } /// Version of the condition. Currently accepted value is '2.0'. + [WirePath("properties.conditionVersion")] public string ConditionVersion { get; } /// DateTime when role eligibility schedule was created. + [WirePath("properties.createdOn")] public DateTimeOffset? CreatedOn { get; } /// DateTime when role eligibility schedule was modified. + [WirePath("properties.updatedOn")] public DateTimeOffset? UpdatedOn { get; } /// Additional properties of principal, scope and role definition. + [WirePath("properties.expandedProperties")] public RoleManagementExpandedProperties ExpandedProperties { get; } } } diff --git a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/RoleEligibilityScheduleInstanceData.Serialization.cs b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/RoleEligibilityScheduleInstanceData.Serialization.cs index 0a3c903f70947..45a0c66e451ed 100644 --- a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/RoleEligibilityScheduleInstanceData.Serialization.cs +++ b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/RoleEligibilityScheduleInstanceData.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.Authorization.Models; using Azure.ResourceManager.Models; @@ -310,7 +312,7 @@ internal static RoleEligibilityScheduleInstanceData DeserializeRoleEligibilitySc { continue; } - expandedProperties = RoleManagementExpandedProperties.DeserializeRoleManagementExpandedProperties(property0.Value, options); + expandedProperties = RoleManagementExpandedProperties.DeserializeRoleManagementExpandedProperties(property0.Value); continue; } } @@ -325,6 +327,325 @@ internal static RoleEligibilityScheduleInstanceData DeserializeRoleEligibilitySc return new RoleEligibilityScheduleInstanceData(id, name, type, systemData.Value, scope.Value, roleDefinitionId.Value, Optional.ToNullable(principalId), Optional.ToNullable(principalType), roleEligibilityScheduleId.Value, Optional.ToNullable(status), Optional.ToNullable(startDateTime), Optional.ToNullable(endDateTime), Optional.ToNullable(memberType), condition.Value, conditionVersion.Value, Optional.ToNullable(createdOn), expandedProperties.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(Scope), out propertyOverride); + if (Optional.IsDefined(Scope) || hasPropertyOverride) + { + builder.Append(" scope: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + if (Scope.Contains(Environment.NewLine)) + { + builder.AppendLine("'''"); + builder.AppendLine($"{Scope}'''"); + } + else + { + builder.AppendLine($"'{Scope}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(RoleDefinitionId), out propertyOverride); + if (Optional.IsDefined(RoleDefinitionId) || hasPropertyOverride) + { + builder.Append(" roleDefinitionId: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{RoleDefinitionId.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(PrincipalId), out propertyOverride); + if (Optional.IsDefined(PrincipalId) || hasPropertyOverride) + { + builder.Append(" principalId: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{PrincipalId.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(PrincipalType), out propertyOverride); + if (Optional.IsDefined(PrincipalType) || hasPropertyOverride) + { + builder.Append(" principalType: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{PrincipalType.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(RoleEligibilityScheduleId), out propertyOverride); + if (Optional.IsDefined(RoleEligibilityScheduleId) || hasPropertyOverride) + { + builder.Append(" roleEligibilityScheduleId: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{RoleEligibilityScheduleId.ToString()}'"); + } + } + + 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(StartOn), out propertyOverride); + if (Optional.IsDefined(StartOn) || hasPropertyOverride) + { + builder.Append(" startDateTime: "); + 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(" endDateTime: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + var formattedDateTimeString = TypeFormatters.ToString(EndOn.Value, "o"); + builder.AppendLine($"'{formattedDateTimeString}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(MemberType), out propertyOverride); + if (Optional.IsDefined(MemberType) || hasPropertyOverride) + { + builder.Append(" memberType: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{MemberType.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Condition), out propertyOverride); + if (Optional.IsDefined(Condition) || hasPropertyOverride) + { + builder.Append(" condition: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + if (Condition.Contains(Environment.NewLine)) + { + builder.AppendLine("'''"); + builder.AppendLine($"{Condition}'''"); + } + else + { + builder.AppendLine($"'{Condition}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ConditionVersion), out propertyOverride); + if (Optional.IsDefined(ConditionVersion) || hasPropertyOverride) + { + builder.Append(" conditionVersion: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + if (ConditionVersion.Contains(Environment.NewLine)) + { + builder.AppendLine("'''"); + builder.AppendLine($"{ConditionVersion}'''"); + } + else + { + builder.AppendLine($"'{ConditionVersion}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(CreatedOn), out propertyOverride); + if (Optional.IsDefined(CreatedOn) || hasPropertyOverride) + { + builder.Append(" createdOn: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + var formattedDateTimeString = TypeFormatters.ToString(CreatedOn.Value, "o"); + builder.AppendLine($"'{formattedDateTimeString}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ExpandedProperties), out propertyOverride); + if (Optional.IsDefined(ExpandedProperties) || hasPropertyOverride) + { + builder.Append(" expandedProperties: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + AppendChildObject(builder, ExpandedProperties, options, 4, false, " expandedProperties: "); + } + } + + builder.AppendLine(" }"); + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine, string formattedPropertyName) + { + string indent = new string(' ', spaces); + int emptyObjectLength = 2 + spaces + Environment.NewLine.Length + Environment.NewLine.Length; + int length = stringBuilder.Length; + bool inMultilineString = false; + + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + 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}"); + } + } + if (stringBuilder.Length == length + emptyObjectLength) + { + stringBuilder.Length = stringBuilder.Length - emptyObjectLength - formattedPropertyName.Length; + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -333,6 +654,8 @@ BinaryData IPersistableModel.Write(ModelRea { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(RoleEligibilityScheduleInstanceData)} does not support '{options.Format}' format."); } @@ -349,6 +672,8 @@ RoleEligibilityScheduleInstanceData IPersistableModel The role eligibility schedule scope. + [WirePath("properties.scope")] public string Scope { get; } /// The role definition ID. + [WirePath("properties.roleDefinitionId")] public ResourceIdentifier RoleDefinitionId { get; } /// The principal ID. + [WirePath("properties.principalId")] public Guid? PrincipalId { get; } /// The principal type of the assigned principal ID. + [WirePath("properties.principalType")] public RoleManagementPrincipalType? PrincipalType { get; } /// Id of the master role eligibility schedule. + [WirePath("properties.roleEligibilityScheduleId")] public ResourceIdentifier RoleEligibilityScheduleId { get; } /// The status of the role eligibility schedule instance. + [WirePath("properties.status")] public RoleManagementScheduleStatus? Status { get; } /// The startDateTime of the role eligibility schedule instance. + [WirePath("properties.startDateTime")] public DateTimeOffset? StartOn { get; } /// The endDateTime of the role eligibility schedule instance. + [WirePath("properties.endDateTime")] public DateTimeOffset? EndOn { get; } /// Membership type of the role eligibility schedule. + [WirePath("properties.memberType")] public RoleManagementScheduleMemberType? MemberType { get; } /// The conditions on the role assignment. This limits the resources it can be assigned to. e.g.: @Resource[Microsoft.Storage/storageAccounts/blobServices/containers:ContainerName] StringEqualsIgnoreCase 'foo_storage_container'. + [WirePath("properties.condition")] public string Condition { get; } /// Version of the condition. Currently accepted value is '2.0'. + [WirePath("properties.conditionVersion")] public string ConditionVersion { get; } /// DateTime when role eligibility schedule was created. + [WirePath("properties.createdOn")] public DateTimeOffset? CreatedOn { get; } /// Additional properties of principal, scope and role definition. + [WirePath("properties.expandedProperties")] public RoleManagementExpandedProperties ExpandedProperties { get; } } } diff --git a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/RoleEligibilityScheduleRequestData.Serialization.cs b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/RoleEligibilityScheduleRequestData.Serialization.cs index 739d4153bb873..42e18962a69e1 100644 --- a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/RoleEligibilityScheduleRequestData.Serialization.cs +++ b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/RoleEligibilityScheduleRequestData.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.Authorization.Models; using Azure.ResourceManager.Models; @@ -340,7 +342,7 @@ internal static RoleEligibilityScheduleRequestData DeserializeRoleEligibilitySch { continue; } - ticketInfo = RoleEligibilityScheduleRequestPropertiesTicketInfo.DeserializeRoleEligibilityScheduleRequestPropertiesTicketInfo(property0.Value, options); + ticketInfo = RoleEligibilityScheduleRequestPropertiesTicketInfo.DeserializeRoleEligibilityScheduleRequestPropertiesTicketInfo(property0.Value); continue; } if (property0.NameEquals("condition"u8)) @@ -377,7 +379,7 @@ internal static RoleEligibilityScheduleRequestData DeserializeRoleEligibilitySch { continue; } - expandedProperties = RoleManagementExpandedProperties.DeserializeRoleManagementExpandedProperties(property0.Value, options); + expandedProperties = RoleManagementExpandedProperties.DeserializeRoleManagementExpandedProperties(property0.Value); continue; } if (property0.NameEquals("scheduleInfo"u8)) @@ -452,6 +454,446 @@ internal static RoleEligibilityScheduleRequestData DeserializeRoleEligibilitySch return new RoleEligibilityScheduleRequestData(id, name, type, systemData.Value, scope.Value, roleDefinitionId.Value, Optional.ToNullable(principalId), Optional.ToNullable(principalType), Optional.ToNullable(requestType), Optional.ToNullable(status), approvalId.Value, targetRoleEligibilityScheduleId.Value, targetRoleEligibilityScheduleInstanceId.Value, justification.Value, ticketInfo.Value, condition.Value, conditionVersion.Value, Optional.ToNullable(createdOn), Optional.ToNullable(requestorId), expandedProperties.Value, Optional.ToNullable(startDateTime), Optional.ToNullable(type0), Optional.ToNullable(endDateTime), Optional.ToNullable(duration), 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(Scope), out propertyOverride); + if (Optional.IsDefined(Scope) || hasPropertyOverride) + { + builder.Append(" scope: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + if (Scope.Contains(Environment.NewLine)) + { + builder.AppendLine("'''"); + builder.AppendLine($"{Scope}'''"); + } + else + { + builder.AppendLine($"'{Scope}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(RoleDefinitionId), out propertyOverride); + if (Optional.IsDefined(RoleDefinitionId) || hasPropertyOverride) + { + builder.Append(" roleDefinitionId: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{RoleDefinitionId.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(PrincipalId), out propertyOverride); + if (Optional.IsDefined(PrincipalId) || hasPropertyOverride) + { + builder.Append(" principalId: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{PrincipalId.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(PrincipalType), out propertyOverride); + if (Optional.IsDefined(PrincipalType) || hasPropertyOverride) + { + builder.Append(" principalType: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{PrincipalType.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(RequestType), out propertyOverride); + if (Optional.IsDefined(RequestType) || hasPropertyOverride) + { + builder.Append(" requestType: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{RequestType.Value.ToString()}'"); + } + } + + 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(ApprovalId), out propertyOverride); + if (Optional.IsDefined(ApprovalId) || hasPropertyOverride) + { + builder.Append(" approvalId: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + if (ApprovalId.Contains(Environment.NewLine)) + { + builder.AppendLine("'''"); + builder.AppendLine($"{ApprovalId}'''"); + } + else + { + builder.AppendLine($"'{ApprovalId}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(TargetRoleEligibilityScheduleId), out propertyOverride); + if (Optional.IsDefined(TargetRoleEligibilityScheduleId) || hasPropertyOverride) + { + builder.Append(" targetRoleEligibilityScheduleId: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{TargetRoleEligibilityScheduleId.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(TargetRoleEligibilityScheduleInstanceId), out propertyOverride); + if (Optional.IsDefined(TargetRoleEligibilityScheduleInstanceId) || hasPropertyOverride) + { + builder.Append(" targetRoleEligibilityScheduleInstanceId: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{TargetRoleEligibilityScheduleInstanceId.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Justification), out propertyOverride); + if (Optional.IsDefined(Justification) || hasPropertyOverride) + { + builder.Append(" justification: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + if (Justification.Contains(Environment.NewLine)) + { + builder.AppendLine("'''"); + builder.AppendLine($"{Justification}'''"); + } + else + { + builder.AppendLine($"'{Justification}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(TicketInfo), out propertyOverride); + if (Optional.IsDefined(TicketInfo) || hasPropertyOverride) + { + builder.Append(" ticketInfo: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + AppendChildObject(builder, TicketInfo, options, 4, false, " ticketInfo: "); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Condition), out propertyOverride); + if (Optional.IsDefined(Condition) || hasPropertyOverride) + { + builder.Append(" condition: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + if (Condition.Contains(Environment.NewLine)) + { + builder.AppendLine("'''"); + builder.AppendLine($"{Condition}'''"); + } + else + { + builder.AppendLine($"'{Condition}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ConditionVersion), out propertyOverride); + if (Optional.IsDefined(ConditionVersion) || hasPropertyOverride) + { + builder.Append(" conditionVersion: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + if (ConditionVersion.Contains(Environment.NewLine)) + { + builder.AppendLine("'''"); + builder.AppendLine($"{ConditionVersion}'''"); + } + else + { + builder.AppendLine($"'{ConditionVersion}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(CreatedOn), out propertyOverride); + if (Optional.IsDefined(CreatedOn) || hasPropertyOverride) + { + builder.Append(" createdOn: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + var formattedDateTimeString = TypeFormatters.ToString(CreatedOn.Value, "o"); + builder.AppendLine($"'{formattedDateTimeString}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(RequestorId), out propertyOverride); + if (Optional.IsDefined(RequestorId) || hasPropertyOverride) + { + builder.Append(" requestorId: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{RequestorId.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ExpandedProperties), out propertyOverride); + if (Optional.IsDefined(ExpandedProperties) || hasPropertyOverride) + { + builder.Append(" expandedProperties: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + AppendChildObject(builder, ExpandedProperties, options, 4, false, " expandedProperties: "); + } + } + + builder.Append(" scheduleInfo:"); + builder.AppendLine(" {"); + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(StartOn), out propertyOverride); + if (Optional.IsDefined(StartOn) || hasPropertyOverride) + { + builder.Append(" startDateTime: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + var formattedDateTimeString = TypeFormatters.ToString(StartOn.Value, "o"); + builder.AppendLine($"'{formattedDateTimeString}'"); + } + } + + builder.Append(" expiration:"); + builder.AppendLine(" {"); + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(ExpirationType), out propertyOverride); + if (Optional.IsDefined(ExpirationType) || hasPropertyOverride) + { + builder.Append(" type: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{ExpirationType.Value.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(EndOn), out propertyOverride); + if (Optional.IsDefined(EndOn) || hasPropertyOverride) + { + builder.Append(" endDateTime: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + var formattedDateTimeString = TypeFormatters.ToString(EndOn.Value, "o"); + builder.AppendLine($"'{formattedDateTimeString}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(Duration), out propertyOverride); + if (Optional.IsDefined(Duration) || hasPropertyOverride) + { + builder.Append(" duration: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + var formattedTimeSpan = TypeFormatters.ToString(Duration.Value, "P"); + builder.AppendLine($"'{formattedTimeSpan}'"); + } + } + + builder.AppendLine(" }"); + 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 formattedPropertyName) + { + string indent = new string(' ', spaces); + int emptyObjectLength = 2 + spaces + Environment.NewLine.Length + Environment.NewLine.Length; + int length = stringBuilder.Length; + bool inMultilineString = false; + + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + 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}"); + } + } + if (stringBuilder.Length == length + emptyObjectLength) + { + stringBuilder.Length = stringBuilder.Length - emptyObjectLength - formattedPropertyName.Length; + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -460,6 +902,8 @@ BinaryData IPersistableModel.Write(ModelRead { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(RoleEligibilityScheduleRequestData)} does not support '{options.Format}' format."); } @@ -476,6 +920,8 @@ RoleEligibilityScheduleRequestData IPersistableModel The role eligibility schedule request scope. + [WirePath("properties.scope")] public string Scope { get; } /// The role definition ID. + [WirePath("properties.roleDefinitionId")] public ResourceIdentifier RoleDefinitionId { get; set; } /// The principal ID. + [WirePath("properties.principalId")] public Guid? PrincipalId { get; set; } /// The principal type of the assigned principal ID. + [WirePath("properties.principalType")] public RoleManagementPrincipalType? PrincipalType { get; } /// The type of the role assignment schedule request. Eg: SelfActivate, AdminAssign etc. + [WirePath("properties.requestType")] public RoleManagementScheduleRequestType? RequestType { get; set; } /// The status of the role eligibility schedule request. + [WirePath("properties.status")] public RoleManagementScheduleStatus? Status { get; } /// The approvalId of the role eligibility schedule request. + [WirePath("properties.approvalId")] public string ApprovalId { get; } /// The resultant role eligibility schedule id or the role eligibility schedule id being updated. + [WirePath("properties.targetRoleEligibilityScheduleId")] public ResourceIdentifier TargetRoleEligibilityScheduleId { get; set; } /// The role eligibility schedule instance id being updated. + [WirePath("properties.targetRoleEligibilityScheduleInstanceId")] public ResourceIdentifier TargetRoleEligibilityScheduleInstanceId { get; set; } /// Justification for the role eligibility. + [WirePath("properties.justification")] public string Justification { get; set; } /// Ticket Info of the role eligibility. + [WirePath("properties.ticketInfo")] public RoleEligibilityScheduleRequestPropertiesTicketInfo TicketInfo { get; set; } /// The conditions on the role assignment. This limits the resources it can be assigned to. e.g.: @Resource[Microsoft.Storage/storageAccounts/blobServices/containers:ContainerName] StringEqualsIgnoreCase 'foo_storage_container'. + [WirePath("properties.condition")] public string Condition { get; set; } /// Version of the condition. Currently accepted value is '2.0'. + [WirePath("properties.conditionVersion")] public string ConditionVersion { get; set; } /// DateTime when role eligibility schedule request was created. + [WirePath("properties.createdOn")] public DateTimeOffset? CreatedOn { get; } /// Id of the user who created this request. + [WirePath("properties.requestorId")] public Guid? RequestorId { get; } /// Additional properties of principal, scope and role definition. + [WirePath("properties.expandedProperties")] public RoleManagementExpandedProperties ExpandedProperties { get; } /// Start DateTime of the role eligibility schedule. + [WirePath("properties.startDateTime")] public DateTimeOffset? StartOn { get; set; } /// Type of the role eligibility schedule expiration. + [WirePath("properties.type")] public RoleManagementScheduleExpirationType? ExpirationType { get; set; } /// End DateTime of the role eligibility schedule. + [WirePath("properties.endDateTime")] public DateTimeOffset? EndOn { get; set; } /// Duration of the role eligibility schedule in TimeSpan. + [WirePath("properties.duration")] public TimeSpan? Duration { get; set; } } } diff --git a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/RoleManagementPolicyAssignmentData.Serialization.cs b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/RoleManagementPolicyAssignmentData.Serialization.cs index 6efe120567fe9..e4508cf418df3 100644 --- a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/RoleManagementPolicyAssignmentData.Serialization.cs +++ b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/RoleManagementPolicyAssignmentData.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.Authorization.Models; using Azure.ResourceManager.Models; @@ -197,7 +200,7 @@ internal static RoleManagementPolicyAssignmentData DeserializeRoleManagementPoli List array = new List(); foreach (var item in property0.Value.EnumerateArray()) { - array.Add(RoleManagementPolicyRule.DeserializeRoleManagementPolicyRule(item, options)); + array.Add(RoleManagementPolicyRule.DeserializeRoleManagementPolicyRule(item)); } effectiveRules = array; continue; @@ -208,7 +211,7 @@ internal static RoleManagementPolicyAssignmentData DeserializeRoleManagementPoli { continue; } - policyAssignmentProperties = PolicyAssignmentProperties.DeserializePolicyAssignmentProperties(property0.Value, options); + policyAssignmentProperties = PolicyAssignmentProperties.DeserializePolicyAssignmentProperties(property0.Value); continue; } } @@ -223,6 +226,202 @@ internal static RoleManagementPolicyAssignmentData DeserializeRoleManagementPoli return new RoleManagementPolicyAssignmentData(id, name, type, systemData.Value, scope.Value, roleDefinitionId.Value, policyId.Value, Optional.ToList(effectiveRules), policyAssignmentProperties.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(Scope), out propertyOverride); + if (Optional.IsDefined(Scope) || hasPropertyOverride) + { + builder.Append(" scope: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + if (Scope.Contains(Environment.NewLine)) + { + builder.AppendLine("'''"); + builder.AppendLine($"{Scope}'''"); + } + else + { + builder.AppendLine($"'{Scope}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(RoleDefinitionId), out propertyOverride); + if (Optional.IsDefined(RoleDefinitionId) || hasPropertyOverride) + { + builder.Append(" roleDefinitionId: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{RoleDefinitionId.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(PolicyId), out propertyOverride); + if (Optional.IsDefined(PolicyId) || hasPropertyOverride) + { + builder.Append(" policyId: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine($"'{PolicyId.ToString()}'"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(EffectiveRules), out propertyOverride); + if (Optional.IsCollectionDefined(EffectiveRules) || hasPropertyOverride) + { + if (EffectiveRules.Any() || hasPropertyOverride) + { + builder.Append(" effectiveRules: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine("["); + foreach (var item in EffectiveRules) + { + AppendChildObject(builder, item, options, 6, true, " effectiveRules: "); + } + builder.AppendLine(" ]"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(PolicyAssignmentProperties), out propertyOverride); + if (Optional.IsDefined(PolicyAssignmentProperties) || hasPropertyOverride) + { + builder.Append(" policyAssignmentProperties: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + AppendChildObject(builder, PolicyAssignmentProperties, options, 4, false, " policyAssignmentProperties: "); + } + } + + builder.AppendLine(" }"); + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine, string formattedPropertyName) + { + string indent = new string(' ', spaces); + int emptyObjectLength = 2 + spaces + Environment.NewLine.Length + Environment.NewLine.Length; + int length = stringBuilder.Length; + bool inMultilineString = false; + + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + 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}"); + } + } + if (stringBuilder.Length == length + emptyObjectLength) + { + stringBuilder.Length = stringBuilder.Length - emptyObjectLength - formattedPropertyName.Length; + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -231,6 +430,8 @@ BinaryData IPersistableModel.Write(ModelRead { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(RoleManagementPolicyAssignmentData)} does not support '{options.Format}' format."); } @@ -247,6 +448,8 @@ RoleManagementPolicyAssignmentData IPersistableModel The role management policy scope. + [WirePath("properties.scope")] public string Scope { get; set; } /// The role definition of management policy assignment. + [WirePath("properties.roleDefinitionId")] public ResourceIdentifier RoleDefinitionId { get; set; } /// The policy id role management policy assignment. + [WirePath("properties.policyId")] public ResourceIdentifier PolicyId { get; set; } /// /// The readonly computed rule applied to the policy. /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. /// The available derived classes include , , , and . /// + [WirePath("properties.effectiveRules")] public IReadOnlyList EffectiveRules { get; } /// Additional properties of scope, role definition and policy. + [WirePath("properties.policyAssignmentProperties")] public PolicyAssignmentProperties PolicyAssignmentProperties { get; } } } diff --git a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/RoleManagementPolicyData.Serialization.cs b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/RoleManagementPolicyData.Serialization.cs index 0671f8caed19f..f637cead75138 100644 --- a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/RoleManagementPolicyData.Serialization.cs +++ b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/RoleManagementPolicyData.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.Authorization.Models; using Azure.ResourceManager.Models; @@ -224,7 +227,7 @@ internal static RoleManagementPolicyData DeserializeRoleManagementPolicyData(Jso { continue; } - lastModifiedBy = RoleManagementPrincipal.DeserializeRoleManagementPrincipal(property0.Value, options); + lastModifiedBy = RoleManagementPrincipal.DeserializeRoleManagementPrincipal(property0.Value); continue; } if (property0.NameEquals("lastModifiedDateTime"u8)) @@ -245,7 +248,7 @@ internal static RoleManagementPolicyData DeserializeRoleManagementPolicyData(Jso List array = new List(); foreach (var item in property0.Value.EnumerateArray()) { - array.Add(RoleManagementPolicyRule.DeserializeRoleManagementPolicyRule(item, options)); + array.Add(RoleManagementPolicyRule.DeserializeRoleManagementPolicyRule(item)); } rules = array; continue; @@ -259,7 +262,7 @@ internal static RoleManagementPolicyData DeserializeRoleManagementPolicyData(Jso List array = new List(); foreach (var item in property0.Value.EnumerateArray()) { - array.Add(RoleManagementPolicyRule.DeserializeRoleManagementPolicyRule(item, options)); + array.Add(RoleManagementPolicyRule.DeserializeRoleManagementPolicyRule(item)); } effectiveRules = array; continue; @@ -270,7 +273,7 @@ internal static RoleManagementPolicyData DeserializeRoleManagementPolicyData(Jso { continue; } - policyProperties = RoleManagementPolicyProperties.DeserializeRoleManagementPolicyProperties(property0.Value, options); + policyProperties = RoleManagementPolicyProperties.DeserializeRoleManagementPolicyProperties(property0.Value); continue; } } @@ -285,6 +288,284 @@ internal static RoleManagementPolicyData DeserializeRoleManagementPolicyData(Jso return new RoleManagementPolicyData(id, name, type, systemData.Value, scope.Value, displayName.Value, description.Value, Optional.ToNullable(isOrganizationDefault), lastModifiedBy.Value, Optional.ToNullable(lastModifiedDateTime), Optional.ToList(rules), Optional.ToList(effectiveRules), policyProperties.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(Scope), out propertyOverride); + if (Optional.IsDefined(Scope) || hasPropertyOverride) + { + builder.Append(" scope: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + if (Scope.Contains(Environment.NewLine)) + { + builder.AppendLine("'''"); + builder.AppendLine($"{Scope}'''"); + } + else + { + builder.AppendLine($"'{Scope}'"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(DisplayName), out propertyOverride); + if (Optional.IsDefined(DisplayName) || hasPropertyOverride) + { + builder.Append(" displayName: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + if (DisplayName.Contains(Environment.NewLine)) + { + builder.AppendLine("'''"); + builder.AppendLine($"{DisplayName}'''"); + } + else + { + builder.AppendLine($"'{DisplayName}'"); + } + } + } + + 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(IsOrganizationDefault), out propertyOverride); + if (Optional.IsDefined(IsOrganizationDefault) || hasPropertyOverride) + { + builder.Append(" isOrganizationDefault: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + var boolValue = IsOrganizationDefault.Value == true ? "true" : "false"; + builder.AppendLine($"{boolValue}"); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(LastModifiedBy), out propertyOverride); + if (Optional.IsDefined(LastModifiedBy) || hasPropertyOverride) + { + builder.Append(" lastModifiedBy: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + AppendChildObject(builder, LastModifiedBy, options, 4, false, " lastModifiedBy: "); + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(LastModifiedOn), out propertyOverride); + if (Optional.IsDefined(LastModifiedOn) || hasPropertyOverride) + { + builder.Append(" lastModifiedDateTime: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + var formattedDateTimeString = TypeFormatters.ToString(LastModifiedOn.Value, "o"); + builder.AppendLine($"'{formattedDateTimeString}'"); + } + } + + 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, " rules: "); + } + builder.AppendLine(" ]"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(EffectiveRules), out propertyOverride); + if (Optional.IsCollectionDefined(EffectiveRules) || hasPropertyOverride) + { + if (EffectiveRules.Any() || hasPropertyOverride) + { + builder.Append(" effectiveRules: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + builder.AppendLine("["); + foreach (var item in EffectiveRules) + { + AppendChildObject(builder, item, options, 6, true, " effectiveRules: "); + } + builder.AppendLine(" ]"); + } + } + } + + hasPropertyOverride = hasObjectOverride && propertyOverrides.TryGetValue(nameof(PolicyProperties), out propertyOverride); + if (Optional.IsDefined(PolicyProperties) || hasPropertyOverride) + { + builder.Append(" policyProperties: "); + if (hasPropertyOverride) + { + builder.AppendLine($"{propertyOverride}"); + } + else + { + AppendChildObject(builder, PolicyProperties, options, 4, false, " policyProperties: "); + } + } + + builder.AppendLine(" }"); + builder.AppendLine("}"); + return BinaryData.FromString(builder.ToString()); + } + + private void AppendChildObject(StringBuilder stringBuilder, object childObject, ModelReaderWriterOptions options, int spaces, bool indentFirstLine, string formattedPropertyName) + { + string indent = new string(' ', spaces); + int emptyObjectLength = 2 + spaces + Environment.NewLine.Length + Environment.NewLine.Length; + int length = stringBuilder.Length; + bool inMultilineString = false; + + BinaryData data = ModelReaderWriter.Write(childObject, options); + string[] lines = data.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + 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}"); + } + } + if (stringBuilder.Length == length + emptyObjectLength) + { + stringBuilder.Length = stringBuilder.Length - emptyObjectLength - formattedPropertyName.Length; + } + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -293,6 +574,8 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOp { case "J": return ModelReaderWriter.Write(this, options); + case "bicep": + return SerializeBicep(options); default: throw new FormatException($"The model {nameof(RoleManagementPolicyData)} does not support '{options.Format}' format."); } @@ -309,6 +592,8 @@ RoleManagementPolicyData IPersistableModel.Create(Bina using JsonDocument document = JsonDocument.Parse(data); return DeserializeRoleManagementPolicyData(document.RootElement, options); } + case "bicep": + throw new InvalidOperationException("Bicep deserialization is not supported for this type."); default: throw new FormatException($"The model {nameof(RoleManagementPolicyData)} does not support '{options.Format}' format."); } diff --git a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/RoleManagementPolicyData.cs b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/RoleManagementPolicyData.cs index c442879ed2925..73e0e3abfa194 100644 --- a/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/RoleManagementPolicyData.cs +++ b/sdk/authorization/Azure.ResourceManager.Authorization/src/Generated/RoleManagementPolicyData.cs @@ -96,30 +96,39 @@ internal RoleManagementPolicyData(ResourceIdentifier id, string name, ResourceTy } /// The role management policy scope. + [WirePath("properties.scope")] public string Scope { get; set; } /// The role management policy display name. + [WirePath("properties.displayName")] public string DisplayName { get; set; } /// The role management policy description. + [WirePath("properties.description")] public string Description { get; set; } /// The role management policy is default policy. + [WirePath("properties.isOrganizationDefault")] public bool? IsOrganizationDefault { get; set; } /// The name of the entity last modified it. + [WirePath("properties.lastModifiedBy")] public RoleManagementPrincipal LastModifiedBy { get; } /// The last modified date time. + [WirePath("properties.lastModifiedDateTime")] public DateTimeOffset? LastModifiedOn { get; } /// /// The rule applied to the policy. /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. /// The available derived classes include , , , and . /// + [WirePath("properties.rules")] public IList Rules { get; } /// /// The readonly computed rule applied to the policy. /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. /// The available derived classes include , , , and . /// + [WirePath("properties.effectiveRules")] public IReadOnlyList EffectiveRules { get; } /// Additional properties of scope. + [WirePath("properties.policyProperties")] public RoleManagementPolicyProperties PolicyProperties { get; } } } diff --git a/sdk/authorization/Azure.ResourceManager.Authorization/src/autorest.md b/sdk/authorization/Azure.ResourceManager.Authorization/src/autorest.md index f5f7207e689f6..29f85995fce7c 100644 --- a/sdk/authorization/Azure.ResourceManager.Authorization/src/autorest.md +++ b/sdk/authorization/Azure.ResourceManager.Authorization/src/autorest.md @@ -17,6 +17,7 @@ sample-gen: clear-output-folder: true use-model-reader-writer: true skip-csproj: true +enable-bicep-serialization: true rename-mapping: RoleAssignment.properties.delegatedManagedIdentityResourceId: -|arm-id