Skip to content

Commit

Permalink
Merged PR 426996: Revert "Context url for expand (OData#1286)"
Browse files Browse the repository at this point in the history
Revert "Context url for expand (OData#1286)"

This reverts commit ec6fb33.

Original PR not only modified how @odata.context formed for v4.0 and v4.01, but also removed a lot of version recognition code. That makes it’s pretty difficult to do conditionally.

Please, keep in mind that default protocol version is v4.0 and client had to say that it wants v4.01. In AX I'm going to add telemetry to allow us to see what clients asked for

Related work items: #1426955
  • Loading branch information
kosinsky committed Jan 23, 2019
2 parents ce45856 + 46a9b53 commit 77da45b
Show file tree
Hide file tree
Showing 34 changed files with 252 additions and 517 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, this.CurrentResourceType, this.jsonLightInputContext.Model);
SelectedPropertiesNode selectedProperties = SelectedPropertiesNode.Create(selectQueryOption);

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(), new SelectedPropertiesNode(SelectedPropertiesNode.SelectionType.EntireSubtree));
this.ReadResourceSetStart(new ODataResourceSet(), SelectedPropertiesNode.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 = new SelectedPropertiesNode(SelectedPropertiesNode.SelectionType.EntireSubtree);
SelectedPropertiesNode selectedProperties = SelectedPropertiesNode.EntireSubtree;
ODataDeltaResourceSet deltaResourceSet = nestedResourceInfo.NestedResourceSet as ODataDeltaResourceSet;
if (deltaResourceSet != null)
{
Expand Down
23 changes: 17 additions & 6 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);
return CreateSelectExpandContextUriSegment(odataUri.SelectAndExpand, version);
}
}

Expand Down Expand Up @@ -379,13 +379,14 @@ 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)
private static string CreateSelectExpandContextUriSegment(SelectExpandClause selectExpandClause, ODataVersion version)
{
if (selectExpandClause != null)
{
string contextUri;
selectExpandClause.Traverse(ProcessSubExpand, CombineSelectAndExpandResult, out contextUri);
selectExpandClause.Traverse(ProcessSubExpand, CombineSelectAndExpandResult, version, out contextUri);
if (!string.IsNullOrEmpty(contextUri))
{
return ODataConstants.ContextUriProjectionStart + contextUri + ODataConstants.ContextUriProjectionEnd;
Expand All @@ -398,11 +399,12 @@ 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)
private static string ProcessSubExpand(string expandNode, string subExpand, ODataVersion version)
{

return expandNode + ODataConstants.ContextUriProjectionStart + subExpand + ODataConstants.ContextUriProjectionEnd;
return string.IsNullOrEmpty(subExpand) && version <= ODataVersion.V4 ? null :
expandNode + ODataConstants.ContextUriProjectionStart + subExpand + ODataConstants.ContextUriProjectionEnd;
}

/// <summary>Create combined result string using selected items list and expand items list.</summary>
Expand All @@ -415,6 +417,15 @@ 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 @@ -292,8 +292,8 @@ internal SelectedPropertiesNode SelectedProperties
get
{
return this.SelectExpandClause != null
? SelectedPropertiesNode.Create(this.SelectExpandClause)
: new SelectedPropertiesNode(SelectedPropertiesNode.SelectionType.EntireSubtree);
? SelectedPropertiesNode.Create(this.SelectExpandClause, this.Version ?? ODataVersion.V4)
: SelectedPropertiesNode.EntireSubtree;
}
}

Expand Down
Loading

0 comments on commit 77da45b

Please sign in to comment.