Skip to content

Fix compiler and update Odata sample #1127

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -24,6 +24,13 @@ public IActionResult Get( ODataQueryOptions<Person> options ) =>
Email = "bill.mei@somewhere.com",
Phone = "555-555-5555",
},
new() {
Id = 2,
FirstName = "Xavier",
LastName = "John",
Email = "xavier@heaven.com",
Phone = "666-666-6666",
}
} );

// GET ~/api/people/{key}?api-version=[1.0|2.0]
3 changes: 2 additions & 1 deletion examples/AspNetCore/OData/ODataBasicExample/Program.cs
Original file line number Diff line number Diff line change
@@ -4,7 +4,8 @@

// Add services to the container.

builder.Services.AddControllers().AddOData();
builder.Services.AddControllers()
.AddOData( options => options.Select().Filter().OrderBy().SetMaxTop( null ).Count() );
builder.Services.AddProblemDetails();
builder.Services.AddApiVersioning()
.AddOData(
22 changes: 22 additions & 0 deletions examples/AspNetCore/OData/ODataBasicExample/odatabasicexample.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
@HostAddress = https://localhost:5001

// Get all records
GET {{HostAddress}}/api/People?api-version=1.0
Accept: application/json
###

// Get all records
GET {{HostAddress}}/api/People?api-version=1.0&$top=1
Accept: application/json
###

// Select firstName
GET {{HostAddress}}/api/People?api-version=1.0&$select=firstName
Accept: application/json
###


// By Key
GET {{HostAddress}}/api/People/5?api-version=1.0
Accept: application/json
###
Original file line number Diff line number Diff line change
@@ -13,6 +13,6 @@ private void VisitAction( HttpActionDescriptor action )
var attributes = new List<EnableQueryAttribute>( controller.GetCustomAttributes<EnableQueryAttribute>( inherit: true ) );

attributes.AddRange( action.GetCustomAttributes<EnableQueryAttribute>( inherit: true ) );
VisitEnableQuery( attributes );
VisitEnableQuery( attributes.ToArray() );
}
}
Original file line number Diff line number Diff line change
@@ -141,7 +141,7 @@ private static
return (metadataControllers, supported, deprecated);
}

private static ControllerModel? SelectBestMetadataController( IReadOnlyList<ControllerModel> controllers )
private static ControllerModel? SelectBestMetadataController( ControllerModel[] controllers )
{
// note: there should be at least 2 metadata controllers, but there could be 3+
// if a developer defines their own custom controller. ultimately, there can be
@@ -154,7 +154,7 @@ private static
var original = typeof( MetadataController ).GetTypeInfo();
var versioned = typeof( VersionedMetadataController ).GetTypeInfo();

for ( var i = 0; i < controllers.Count; i++ )
for ( var i = 0; i < controllers.Length; i++ )
{
var controller = controllers[i];

@@ -192,7 +192,7 @@ private void ApplyMetadataControllerConventions(
return;
}

var metadataController = SelectBestMetadataController( metadataControllers );
var metadataController = SelectBestMetadataController( metadataControllers.ToArray() );

if ( metadataController == null )
{
Original file line number Diff line number Diff line change
@@ -256,9 +256,9 @@ private static void AssertQueryOptionWithoutOData( ApiDescription description, s
parameter.ModelMetadata.Description.Should().EndWith( suffix + '.' );
}

private void PrintGroup( IReadOnlyList<ApiDescription> items )
private void PrintGroup( ApiDescription[] items )
{
for ( var i = 0; i < items.Count; i++ )
for ( var i = 0; i < items.Length; i++ )
{
var item = items[i];
console.WriteLine( $"[{item.GroupName}] {item.HttpMethod} {item.RelativePath}" );
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ namespace Asp.Versioning.ApplicationModels;
[CLSCompliant( false )]
public sealed class DefaultApiControllerFilter : IApiControllerFilter
{
private readonly IReadOnlyList<IApiControllerSpecification> specifications;
private readonly IApiControllerSpecification[] specifications;

/// <summary>
/// Initializes a new instance of the <see cref="DefaultApiControllerFilter"/> class.
@@ -24,7 +24,7 @@ public DefaultApiControllerFilter( IEnumerable<IApiControllerSpecification> spec
/// <inheritdoc />
public IList<ControllerModel> Apply( IList<ControllerModel> controllers )
{
if ( specifications.Count == 0 )
if ( specifications.Length == 0 )
{
return controllers;
}
@@ -44,7 +44,7 @@ public IList<ControllerModel> Apply( IList<ControllerModel> controllers )

private bool IsApiController( ControllerModel controller )
{
for ( var i = 0; i < specifications.Count; i++ )
for ( var i = 0; i < specifications.Length; i++ )
{
if ( specifications[i].IsSatisfiedBy( controller ) )
{
Original file line number Diff line number Diff line change
@@ -76,11 +76,11 @@ private void VisitModel( IEdmStructuredType modelType )
VisitMaxTop( querySettings );
}

private void VisitEnableQuery( IReadOnlyList<EnableQueryAttribute> attributes )
private void VisitEnableQuery(EnableQueryAttribute[] attributes )
{
var @default = new EnableQueryAttribute();

for ( var i = 0; i < attributes.Count; i++ )
for ( var i = 0; i < attributes.Length; i++ )
{
var attribute = attributes[i];