Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the validation rules to the abstract types #1058

Merged
merged 4 commits into from Feb 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Microsoft.OData.Edm/EdmModelVisitor.cs
Expand Up @@ -312,6 +312,7 @@ public void VisitPrimitiveTypeReference(IEdmPrimitiveTypeReference reference)
case EdmPrimitiveTypeKind.Single:
case EdmPrimitiveTypeKind.Stream:
case EdmPrimitiveTypeKind.Date:
case EdmPrimitiveTypeKind.PrimitiveType:
case EdmPrimitiveTypeKind.None:
this.ProcessPrimitiveTypeReference(reference);
break;
Expand Down
21 changes: 20 additions & 1 deletion src/Microsoft.OData.Edm/ExtensionMethods/EdmTypeSemantics.cs
Expand Up @@ -15,7 +15,7 @@ namespace Microsoft.OData.Edm
/// </summary>
public static class EdmTypeSemantics
{
#region IsCollection, IsEntity, IsComplex, ...
#region IsCollection, IsEntity, IsComplex, IsPath...

/// <summary>
/// Returns true if this reference refers to a collection.
Expand All @@ -39,6 +39,17 @@ public static bool IsEntity(this IEdmTypeReference type)
return type.TypeKind() == EdmTypeKind.Entity;
}

/// <summary>
/// Returns true if this reference refers to a path type.
/// </summary>
/// <param name="type">Type reference.</param>
/// <returns>This reference refers to a path type.</returns>
public static bool IsPath(this IEdmTypeReference type)
{
EdmUtil.CheckArgumentNull(type, "type");
return type.TypeKind() == EdmTypeKind.Path;
}

