Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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 = "[email protected]",
Phone = "555-555-5555",
},
new() {
Id = 2,
FirstName = "Xavier",
LastName = "John",
Email = "[email protected]",
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see how this file is necessary at all. The OpenAPI example supplants the need for it. While I'm not completely opposed to the idea, this file just feels one-off and out of sync with the other examples. I'm not convinced this is worth keeping - yet.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using .http file is the easiest way to make API calls and view the results.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree. Running the OpenAPI examples are. This is highly inconsistent. Why just this one? Are you going to go add these for all example projects?


// 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