Skip to content
Open
Show file tree
Hide file tree
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
Expand Up @@ -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]
Expand Down
3 changes: 2 additions & 1 deletion examples/AspNetCore/OData/ODataBasicExample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
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
Expand Up @@ -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
Expand Up @@ -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
Expand All @@ -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];

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

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

if ( metadataController == null )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}" );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
}
Expand All @@ -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 ) )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down
Loading