/// <summary>
/// Returns true if this reference refers to an entity type.
/// </summary>
Expand Down Expand Up @@ -702,6 +713,7 @@ public static IEdmPrimitiveTypeReference AsPrimitive(this IEdmTypeReference type
case EdmPrimitiveTypeKind.SByte:
case EdmPrimitiveTypeKind.Single:
case EdmPrimitiveTypeKind.Stream:
case EdmPrimitiveTypeKind.PrimitiveType:
return new EdmPrimitiveTypeReference(primitiveDefinition, type.IsNullable);
case EdmPrimitiveTypeKind.Binary:
return type.AsBinary();
Expand Down Expand Up @@ -1260,6 +1272,7 @@ internal static IEdmPrimitiveTypeReference GetPrimitiveTypeReference(this IEdmPr
case EdmPrimitiveTypeKind.SByte:
case EdmPrimitiveTypeKind.Single:
case EdmPrimitiveTypeKind.Stream:
case EdmPrimitiveTypeKind.PrimitiveType:
return new EdmPrimitiveTypeReference(type, isNullable);
case EdmPrimitiveTypeKind.Binary:
return new EdmBinaryTypeReference(type, isNullable);
Expand Down Expand Up @@ -1319,6 +1332,12 @@ internal static IEdmTypeReference GetTypeReference(this IEdmType type, bool isNu
return new EdmEnumTypeReference(enumType, isNullable);
}

IEdmPathType pathType = type as IEdmPathType;
if (pathType != null)
{
return new EdmPathTypeReference(pathType, isNullable);
}

throw new InvalidOperationException(Edm.Strings.EdmType_UnexpectedEdmType);
}

Expand Down
11 changes: 11 additions & 0 deletions src/Microsoft.OData.Edm/GlobalSuppressions.cs
Expand Up @@ -263,3 +263,14 @@
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Multi", Scope = "member", Target = "Microsoft.OData.Edm.EdmPrimitiveTypeKind.#GeographyMultiLineString")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate", Scope = "member", Target = "Microsoft.OData.Edm.EdmCoreModel.#GetUntypedType()")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate", Scope = "member", Target = "Microsoft.OData.Edm.EdmCoreModel.#GetUntyped()")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Scope = "member", Target = "Microsoft.OData.Edm.Validation.ValidationRules.#TypeDefinitionUnderlyingTypeCannotBeEdmPrimitiveType")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Scope = "member", Target = "Microsoft.OData.Edm.Validation.ValidationRules.#StructuredTypeBaseTypeCannotBeAbstractType")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Scope = "member", Target = "Microsoft.OData.Edm.Validation.ValidationRules.#PropertyTypeCannotBeCollectionOfAbstractType")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Scope = "member", Target = "Microsoft.OData.Edm.Validation.ValidationRules.#OperationReturnTypeCannotBeCollectionOfAbstractType")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Scope = "member", Target = "Microsoft.OData.Edm.Validation.ValidationRules.#EntityTypeKeyTypeCannotBeEdmPrimitiveType")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Scope = "member", Target = "Microsoft.OData.Edm.Validation.ValidationRules.#EntitySetTypeCannotBeEdmEntityType")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Scope = "member", Target = "Microsoft.OData.Edm.Validation.ValidationRules.#SingletonTypeCannotBeEdmEntityType")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Scope = "member", Target = "Microsoft.OData.Edm.Validation.ValidationRules.#EnumUnderlyingTypeCannotBeEdmPrimitiveType")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Scope = "member", Target = "Microsoft.OData.Edm.Validation.ValidationRules.#NavigationSourceDeclaringTypeCannotHavePathTypeProperty")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Scope = "member", Target = "Microsoft.OData.Edm.Validation.ValidationRules.#NavigationPropertyTypeCannotHavePathTypeProperty")]

9 changes: 9 additions & 0 deletions src/Microsoft.OData.Edm/Microsoft.OData.Edm.cs
Expand Up @@ -154,6 +154,8 @@ internal sealed class EntityRes {
internal const string EdmModel_Validator_Semantic_BaseTypeMustHaveSameTypeKind = "EdmModel_Validator_Semantic_BaseTypeMustHaveSameTypeKind";
internal const string EdmModel_Validator_Semantic_BaseTypeOfOpenTypeMustBeOpen = "EdmModel_Validator_Semantic_BaseTypeOfOpenTypeMustBeOpen";
internal const string EdmModel_Validator_Semantic_KeyPropertyMustBelongToEntity = "EdmModel_Validator_Semantic_KeyPropertyMustBelongToEntity";
internal const string EdmModel_Validator_Semantic_EdmPrimitiveTypeCannotBeUsedAsTypeOfKey = "EdmModel_Validator_Semantic_EdmPrimitiveTypeCannotBeUsedAsTypeOfKey";
internal const string EdmModel_Validator_Semantic_EdmPrimitiveTypeCannotBeUsedAsUnderlyingType = "EdmModel_Validator_Semantic_EdmPrimitiveTypeCannotBeUsedAsUnderlyingType";
internal const string EdmModel_Validator_Semantic_DependentPropertiesMustBelongToDependentEntity = "EdmModel_Validator_Semantic_DependentPropertiesMustBelongToDependentEntity";
internal const string EdmModel_Validator_Semantic_DeclaringTypeMustBeCorrect = "EdmModel_Validator_Semantic_DeclaringTypeMustBeCorrect";
internal const string EdmModel_Validator_Semantic_InaccessibleType = "EdmModel_Validator_Semantic_InaccessibleType";
Expand Down Expand Up @@ -223,6 +225,13 @@ internal sealed class EntityRes {
internal const string EdmModel_Validator_Semantic_EntitySetTypeMustBeCollectionOfEntityType = "EdmModel_Validator_Semantic_EntitySetTypeMustBeCollectionOfEntityType";
internal const string EdmModel_Validator_Semantic_SingletonTypeMustBeEntityType = "EdmModel_Validator_Semantic_SingletonTypeMustBeEntityType";
internal const string EdmModel_Validator_Semantic_NavigationPropertyOfCollectionTypeMustNotTargetToSingleton = "EdmModel_Validator_Semantic_NavigationPropertyOfCollectionTypeMustNotTargetToSingleton";
internal const string EdmModel_Validator_Semantic_StructuredTypeBaseTypeCannotBeAbstractType = "EdmModel_Validator_Semantic_StructuredTypeBaseTypeCannotBeAbstractType";
internal const string EdmModel_Validator_Semantic_PropertyTypeCannotBeCollectionOfAbstractType = "EdmModel_Validator_Semantic_PropertyTypeCannotBeCollectionOfAbstractType";
internal const string EdmModel_Validator_Semantic_OperationReturnTypeCannotBeCollectionOfAbstractType = "EdmModel_Validator_Semantic_OperationReturnTypeCannotBeCollectionOfAbstractType";
internal const string EdmModel_Validator_Semantic_EdmEntityTypeCannotBeTypeOfSingleton = "EdmModel_Validator_Semantic_EdmEntityTypeCannotBeTypeOfSingleton";
internal const string EdmModel_Validator_Semantic_EdmEntityTypeCannotBeTypeOfEntitySet = "EdmModel_Validator_Semantic_EdmEntityTypeCannotBeTypeOfEntitySet";
internal const string EdmModel_Validator_Semantic_DeclaringTypeOfNavigationSourceCannotHavePathProperty = "EdmModel_Validator_Semantic_DeclaringTypeOfNavigationSourceCannotHavePathProperty";
internal const string EdmModel_Validator_Semantic_TypeOfNavigationPropertyCannotHavePathProperty = "EdmModel_Validator_Semantic_TypeOfNavigationPropertyCannotHavePathProperty";
internal const string EdmModel_Validator_Syntactic_MissingName = "EdmModel_Validator_Syntactic_MissingName";
internal const string EdmModel_Validator_Syntactic_EdmModel_NameIsTooLong = "EdmModel_Validator_Syntactic_EdmModel_NameIsTooLong";
internal const string EdmModel_Validator_Syntactic_EdmModel_NameIsNotAllowed = "EdmModel_Validator_Syntactic_EdmModel_NameIsNotAllowed";
Expand Down
9 changes: 9 additions & 0 deletions src/Microsoft.OData.Edm/Microsoft.OData.Edm.txt
Expand Up @@ -92,6 +92,8 @@ EdmModel_Validator_Semantic_PropertyNameAlreadyDefined=Each property name in a t
EdmModel_Validator_Semantic_BaseTypeMustHaveSameTypeKind=The base type kind of a structured type must be the same as its derived type.
EdmModel_Validator_Semantic_BaseTypeOfOpenTypeMustBeOpen=The base type of open type '{0}' is not open type.
EdmModel_Validator_Semantic_KeyPropertyMustBelongToEntity=The key property '{0}' must belong to the entity '{1}'.
EdmModel_Validator_Semantic_EdmPrimitiveTypeCannotBeUsedAsTypeOfKey=The 'Edm.PrimitiveType' cannot be used as the type of a key property '{0}' of an entity type '{1}'.
EdmModel_Validator_Semantic_EdmPrimitiveTypeCannotBeUsedAsUnderlyingType=The 'Edm.PrimitiveType' cannot be used as the underlying type of '{0}' type '{1}'.
EdmModel_Validator_Semantic_DependentPropertiesMustBelongToDependentEntity=The dependent property '{0}' must belong to the dependent entity '{1}'.
EdmModel_Validator_Semantic_DeclaringTypeMustBeCorrect=The property '{0}' cannot belong to a type other than its declaring type.
EdmModel_Validator_Semantic_InaccessibleType=The named type '{0}' could not be found from the model being validated.
Expand Down Expand Up @@ -161,6 +163,13 @@ EdmModel_Validator_Semantic_BoundFunctionOverloadsMustHaveSameReturnType=The bou
EdmModel_Validator_Semantic_EntitySetTypeMustBeCollectionOfEntityType=The type '{0}' of the entity set '{1}' is not valid, it must be collection of entity type.
EdmModel_Validator_Semantic_SingletonTypeMustBeEntityType=The type '{0}' of the singleton '{1}' is not valid, it must be entity type.
EdmModel_Validator_Semantic_NavigationPropertyOfCollectionTypeMustNotTargetToSingleton=The navigation property mapping '{0}' is invalid because its type is collection but target to a singleton '{1}'.
EdmModel_Validator_Semantic_StructuredTypeBaseTypeCannotBeAbstractType=The type '{0}' cannot be the base type of an '{1}' type '{2}'.
EdmModel_Validator_Semantic_PropertyTypeCannotBeCollectionOfAbstractType=The type '{0}' cannot be used as the type of a property '{1}'.
EdmModel_Validator_Semantic_OperationReturnTypeCannotBeCollectionOfAbstractType=The type '{0}' cannot be used as the return type of a function '{1}'.
EdmModel_Validator_Semantic_EdmEntityTypeCannotBeTypeOfSingleton=The type 'Edm.EntityType' cannot be used as the type of a singleton '{0}' in an entity container.
EdmModel_Validator_Semantic_EdmEntityTypeCannotBeTypeOfEntitySet=The type 'Edm.EntityType' cannot be used as the type of an entity set '{0}' in an entity container.
EdmModel_Validator_Semantic_DeclaringTypeOfNavigationSourceCannotHavePathProperty=The declaring type '{0}' of {1} '{2}' cannot include path type property.
EdmModel_Validator_Semantic_TypeOfNavigationPropertyCannotHavePathProperty=The type '{0}' of navigation property '{1}' on declaring type '{2}' cannot include path type property.

;Error message for Syntactic validation rules
EdmModel_Validator_Syntactic_MissingName=The name is missing or not valid.
Expand Down
65 changes: 64 additions & 1 deletion src/Microsoft.OData.Edm/Parameterized.Microsoft.OData.Edm.cs
Expand Up @@ -25,7 +25,7 @@ internal static class Strings {
}

/// <summary>
/// A string like "Unexpected abstract type kind."
/// A string like "Unexpected path type kind."
/// </summary>
internal static string EdmPath_UnexpectedKind {
get {
Expand Down Expand Up @@ -642,6 +642,20 @@ internal static class Strings {
return Microsoft.OData.Edm.EntityRes.GetString(Microsoft.OData.Edm.EntityRes.EdmModel_Validator_Semantic_KeyPropertyMustBelongToEntity, p0, p1);
}

/// <summary>
/// A string like "The 'Edm.PrimitiveType' cannot be used as the type of a key property '{0}' of an entity type '{1}'."
/// </summary>
internal static string EdmModel_Validator_Semantic_EdmPrimitiveTypeCannotBeUsedAsTypeOfKey(object p0, object p1) {
return Microsoft.OData.Edm.EntityRes.GetString(Microsoft.OData.Edm.EntityRes.EdmModel_Validator_Semantic_EdmPrimitiveTypeCannotBeUsedAsTypeOfKey, p0, p1);
}

/// <summary>
/// A string like "The 'Edm.PrimitiveType' cannot be used as the underlying type of '{0}' type '{1}'."
/// </summary>
internal static string EdmModel_Validator_Semantic_EdmPrimitiveTypeCannotBeUsedAsUnderlyingType(object p0, object p1) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like p0 is always "type definition" only one argument typeDefinition.FullName() is needed?
Please check the chained definitions as well.

Copy link
Member Author

@xuzhg xuzhg Feb 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can be used as "enumeration type" as well.
The rule is:
*The 'Edm.PrimitiveType' cannot be used as the underlying type of type definition or enumeration type. *

return Microsoft.OData.Edm.EntityRes.GetString(Microsoft.OData.Edm.EntityRes.EdmModel_Validator_Semantic_EdmPrimitiveTypeCannotBeUsedAsUnderlyingType, p0, p1);
}

/// <summary>
/// A string like "The dependent property '{0}' must belong to the dependent entity '{1}'."
/// </summary>
Expand Down Expand Up @@ -1163,6 +1177,55 @@ internal static class Strings {
return Microsoft.OData.Edm.EntityRes.GetString(Microsoft.OData.Edm.EntityRes.EdmModel_Validator_Semantic_NavigationPropertyOfCollectionTypeMustNotTargetToSingleton, p0, p1);
}

/// <summary>
/// A string like "The type '{0}' cannot be the base type of an '{1}' type '{2}'."
/// </summary>
internal static string EdmModel_Validator_Semantic_StructuredTypeBaseTypeCannotBeAbstractType(object p0, object p1, object p2) {
return Microsoft.OData.Edm.EntityRes.GetString(Microsoft.OData.Edm.EntityRes.EdmModel_Validator_Semantic_StructuredTypeBaseTypeCannotBeAbstractType, p0, p1, p2);
}

/// <summary>
/// A string like "The type '{0}' cannot be used as the type of a property '{1}'."
/// </summary>
internal static string EdmModel_Validator_Semantic_PropertyTypeCannotBeCollectionOfAbstractType(object p0, object p1) {
return Microsoft.OData.Edm.EntityRes.GetString(Microsoft.OData.Edm.EntityRes.EdmModel_Validator_Semantic_PropertyTypeCannotBeCollectionOfAbstractType, p0, p1);
}

/// <summary>
/// A string like "The type '{0}' cannot be used as the return type of a function '{1}'."
/// </summary>
internal static string EdmModel_Validator_Semantic_OperationReturnTypeCannotBeCollectionOfAbstractType(object p0, object p1) {
return Microsoft.OData.Edm.EntityRes.GetString(Microsoft.OData.Edm.EntityRes.EdmModel_Validator_Semantic_OperationReturnTypeCannotBeCollectionOfAbstractType, p0, p1);
}

/// <summary>
/// A string like "The type 'Edm.EntityType' cannot be used as the type of a singleton '{0}' in an entity container."
/// </summary>
internal static string EdmModel_Validator_Semantic_EdmEntityTypeCannotBeTypeOfSingleton(object p0) {
return Microsoft.OData.Edm.EntityRes.GetString(Microsoft.OData.Edm.EntityRes.EdmModel_Validator_Semantic_EdmEntityTypeCannotBeTypeOfSingleton, p0);
}

/// <summary>
/// A string like "The type 'Edm.EntityType' cannot be used as the type of an entity set '{0}' in an entity container."
/// </summary>
internal static string EdmModel_Validator_Semantic_EdmEntityTypeCannotBeTypeOfEntitySet(object p0) {
return Microsoft.OData.Edm.EntityRes.GetString(Microsoft.OData.Edm.EntityRes.EdmModel_Validator_Semantic_EdmEntityTypeCannotBeTypeOfEntitySet, p0);
}

/// <summary>
/// A string like "The declaring type '{0}' of {1} '{2}' cannot include path type property."
/// </summary>
internal static string EdmModel_Validator_Semantic_DeclaringTypeOfNavigationSourceCannotHavePathProperty(object p0, object p1, object p2) {
return Microsoft.OData.Edm.EntityRes.GetString(Microsoft.OData.Edm.EntityRes.EdmModel_Validator_Semantic_DeclaringTypeOfNavigationSourceCannotHavePathProperty, p0, p1, p2);
}

/// <summary>
/// A string like "The type '{0}' of navigation property '{1}' on declaring type '{2}' cannot include path type property."
/// </summary>
internal static string EdmModel_Validator_Semantic_TypeOfNavigationPropertyCannotHavePathProperty(object p0, object p1, object p2) {
return Microsoft.OData.Edm.EntityRes.GetString(Microsoft.OData.Edm.EntityRes.EdmModel_Validator_Semantic_TypeOfNavigationPropertyCannotHavePathProperty, p0, p1, p2);
}

/// <summary>
/// A string like "The name is missing or not valid."
/// </summary>
Expand Down