Skip to content

Commit

Permalink
Context url for expand (#1286)
Browse files Browse the repository at this point in the history
* Set the selectionType to EntireSubtree when the selected list contains only expand tokens.

* For $expand, add navProp() to context-url.

* ABNF v4; ensure explicit select; don't add link for expand to select items.

* Resolve CR comments.
- cleanups
- Create SelectedPropertiesnode based on AllSelected values of current level and expanded nav properties.

* Update for navProp token resolution logic per CR comments; cleanups
  • Loading branch information
biaol-odata committed Nov 20, 2018
1 parent 43ffb7f commit 8e29332
Show file tree
Hide file tree
Showing 34 changed files with 517 additions and 252 deletions.
6 changes: 3 additions & 3 deletions src/Microsoft.OData.Core/JsonLight/ODataJsonLightReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@ private bool ReadAtStartImplementationSynchronously(
? null
: this.jsonLightResourceDeserializer.ContextUriParseResult.SelectQueryOption;

SelectedPropertiesNode selectedProperties = SelectedPropertiesNode.Create(selectQueryOption);
SelectedPropertiesNode selectedProperties = SelectedPropertiesNode.Create(selectQueryOption, this.CurrentResourceType, this.jsonLightInputContext.Model);

if (this.ReadingResourceSet)
{
Expand Down Expand Up @@ -1493,7 +1493,7 @@ private void ReadNextResourceSetItem()
break;
case JsonNodeType.StartArray:
// we are at the start of a nested resource set
this.ReadResourceSetStart(new ODataResourceSet(), SelectedPropertiesNode.EntireSubtree);
this.ReadResourceSetStart(new ODataResourceSet(), new SelectedPropertiesNode(SelectedPropertiesNode.SelectionType.EntireSubtree));
break;
case JsonNodeType.EndArray:
// we are at the end of a resource set
Expand Down Expand Up @@ -1925,7 +1925,7 @@ private void ReadNextNestedResourceInfoContentItemInRequest()
if (nestedResourceInfo.NestedResourceInfo.IsCollection == true)
{
// because this is a request, there is no $select query option.
SelectedPropertiesNode selectedProperties = SelectedPropertiesNode.EntireSubtree;
SelectedPropertiesNode selectedProperties = new SelectedPropertiesNode(SelectedPropertiesNode.SelectionType.EntireSubtree);
ODataDeltaResourceSet deltaResourceSet = nestedResourceInfo.NestedResourceSet as ODataDeltaResourceSet;
if (deltaResourceSet != null)
{
Expand Down
23 changes: 6 additions & 17 deletions src/Microsoft.OData.Core/ODataContextUrlInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ private static string ComputeQueryClause(ODataUri odataUri, ODataVersion version
}
else
{
return CreateSelectExpandContextUriSegment(odataUri.SelectAndExpand, version);
return CreateSelectExpandContextUriSegment(odataUri.SelectAndExpand);
}
}

Expand Down Expand Up @@ -379,14 +379,13 @@ private static string CreateApplyUriSegment(ApplyClause applyClause)
/// Build the expand clause for a given level in the selectExpandClause
/// </summary>
/// <param name="selectExpandClause">the current level select expand clause</param>
/// <param name="version">OData Version of the response</param>
/// <returns>the select and expand segment for context url in this level.</returns>
private static string CreateSelectExpandContextUriSegment(SelectExpandClause selectExpandClause, ODataVersion version)
private static string CreateSelectExpandContextUriSegment(SelectExpandClause selectExpandClause)
{
if (selectExpandClause != null)
{
string contextUri;
selectExpandClause.Traverse(ProcessSubExpand, CombineSelectAndExpandResult, version, out contextUri);
selectExpandClause.Traverse(ProcessSubExpand, CombineSelectAndExpandResult, out contextUri);
if (!string.IsNullOrEmpty(contextUri))
{
return ODataConstants.ContextUriProjectionStart + contextUri + ODataConstants.ContextUriProjectionEnd;
Expand All @@ -399,12 +398,11 @@ private static string CreateSelectExpandContextUriSegment(SelectExpandClause sel
/// <summary>Process sub expand node, contact with subexpand result</summary>
/// <param name="expandNode">The current expanded node.</param>
/// <param name="subExpand">Generated sub expand node.</param>
/// <param name="version">OData Version of the generated response.</param>
/// <returns>The generated expand string.</returns>
private static string ProcessSubExpand(string expandNode, string subExpand, ODataVersion version)
private static string ProcessSubExpand(string expandNode, string subExpand)
{
return string.IsNullOrEmpty(subExpand) && version <= ODataVersion.V4 ? null :
expandNode + ODataConstants.ContextUriProjectionStart + subExpand + ODataConstants.ContextUriProjectionEnd;

return expandNode + ODataConstants.ContextUriProjectionStart + subExpand + ODataConstants.ContextUriProjectionEnd;
}

/// <summary>Create combined result string using selected items list and expand items list.</summary>
Expand All @@ -417,15 +415,6 @@ private static string CombineSelectAndExpandResult(IList<string> selectList, ILi

if (selectList.Any())
{
// https://github.com/OData/odata.net/issues/1104
// If the user explicitly selects and expands a nav prop, we should include both forms in contextUrl
// We can't, though, because SelectExpandClauseFinisher.AddExplicitNavPropLinksWhereNecessary adds all of
// the expanded items to the select before it gets here, so we can't tell what is explicitly selected by the user.
foreach (var item in expandList)
{
string expandNode = item.Substring(0, item.IndexOf(ODataConstants.ContextUriProjectionStart));
selectList.Remove(expandNode);
}

currentExpandClause += String.Join(ODataConstants.ContextUriProjectionPropertySeparator, selectList.ToArray());
}
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.OData.Core/ODataMessageWriterSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,8 @@ internal SelectedPropertiesNode SelectedProperties
get
{
return this.SelectExpandClause != null
? SelectedPropertiesNode.Create(this.SelectExpandClause, this.Version ?? ODataVersion.V4)
: SelectedPropertiesNode.EntireSubtree;
? SelectedPropertiesNode.Create(this.SelectExpandClause)
: new SelectedPropertiesNode(SelectedPropertiesNode.SelectionType.EntireSubtree);
}
}

Expand Down
Loading

0 comments on commit 8e29332

Please sign in to comment.