Skip to content

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

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

Closed
engenb opened this issue Nov 27, 2020 · 4 comments · Fixed by #879
Assignees

Comments

@engenb
Copy link

engenb commented Nov 27, 2020

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!

@adrianaxente
Copy link

It happens in my case as well !

@adrianaxente
Copy link

adrianaxente commented Nov 8, 2021

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.

@commonsensesoftware
Copy link
Collaborator

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
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants