public void UnionTypeInvolvingResourceScopeTypesShouldProduceExpectedDisplayString() { var unionType = TypeHelper.CreateTypeUnion( new StringLiteralType("Test"), LanguageConstants.CreateResourceScopeReference(ResourceScope.Resource), LanguageConstants.CreateResourceScopeReference(ResourceScope.Subscription | ResourceScope.Tenant) ); unionType.Name.Should().Be("'Test' | resource | (tenant | subscription)"); }
public void ArraysOfCompoundTypesShouldHaveExpectedDisplayString() { Create(UnionType.Create(new StringLiteralType("one"), new StringLiteralType("two"))).Name.Should().Be("('one' | 'two')[]"); Create(UnionType.Create(LanguageConstants.CreateResourceScopeReference(ResourceScope.ManagementGroup), new StringLiteralType("test"))).Name .Should().Be("('test' | managementGroup)[]"); Create(UnionType.Create(LanguageConstants.CreateResourceScopeReference(ResourceScope.ManagementGroup | ResourceScope.Tenant), new StringLiteralType("test"))).Name .Should().Be("('test' | (tenant | managementGroup))[]"); }
private static ObjectType SetBicepResourceProperties(ObjectType objectType, ResourceScope validParentScopes, ResourceTypeReference typeReference, bool isExistingResource) { var properties = objectType.Properties; var scopePropertyFlags = TypePropertyFlags.WriteOnly | TypePropertyFlags.DeployTimeConstant; if (validParentScopes == ResourceScope.Resource) { // resource can only be deployed as an extension resource - scope should be required scopePropertyFlags |= TypePropertyFlags.Required; } if (isExistingResource) { // we can refer to a resource at any scope if it is an existing resource not being deployed by this file var scopeReference = LanguageConstants.CreateResourceScopeReference(validParentScopes); properties = properties.SetItem(LanguageConstants.ResourceScopePropertyName, new TypeProperty(LanguageConstants.ResourceScopePropertyName, scopeReference, scopePropertyFlags)); } else { // TODO: remove 'dependsOn' from the type library properties = properties.SetItem(LanguageConstants.ResourceDependsOnPropertyName, new TypeProperty(LanguageConstants.ResourceDependsOnPropertyName, LanguageConstants.ResourceOrResourceCollectionRefArray, TypePropertyFlags.WriteOnly)); // we only support scope for extension resources (or resources where the scope is unknown and thus may be an extension resource) if (validParentScopes.HasFlag(ResourceScope.Resource)) { var scopeReference = LanguageConstants.CreateResourceScopeReference(ResourceScope.Resource); properties = properties.SetItem(LanguageConstants.ResourceScopePropertyName, new TypeProperty(LanguageConstants.ResourceScopePropertyName, scopeReference, scopePropertyFlags)); } } // add the 'parent' property for child resource types if (!typeReference.IsRootType) { var parentType = LanguageConstants.CreateResourceScopeReference(ResourceScope.Resource); var parentFlags = TypePropertyFlags.WriteOnly | TypePropertyFlags.DeployTimeConstant; properties = properties.SetItem(LanguageConstants.ResourceParentPropertyName, new TypeProperty(LanguageConstants.ResourceParentPropertyName, parentType, parentFlags)); } // Deployments RP if (StringComparer.OrdinalIgnoreCase.Equals(objectType.Name, ResourceTypeDeployments)) { properties = properties.SetItem("resourceGroup", new TypeProperty("resourceGroup", LanguageConstants.String, TypePropertyFlags.DeployTimeConstant)); properties = properties.SetItem("subscriptionId", new TypeProperty("subscriptionId", LanguageConstants.String, TypePropertyFlags.DeployTimeConstant)); } return(new NamedObjectType( objectType.Name, objectType.ValidationFlags, isExistingResource ? ConvertToReadOnly(properties.Values) : properties.Values, objectType.AdditionalPropertiesType, isExistingResource ? ConvertToReadOnly(objectType.AdditionalPropertiesFlags) : objectType.AdditionalPropertiesFlags)); }
private static ObjectType SetBicepResourceProperties(ObjectType objectType, ResourceScope validParentScopes, bool isExistingResource) { var properties = objectType.Properties; var scopeRequiredFlag = TypePropertyFlags.WriteOnly; if (validParentScopes == ResourceScope.Resource) { // resource can only be deployed as an extension resource - scope should be required scopeRequiredFlag |= TypePropertyFlags.Required; } if (isExistingResource) { // we can refer to a resource at any scope if it is an existing resource not being deployed by this file var scopeReference = LanguageConstants.CreateResourceScopeReference(validParentScopes); properties = properties.SetItem(LanguageConstants.ResourceScopePropertyName, new TypeProperty(LanguageConstants.ResourceScopePropertyName, scopeReference, scopeRequiredFlag)); return(new NamedObjectType( objectType.Name, objectType.ValidationFlags, ConvertToReadOnly(properties.Values), objectType.AdditionalPropertiesType, ConvertToReadOnly(objectType.AdditionalPropertiesFlags))); } else { // we only support scope for extension resources (or resources where the scope is unknown and thus may be an extension resource) if (validParentScopes.HasFlag(ResourceScope.Resource)) { var scopeReference = LanguageConstants.CreateResourceScopeReference(ResourceScope.Resource); properties = properties.SetItem(LanguageConstants.ResourceScopePropertyName, new TypeProperty(LanguageConstants.ResourceScopePropertyName, scopeReference, scopeRequiredFlag)); } // TODO: remove 'dependsOn' from the type library properties = properties.SetItem(LanguageConstants.ResourceDependsOnPropertyName, new TypeProperty(LanguageConstants.ResourceDependsOnPropertyName, LanguageConstants.ResourceRefArray, TypePropertyFlags.WriteOnly)); return(new NamedObjectType( objectType.Name, objectType.ValidationFlags, properties.Values, objectType.AdditionalPropertiesType, objectType.AdditionalPropertiesFlags)); } }