Repository navigation
Uri parsing on type cast on property allowed in validation vocabulary - #1295
Conversation
e96f5ce to
2bc0559
Compare
| if (annotation != null) | ||
| { | ||
| IEdmCollectionExpression collectionExpression = annotation.Value as IEdmCollectionExpression; | ||
| if (collectionExpression != null && collectionExpression.Elements != null) |
There was a problem hiding this comment.
collectionExpression.Elements != null [](start = 52, length = 37)
It should be legal to have the annotation with an empty list of derived types, in which case the type of the element must be exactly the expected type (no derived types allowed). Can we add a test for this case? #Closed
There was a problem hiding this comment.
Thanks. I added a new test. Please take a look. #Closed
| } | ||
| } | ||
|
|
||
| private static void CheckTypeCastSegmentRestrictions(IEdmModel model, ODataPathSegment previous, IEdmType targetEdmType) |
There was a problem hiding this comment.
CheckTypeCastSegmentRestrictions [](start = 28, length = 32)
Note; this doesn't support scenarios where the immediately previous segment was not a property or a navigation property; for example, Customers/1/ns.PreferredCustomer. Probably okay just to note this in the code.
There was a problem hiding this comment.
Thanks @mikepizzo .
I noticed the "AppliesTo" includes the "TypeDefinnition" as below:
<Term Name="DerivedTypeConstraint" Type="Collection(Core.QualifiedTypeName)" Nullable="false" AppliesTo="Property TypeDefinition">What does it mean for 'TypeDefinition'? #Closed
There was a problem hiding this comment.
If the underlying type of the TypeDefinition is Edm.Primitive, then the DerivedTypeConstraint can be used to restrict the set of primitive types (i.e., to string and int). If the DerivedTypeConstraint is defined on both a TypeDefinition and a Property where that DerivedTypeConstraint is used, then only those types that are in both lists are valid.
In reply to: 227070272 [](ancestors = 227070272)
There was a problem hiding this comment.
@mikepizzo Thanks for the explanation. In this PR, i left some commented codes for type definition, because ODL doesn't support the Uri parse for the type definition, see issue at: #1326. So, i will un-comment type definition codes after i fix #1326. Is it ok? #Closed
b9b3c8b to
aad6983
Compare
e173037 to
0b17729
Compare
0b17729 to
d59865b
Compare
| { | ||
| Debug.Assert(operation != null); | ||
|
|
||
| if (this.parsedSegments == null || !this.parsedSegments.Any()) |
There was a problem hiding this comment.
|| !this.parsedSegments.Any() [](start = 44, length = 29)
|| !this.parsedSegments.Any() [](start = 44, length = 29)
This would also be caught in the this.parsedSegments.LastOrDefault() check on line 1546 below, right? #Closed
There was a problem hiding this comment.
Yes. You are right. #Closed
| } | ||
| } | ||
|
|
||
| private void CheckTypeCastSegmentRestriction(ODataPathSegment previous, IEdmType targetEdmType) |
There was a problem hiding this comment.
CheckTypeCastSegmentRestriction [](start = 21, length = 31)
We should also validate, if the previous segment is an operation, that the return type of the operation can be cast to the specified type.
There was a problem hiding this comment.
@mikepizzo I saw you closed the related issues (#52) as not-fixed. But, how to annotation the ReturnType of the operation?
There was a problem hiding this comment.
Separate offline discussion on how to support annotating ReturnType.
In reply to: 236788996 [](ancestors = 236788996)
| /// The model referenced to. | ||
| /// The target annotatable to find annotation. | ||
|
/// |
||
|
public static IList |
There was a problem hiding this comment.
IList [](start = 22, length = 5)
IList [](start = 22, length = 5)
Should this be an IEnumerable, rather than an IList? We don't expect the caller to add/remove from the list. #Closed
There was a problem hiding this comment.
Yes. # Fixed. #Closed
d59865b to
8d3fbe8
Compare
| [ | ||
| ExtensionAttribute(), | ||
| ] | ||
| public static System.Collections.Generic.IList`1[[System.String]] GetDerivedTypeConstraints (Microsoft.OData.Edm.IEdmModel model, Microsoft.OData.Edm.Vocabularies.IEdmVocabularyAnnotatable target) |
There was a problem hiding this comment.
IList [](start = 42, length = 5)
IList [](start = 42, length = 5)
This should be updated to IEnumerable rather than IList as per the updated code. #Closed
| PathParser_CannotUseValueOnCollection=$value cannot be applied to a collection. | ||
| PathParser_TypeMustBeRelatedToSet=The type '{0}' does not inherit from and is not a base type of '{1}'. The type of '{2}' must be related to the Type of the EntitySet. | ||
| PathParser_TypeCastOnlyAllowedAfterStructuralCollection=Type cast segment '{0}' after a collection which is not of entity or complex type is not allowed. | ||
| PathParser_TypeCastOnlyAllowedInDerivedTypeConstraint=Type cast segment '{0}' on {1} '{2}' is not allowed from the Org.OData.Validation.V1.DerivedTypeConstraint annotation. |
There was a problem hiding this comment.
from the [](start = 106, length = 8)
how about "due to an"
1. Type cast on singleton: ~/Me/NS.Cast 2. Type cast on entity set: /Users/NS.Cast 3. Type cast on entity: ~/users(1)/NS.Cast 4. Type cast on property: ~/user(1)/property/NS.Cast 5. Type cast on navigation property: ~/users(1)/navigationproperty/NS.Cast 6. Type cast on binding parameter
546c326 to
be845a3
Compare
be845a3 to
c9c9cea
Compare
Issues
This pull request is part of Union type supporting.
Description
Checklist (Uncheck if it is not completed)
Additional work necessary
If documentation update is needed, please add "Docs Needed" label to the issue and provide details about the required document change in the issue.