Skip to content

Commit

Permalink
#1208 Support relative context URI starting with "$metadata" (#2313)
Browse files Browse the repository at this point in the history
  • Loading branch information
nobyk authored Feb 21, 2022
1 parent 9770082 commit 511895d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,12 @@ internal void ReadPayloadStart(
{
// If the Base uri string is http://odata.org/test
// The MetadataDocumentUri will be http://odata.org/test/$metadata
// If the contextUriAnnotation value is Customers(1)/Name
// If the contextUriAnnotation value is Customers(1)/Name or $metadata#Customers(1)/Name
// The generated context uri will be http://odata.org/test/$metadata#Customers(1)/Name
ODataUri oDataUri = new ODataUri() { ServiceRoot = this.BaseUri };
contextUriAnnotationValue = oDataUri.MetadataDocumentUri.ToString() + ODataConstants.ContextUriFragmentIndicator + contextUriAnnotationValue;
contextUriAnnotationValue = contextUriAnnotationValue.StartsWith("$metadata#", StringComparison.OrdinalIgnoreCase)
? this.BaseUri + contextUriAnnotationValue
: oDataUri.MetadataDocumentUri.ToString() + ODataConstants.ContextUriFragmentIndicator + contextUriAnnotationValue;
}

ODataJsonLightContextUriParseResult parseResult = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,12 @@ public void TopLevelPropertyShouldReadContextUriAsRelativeUri()

Assert.NotNull(property);
Assert.Equal("http://odata.org/test/$metadata#Customers(1)/Name", deserializer.ContextUriParseResult.ContextUri.ToString());

deserializer = new ODataJsonLightPropertyAndValueDeserializer(this.CreateJsonLightInputContext("{\"@odata.context\":\"$metadata#Customers(1)/Name\",\"value\":\"Joe\"}", model));
property = deserializer.ReadTopLevelProperty(primitiveTypeRef);

Assert.NotNull(property);
Assert.Equal("http://odata.org/test/$metadata#Customers(1)/Name", deserializer.ContextUriParseResult.ContextUri.ToString());
}


Expand Down

0 comments on commit 511895d

Please sign in to comment.