-
Notifications
You must be signed in to change notification settings - Fork 349
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
fixes #2785: support property instance annotation without property value #2786
Conversation
ExpectedException = tc.Format == ODataFormat.Json | ||
? ODataExpectedExceptions.ODataException("ODataJsonLightResourceDeserializer_PropertyWithoutValueWithWrongType", "NonStreamProperty", "Edm.Boolean") | ||
: ODataExpectedExceptions.ODataException("JsonReaderExtensions_UnexpectedNodeDetected", "PrimitiveValue", "StartObject") | ||
//ExpectedException = tc.Format == ODataFormat.Json |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove commented code #Resolved
(tc.Format == ODataFormat.Json) | ||
? ODataExpectedExceptions.ODataException("ODataJsonLightResourceDeserializer_PropertyWithoutValueWithWrongType", "Name", "Edm.String") | ||
: ODataExpectedExceptions.ODataException("ValidationUtils_NavigationPropertyExpected", "Name", "TestModel.CityType", "Structural"), | ||
//ExpectedException = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove commented code #Resolved
Json = | ||
"\"" + JsonLightUtils.GetPropertyAnnotationName("Name", JsonLightConstants.ODataMediaEditLinkAnnotationName) + "\":\"http://odata.org/streamproperty/editlink\"", | ||
ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightResourceDeserializer_PropertyWithoutValueWithWrongType", "Name", "Edm.String"), | ||
// ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightResourceDeserializer_PropertyWithoutValueWithWrongType", "Name", "Edm.String"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove commented code #Resolved
|
||
IEdmTypeReference propertyType = property?.Type; | ||
IDictionary<string, object> odataAnnotations = resourceState.PropertyAndAnnotationCollector.GetODataPropertyAnnotations(propertyName); | ||
IList<KeyValuePair<string, object>> propertyAnnotations = resourceState.PropertyAndAnnotationCollector.GetCustomPropertyAnnotations(propertyName).ToList(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IList<KeyValuePair<string, object>> propertyAnnotations = resourceState.PropertyAndAnnotationCollector.GetCustomPropertyAnnotations(propertyName).ToList(); | |
IList<KeyValuePair<string, object>> customAnnotations = resourceState.PropertyAndAnnotationCollector.GetCustomPropertyAnnotations(propertyName).ToList(); | |
``` #Resolved |
IEdmTypeReference propertyType = property?.Type; | ||
IDictionary<string, object> odataAnnotations = resourceState.PropertyAndAnnotationCollector.GetODataPropertyAnnotations(propertyName); | ||
IList<KeyValuePair<string, object>> propertyAnnotations = resourceState.PropertyAndAnnotationCollector.GetCustomPropertyAnnotations(propertyName).ToList(); | ||
if ((odataAnnotations.Count + propertyAnnotations.Count) == 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need to do the addition while you can use:
if (odataAnnotations.Count == 0 && propertyAnnotations.Count == 0)
``` #Resolved
@@ -1706,6 +1756,7 @@ private ODataJsonLightReaderNestedInfo ReadUndeclaredProperty(IODataJsonLightRea | |||
// Property without a value can't be ignored if we don't know what it is. | |||
if (!propertyWithValue) | |||
{ | |||
// TODO: Shall we return ODataJsonLightReaderNestedPropertyInfo for a dynamic property without value? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question or gap? Do you need to create an issue to track this? #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, That's handled in Line 1752 and I should remove this comment.
}, | ||
expectedPayload); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add tests for the following code block in the ReadNestedPropertyInfoWithoutValue
method:
if ((odataAnnotations.Count + propertyAnnotations.Count) == 0)
{
// If we don't have any annotations for the property, it could contain errors.
if (property != null)
{
throw new ODataException(ODataErrorStrings.ODataJsonLightResourceDeserializer_PropertyWithoutValueWithWrongType(propertyName, propertyType.FullName()));
}
else
{
// it's a dynamic property
throw new ODataException(ODataErrorStrings.ODataJsonLightResourceDeserializer_OpenPropertyWithoutValue(propertyName));
}
}
Part of me thinks it's dead code. I don't see how we'd get here if the reader doesn't come across an OData or custom property annotation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to keep those codes; I do remember It throws exception for dynamic property.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@xuzhg If that is the case, can we add a test for that scenario?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's baffling though since property without value would be in the form of "property@custom.annotation":"#ANNOTATION_VALUE#"
or property@odata.annotation="#ANNOTATION_VALUE#"
.
I believe even in the case of dynamic property we'd have something like "dynamicproperty@custom.annotation":"#ANNOTATION_VALUE#"
or dynamicproperty@odata.annotation="#ANNOTATION_VALUE#"
.
How we'd get here only to find that odataAnnotations.Count == 0 && propertyAnnotations.Count == 0
I'm still not sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am curious about the scenario: a property:
- without value
- without odata instance annotation
- without custom instance annotation
Let me remove it and see what will happen
writer.WriteStart(resource); | ||
|
||
writer.WriteStart(propertyInfo); | ||
writer.WritePrimitive(new ODataPrimitiveValue(37)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix indentation #WontFix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indent intentionally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@xuzhg I don't think this approach is sustainable. The indentation will most probably be undone the next time VS auto-formats the contents of this file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
auto-format automatically runs? We have lots of such intentionally indent in our test codes, so far, I haven't seen any un-done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@xuzhg I meant that the next contributor who "touches" that file and triggers the formatter (which often happens), the indentation will be undone. Though I understand what you're trying to visually communicate by applying the indentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should review the chances and let the contributor to revert it.
}, | ||
expectedPayload); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@xuzhg There at least 3 places where the new ReadNestedPropertyInfoWithoutValue
is called. Do the two tests cover all 3 calls? #Pending
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean the 'readingTests.cs'?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So far, the reader tests added covers normal property and dynamic property scenarios.
But, I didn't add the test cases using Async. I tried to find a place to add 'async' test cases, but I can't find it. Do you know where or which file to add async is better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@xuzhg The async tests for ODataJsonLightReader
are here https://github.com/OData/odata.net/blob/master/test/FunctionalTests/Microsoft.OData.Core.Tests/JsonLight/ODataJsonLightReaderTests.cs.
Other async tests for ODataJsonLightResourceDeserializer
are here https://github.com/OData/odata.net/blob/master/test/FunctionalTests/Microsoft.OData.Core.Tests/JsonLight/ODataJsonLightResourceDeserializerTests.cs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gathogojr I added async test cases to verify the async scenarios. Please take a look again.
foreach (KeyValuePair<string, object> annotation in propertyAnnotations) | ||
{ | ||
// annotation.Value == null indicates that this annotation should be skipped? | ||
propertyInfo.InstanceAnnotations.Add(new ODataInstanceAnnotation(annotation.Key, annotation.Value.ToODataValue())); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@xuzhg This code for adding the custom property annotations is repeated in 3 places in the base class and now here. Wouldn't it make more sense to add a protected static
method for that - just like AttachODataAnnotations
- to avoid the code duplication? #WontFix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So far, I think the codes are only couple lines and it's easy to maintain. But, I agree if we have a helper method to maintain them together, it could be be. I'd like to leave it to a new PR to improve this.
1) there's not value 2) there's no odata instance annotation 3) There's no custom instance annotation
This PR has Quantification details
Why proper sizing of changes matters
Optimal pull request sizes drive a better predictable PR flow as they strike a
What can I do to optimize my changes
How to interpret the change counts in git diff output
Was this comment helpful? 👍 :ok_hand: :thumbsdown: (Email) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Issues
This pull request fixes #2785.
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.