-
Notifications
You must be signed in to change notification settings - Fork 711
$batch returns 404 or 405 when using Asp.Versioning.OData.ApiExplorer 6.0.0-preview.3, OData 8 and .Net 6 #847
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
Comments
The I have a feeling that this may only happen because you're versioning by URL segment. This would be one more entry in a long list of issues with that approach, aside from it not being RESTful. If it's an option, you might consider another approach. Another possible solution would be to register the This should work, so I'll look into it. You might consider whether you actually need OData batching. When it was first created, it was a very novel idea and tackled some tough limitations in |
Is it expected that swagger doesn't see the versions we define and just shows all the mapped routes on the page and doesn't split them into versions? |
@knightian I'm not sure I fully follow the question. API Versioning doesn't specific care anything about OpenAPI (or Swagger). The API Explorer extensions will bucketize all endpoints by API version and represent that via the Is this relating to batching? This seems to be a completely different question. |
What I mean is, if I click on /v1.0/swagger.json I only want to see my /v1.0/mappedroute returned I don't want to see all the versions in the v1.0 json that makes no sense, why would I see v2.0 etc in the v1.0 json? |
I don't see how is related to batching (e.g. this issue) or OData; however, this happening for one or both of the following reasons:
The examples demonstrate how to properly setup OpenAPI support for standard and Minimal APIs. That includes grouping |
@joevanheerden were you ever able to get things working? @knightian even though your question was a segue, did you get things working as well? |
Hey yes I did thank you, working well. |
Apologies for the late response. Thanks for your detailed explanation. I could not get $batch to work - not even when registering the default batch handler for route prefixes without versioning. I've since abandonded $batch, and started using ODataQueryRequest since it is better suited for my use case, which is to be able to use large OData queries with HTTP POST. It took me only a few minutes to get that to work opposed to hours of fiddling to try and get $batch to work. Side note: It seems that prior to .Net 6 with OData 8 ODataQueryRequest was enabled by default, but now it is opt-in and requires app.UseODataQueryRequest() to enable it. Once again @knightian: Thanks for all the effort in producing a great library. |
@joevanheerden Good to know. OData is always seems to be a moving target. I've had reports of breaking changes or regressions between even patch versions. 😬 Glad you are unblocked. I'll leave this issue open for now. I have a feeling there are some edge cases around batching that still need to be ironed out. I've been advising people away from it, but if the really want to use it, then it should work. Thanks for the update. |
I'm also getting 404 errors from $batch endpoints. I'm using Asp.Versioning.OData 6.0.0, Microsoft.AspNetCore.OData 8.0.11 and .NET 6. My setup is something like
I did some debugging and saw that when the ODataBatchMiddleware is instantiated, there are zero RouteCompoents in the ODataOptions. See https://github.com/OData/AspNetCoreOData/blob/eb3ca8e0b02058c33212f124c810c67f453f74dc/src/Microsoft.AspNetCore.OData/Batch/ODataBatchMiddleware.cs#L83. The resolved IOptions<ODataOptions> in the middleware is the replaced VersionedODataOptions. So when the Value getter is invoked, I'm assuming we are returning a default/empty ODataOptions, due to not being in the scope of a request. Is that correct? |
@fannydengdeng I dig a bit into
|
@fannydengdeng This behavior is, unfortunately, by design. I tried to influence the OData 8.0 design early on to no avail. Its design assumes there can be only one I'm looking into this issue more deeply, but there are a myriad of problems. One significant issue is that OData now allows an @pil0t I'd be curious as to the hack or what you got working. I presume you replaced or extended the built-in middleware? It seems I'm going to have to create version-ware variants for batching. |
Just a quick update. It appears I finally have something working. The native OData implementation isn't doing us any favors. I tried making things working over the existing implementation, but there is no way to make it work - unfortunately. There are also a litany of bugs and other internal OData issues that made this difficult to troubleshoot and support. Batching is coming in
Unlike the built-in OData libraries, you don't have to register your own batch handler to get batching to work. The new, minimum setup will be: var services = builder.Services;
services.AddControllers().AddOData();
services
.AddApiVersioning(options => options.ApiVersionReader = new UrlSegmentApiVersionReader())
.AddOData(options => options.AddRouteComponents("api/v{version:apiVersion}"));
app.UseHttpsRedirection();
app.UseAuthorization();
app.UseVersionedODataBatching(); // ← new
app.MapControllers();
app.Run(); It should be noted that it doesn't really matter which batch handler (e.g. That being said, you can specify an API version to route to a specific The default var services = builder.Services;
services.AddControllers().AddOData();
services
.AddApiVersioning(options => options.ApiVersionReader = new UrlSegmentApiVersionReader())
.AddOData(
options => options.AddRouteComponents(
"api/v{version:apiVersion}",
new VersionedODataBatchHandler()
{
MessageQuotas =
{
MaxNestingDepth = 2,
MaxOperationsPerChangeset = 10,
MaxReceivedMessageSize = 100
},
} ) ); I'm reviewing what else needs to go into |
Uh oh!
There was an error while loading. Please reload this page.
I'm cannot figure out how to make Odata Batching to work when using API Versioing. I cannot tell if I'm missing configuration, or whether the issue is with Odata or API Versioning.
Using URL Segement versioning and the following configuration results in a 404 when making a GET request to api/v1/$batch, and 405 when making a POST request.
Expected behaviour is to get the expected OData response for POST, and 'The batch request must have a "Content-Type" header.' for GET.
Any help would be much appreciated.
Thanks to the author of this repo for all the hard work in maintaining this - the effort is much appreciated.
The text was updated successfully, but these errors were encountered: