Skip to content

Commit

Permalink
Add a IsConventaional flag in routing metadata (#650)
Browse files Browse the repository at this point in the history
* Add a IsConventaional flag in routing metadata

* fix the failing public API test
  • Loading branch information
xuzhg authored Aug 5, 2022
1 parent 0feec0a commit f1db770
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 17 deletions.
40 changes: 26 additions & 14 deletions src/Microsoft.AspNetCore.OData/Microsoft.AspNetCore.OData.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1094,20 +1094,6 @@
<param name="clrType">The type to test.</param>
<returns>True if the type is a DateTime; false otherwise.</returns>
</member>
<member name="M:Microsoft.AspNetCore.OData.Common.TypeHelper.IsDateOnly(System.Type)">
<summary>
Determine if a type is a <see cref="T:System.DateOnly"/>.
</summary>
<param name="clrType">The type to test.</param>
<returns>True if the type is a DateOnly; false otherwise.</returns>
</member>
<member name="M:Microsoft.AspNetCore.OData.Common.TypeHelper.IsTimeOnly(System.Type)">
<summary>
Determine if a type is a <see cref="T:System.TimeOnly"/>.
</summary>
<param name="clrType">The type to test.</param>
<returns>True if the type is a TimeOnly; false otherwise.</returns>
</member>
<member name="M:Microsoft.AspNetCore.OData.Common.TypeHelper.IsTimeSpan(System.Type)">
<summary>
Determine if a type is a TimeSpan.
Expand Down Expand Up @@ -12798,6 +12784,11 @@
Gets the OData path template
</summary>
</member>
<member name="P:Microsoft.AspNetCore.OData.Routing.IODataRoutingMetadata.IsConventional">
<summary>
Gets the boolean value indicating whether it's from OData conventional routing, false means from attribute routing.
</summary>
</member>
<member name="T:Microsoft.AspNetCore.OData.Routing.ODataPathExtensions">
<summary>
Extension methods for <see cref="T:Microsoft.OData.UriParser.ODataPath"/>.
Expand Down Expand Up @@ -13258,6 +13249,11 @@
Gets the OData path template
</summary>
</member>
<member name="P:Microsoft.AspNetCore.OData.Routing.ODataRoutingMetadata.IsConventional">
<summary>
Gets or sets a boolean value indicating from odata conventional routing.
</summary>
</member>
<member name="T:Microsoft.AspNetCore.OData.Routing.ODataSegmentKinds">
<summary>
Provides the values of segment kinds for implementations of odata path template.
Expand Down Expand Up @@ -14386,3 +14382,19 @@
</member>
</members>
</doc>
ummary>
<param name="segment">The value segment.</param>
</member>
<member name="P:Microsoft.AspNetCore.OData.Routing.Template.ValueSegmentTemplate.Segment">
<summary>
Gets the value segment.
</summary>
</member>
<member name="M:Microsoft.AspNetCore.OData.Routing.Template.ValueSegmentTemplate.GetTemplates(Microsoft.AspNetCore.OData.Routing.ODataRouteOptions)">
<inheritdoc />
</member>
<member name="M:Microsoft.AspNetCore.OData.Routing.Template.ValueSegmentTemplate.TryTranslate(Microsoft.AspNetCore.OData.Routing.Template.ODataTemplateTranslateContext)">
<inheritdoc />
</member>
</members>
</doc>
3 changes: 3 additions & 0 deletions src/Microsoft.AspNetCore.OData/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1236,6 +1236,7 @@ Microsoft.AspNetCore.OData.Routing.Conventions.SingletonRoutingConvention
Microsoft.AspNetCore.OData.Routing.Conventions.SingletonRoutingConvention.AppliesToAction(Microsoft.AspNetCore.OData.Routing.Conventions.ODataControllerActionContext context) -> bool
Microsoft.AspNetCore.OData.Routing.Conventions.SingletonRoutingConvention.SingletonRoutingConvention() -> void
Microsoft.AspNetCore.OData.Routing.IODataRoutingMetadata
Microsoft.AspNetCore.OData.Routing.IODataRoutingMetadata.IsConventional.get -> bool
Microsoft.AspNetCore.OData.Routing.IODataRoutingMetadata.Model.get -> Microsoft.OData.Edm.IEdmModel
Microsoft.AspNetCore.OData.Routing.IODataRoutingMetadata.Prefix.get -> string
Microsoft.AspNetCore.OData.Routing.IODataRoutingMetadata.Template.get -> Microsoft.AspNetCore.OData.Routing.Template.ODataPathTemplate
Expand Down Expand Up @@ -1269,6 +1270,8 @@ Microsoft.AspNetCore.OData.Routing.ODataRouteOptions.EnableUnqualifiedOperationC
Microsoft.AspNetCore.OData.Routing.ODataRouteOptions.EnableUnqualifiedOperationCall.set -> void
Microsoft.AspNetCore.OData.Routing.ODataRouteOptions.ODataRouteOptions() -> void
Microsoft.AspNetCore.OData.Routing.ODataRoutingMetadata
Microsoft.AspNetCore.OData.Routing.ODataRoutingMetadata.IsConventional.get -> bool
Microsoft.AspNetCore.OData.Routing.ODataRoutingMetadata.IsConventional.set -> void
Microsoft.AspNetCore.OData.Routing.ODataRoutingMetadata.Model.get -> Microsoft.OData.Edm.IEdmModel
Microsoft.AspNetCore.OData.Routing.ODataRoutingMetadata.ODataRoutingMetadata(string prefix, Microsoft.OData.Edm.IEdmModel model, Microsoft.AspNetCore.OData.Routing.Template.ODataPathTemplate template) -> void
Microsoft.AspNetCore.OData.Routing.ODataRoutingMetadata.Prefix.get -> string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,11 @@ private SelectorModel CreateActionSelectorModel(string prefix, IEdmModel model,
ClearMetadata(newSelectorModel);

// Add OData routing metadata
ODataRoutingMetadata odataMetadata = new ODataRoutingMetadata(prefix, model, pathTemplate);
ODataRoutingMetadata odataMetadata = new ODataRoutingMetadata(prefix, model, pathTemplate)
{
IsConventional = false
};

newSelectorModel.EndpointMetadata.Add(odataMetadata);

// replace the attribute routing template using absolute routing template to avoid appending any controller route template
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,10 @@ public interface IODataRoutingMetadata
/// Gets the OData path template
/// </summary>
ODataPathTemplate Template { get; }

/// <summary>
/// Gets the boolean value indicating whether it's from OData conventional routing, false means from attribute routing.
/// </summary>
bool IsConventional { get; }
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// <copyright file="ODataRouteDebugMiddleware.cs" company=".NET Foundation">
// Copyright (c) .NET Foundation and Contributors. All rights reserved.
// See License.txt in the project root for license information.
Expand Down Expand Up @@ -107,6 +107,7 @@ internal static IList<EndpointRouteInfo> GetRouteInfo(HttpContext context)
HttpMethods = endpoint.Metadata.GetMetadata<HttpMethodMetadata>()?.HttpMethods ?? EmptyHeaders,
Pattern = routeEndpoint?.RoutePattern?.RawText ?? "N/A",
IsODataRoute = metadata != null,
IsConventional = metadata != null ? metadata.IsConventional : false
};

routInfoList.Add(info);
Expand Down Expand Up @@ -183,6 +184,13 @@ private static void AppendRoute(StringBuilder builder, EndpointRouteInfo routeIn
{
builder.Append($"<td>{routeInfo.Pattern}</td>");
}

if (routeInfo.IsODataRoute)
{
var isConventional = routeInfo.IsConventional ? "Yes" : "-";
builder.Append($"<td>{isConventional}</td>");
}

builder.AppendLine("</tr>");
}

Expand Down Expand Up @@ -216,7 +224,8 @@ private static void AppendRoute(StringBuilder builder, EndpointRouteInfo routeIn
<tr>
<th> Controller & Action </th>
<th> HttpMethods </th>
<th> Template </th>
<th> Template </th>
<th> IsConventional </th>
</tr>
ODATA_ROUTE_CONTENT
</table>
Expand Down Expand Up @@ -244,6 +253,8 @@ internal class EndpointRouteInfo
public string Pattern { get; set; }

public bool IsODataRoute { get; set; }

public bool IsConventional { get; set; }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,10 @@ internal ODataRoutingMetadata()
/// Gets the OData path template
/// </summary>
public ODataPathTemplate Template { get; }

/// <summary>
/// Gets or sets a boolean value indicating from odata conventional routing.
/// </summary>
public bool IsConventional { get; set; } = true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1723,6 +1723,7 @@ public sealed class Microsoft.AspNetCore.OData.Results.SingleResult`1 : Microsof
}

public interface Microsoft.AspNetCore.OData.Routing.IODataRoutingMetadata {
bool IsConventional { public abstract get; }
Microsoft.OData.Edm.IEdmModel Model { public abstract get; }
string Prefix { public abstract get; }
Microsoft.AspNetCore.OData.Routing.Template.ODataPathTemplate Template { public abstract get; }
Expand Down Expand Up @@ -1849,6 +1850,7 @@ public class Microsoft.AspNetCore.OData.Routing.ODataRouteOptions {
public sealed class Microsoft.AspNetCore.OData.Routing.ODataRoutingMetadata : IODataRoutingMetadata {
public ODataRoutingMetadata (string prefix, Microsoft.OData.Edm.IEdmModel model, Microsoft.AspNetCore.OData.Routing.Template.ODataPathTemplate template)

bool IsConventional { public virtual get; public set; }
Microsoft.OData.Edm.IEdmModel Model { public virtual get; }
string Prefix { public virtual get; }
Microsoft.AspNetCore.OData.Routing.Template.ODataPathTemplate Template { public virtual get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1723,6 +1723,7 @@ public sealed class Microsoft.AspNetCore.OData.Results.SingleResult`1 : Microsof
}

public interface Microsoft.AspNetCore.OData.Routing.IODataRoutingMetadata {
bool IsConventional { public abstract get; }
Microsoft.OData.Edm.IEdmModel Model { public abstract get; }
string Prefix { public abstract get; }
Microsoft.AspNetCore.OData.Routing.Template.ODataPathTemplate Template { public abstract get; }
Expand Down Expand Up @@ -1849,6 +1850,7 @@ public class Microsoft.AspNetCore.OData.Routing.ODataRouteOptions {
public sealed class Microsoft.AspNetCore.OData.Routing.ODataRoutingMetadata : IODataRoutingMetadata {
public ODataRoutingMetadata (string prefix, Microsoft.OData.Edm.IEdmModel model, Microsoft.AspNetCore.OData.Routing.Template.ODataPathTemplate template)

bool IsConventional { public virtual get; public set; }
Microsoft.OData.Edm.IEdmModel Model { public virtual get; }
string Prefix { public virtual get; }
Microsoft.AspNetCore.OData.Routing.Template.ODataPathTemplate Template { public virtual get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1723,6 +1723,7 @@ public sealed class Microsoft.AspNetCore.OData.Results.SingleResult`1 : Microsof
}

public interface Microsoft.AspNetCore.OData.Routing.IODataRoutingMetadata {
bool IsConventional { public abstract get; }
Microsoft.OData.Edm.IEdmModel Model { public abstract get; }
string Prefix { public abstract get; }
Microsoft.AspNetCore.OData.Routing.Template.ODataPathTemplate Template { public abstract get; }
Expand Down Expand Up @@ -1849,6 +1850,7 @@ public class Microsoft.AspNetCore.OData.Routing.ODataRouteOptions {
public sealed class Microsoft.AspNetCore.OData.Routing.ODataRoutingMetadata : IODataRoutingMetadata {
public ODataRoutingMetadata (string prefix, Microsoft.OData.Edm.IEdmModel model, Microsoft.AspNetCore.OData.Routing.Template.ODataPathTemplate template)

bool IsConventional { public virtual get; public set; }
Microsoft.OData.Edm.IEdmModel Model { public virtual get; }
string Prefix { public virtual get; }
Microsoft.AspNetCore.OData.Routing.Template.ODataPathTemplate Template { public virtual get; }
Expand Down

0 comments on commit f1db770

Please sign in to comment.