aspnet-api-versioning icon indicating copy to clipboard operation
aspnet-api-versioning copied to clipboard

ODataModelBuilder EntitySet.EntityType.Page() does not result in $top or $skip params being included in ApiExplorer (Swagger)

Open engenb opened this issue 4 years ago • 4 comments
trafficstars

Hello again,

Been appreciating the help I've been getting so far! Two issues here which I can split if that's more helpful.

The main issue (for which I don't have a workaround) is when I configure an EntityTypeConfiguration with .Page(), the corresponding $top and $skip query parameters are not presented in the ApiExplorer/Swagger.

var fooType = builder.EntitySet<Foo>("Foos").EntityType;

fooType.HasMany(x => x.Bars);

fooType.HasKey(x => x.Id)
	.Count()
	.Page()
	.Select()
	.Filter()
	.Expand(SelectExpandType.Allowed)
	.OrderBy();

...

[ApiVersion("1")]
[ODataRoutePrefix("Foos")]
[Consumes("application/json")]
[Produces("application/json")]
public class FoosController : ODataController
{		
	[HttpGet]
	[ODataRoute]
	[Produces("application/json")]
	[ProducesResponseType(typeof(ODataValue<IEnumerable<Foo>>), Status200OK)]
	public IActionResult Get(ODataQueryOptions<Foo> options)
	{
		...
	}
}

In the above example, $select, $expand, $filter, $orderby, and $count all show up, but $top and $skip do not.

Sample project here.

The second issue I noticed can be demonstrated in the FoosController in the above project as well. If the method Get above is named GetFoos it doesn't show up in ApiExplorer/Swagger as I would expect, based on documented routing conventions. These docs don't mention usage of ODataQueryOptions<> so maybe this behavior doesn't apply? Just thought I'd mention this in case it's an issue. My main priority is the $top/$skip issue as a working Swagger app for every API at my company is a table-stakes requirement.

Thanks again!

engenb avatar Nov 27 '20 23:11 engenb

It happens in my case as well !

adrianaxente avatar Nov 08 '21 18:11 adrianaxente

Adding explicitly the EnableQueryAttribute will make $top and $skip to appear in the swagger documentation. We have defined a default EnableQueryAttribute set with some values from our configuration with a custom MaxNodeCount added as follows: services.AddODataQueryFilter( defaultEnableQuery ). If we add explicitly the EnableQueryAttribute on the action without MaxNodeCount set the default value is not used, instead the EnableQueryAttribute default value is used.

adrianaxente avatar Nov 08 '21 18:11 adrianaxente

Yikes! So sorry I never replied on this. Is this still an issue? Did adding [EnableQuery] solve the problem? There have historically be a bunch of gaps and inconsistencies in how or where query options can be applied. It's changed over the years too.

The 6.0 release is just around the corner, which will have support .NET 6.0 and OData 8.0. You can see the latest code and examples here. If this is still an issue, I'd certainly like to get it patched and make sure that it works properly in the upcoming release.

If this isn't an issue anymore, then we should close it out. I'm in the process of cleaning up all the open issues. Again, sorry for my poor follow-up on this one. I hope you eventually got something working.

commonsensesoftware avatar Mar 21 '22 04:03 commonsensesoftware

Last call. Has there been any other updates or progress? 6.0 has been officially released. If this is now resolved, I'd like to close it out. If there is more to do, then this item can finally move up in the queue.

commonsensesoftware avatar Aug 24 '22 01:08 commonsensesoftware