AspNetCoreOData icon indicating copy to clipboard operation
AspNetCoreOData copied to clipboard

OData 8, .net core 5, aspnet-api-versioning, & swagger

Open twmillett opened this issue 4 years ago • 5 comments
trafficstars

I'm trying to upgrade our project to .net core 5, which apparently requires upgrading to OData 8.

But, OData 8 appears to be incompatible with Microsoft.AspNetCore.OData.Versioning.ApiExplorer, so I was required to remove the dependency on that and change the startup call from

 services.AddODataApiExplorer()

to instead use the one in Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer

 services.AddVersionedApiExplorer();

Not surprisingly, swagger isn't showing any of the OData API definitions. I cloned your samples directory and found that swagger doesn't seem to be working there, either.

image

What is the recommended way to get OData 8 API definitions hooked up to swagger?

twmillett avatar Jun 29 '21 20:06 twmillett

@twmillett You cloned "ODataRoutingSample" and run this sample, It can't work for the Swagger?

It seems not true. Because, I just run it and send "http://localhost:5000/swagger". I got the following page.

image

xuzhg avatar Jul 01 '21 04:07 xuzhg

Ah, OK. When I run ODataRoutingSample, it works as you describe. Good to know it's supported.

I was running the ODataCustomizedSample, which it turns out fails with this exception.

fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1] An unhandled exception has occurred while executing the request. System.NotSupportedException: Ambiguous HTTP method for action - ODataCustomizedSample.Controller.EmployeesController.Get (ODataCustomizedSample). Actions require an explicit HttpMethod binding for Swagger/OpenAPI 3.0 at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GenerateOperations(IEnumerable1 apiDescriptions, SchemaRepository schemaRepository) at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GeneratePaths(IEnumerable1 apiDescriptions, SchemaRepository schemaRepository) at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GetSwagger(String documentName, String host, String basePath) at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider) at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

twmillett avatar Jul 06 '21 21:07 twmillett

@xuzhg, is there a supported way to run OData v8.0 with api versioning and swagger? I was wrong, above, about swagger not working in general (it was just the customized sample that was failing). But, I still can't figure out how to get OData 8 wired up with aspnet-api-versioning and swagger.

The Odata controllers don't seem to be discovered unless I mark them with [ApiController], but that causes other problems and is recommended against in one of your readme's.

What I really would like is a .net core 5 compatible version of OData that supports aspnet-api-versioning, preferably working with swagger, too. Does that exist?

twmillett avatar Jul 30 '21 19:07 twmillett

@xuzhg, could you please help with @twmillett's question above?

vishmittal avatar Aug 12 '21 11:08 vishmittal

sorry for the cross-post. @twmillett , @vishmittal just announced in dotnet/aspnet-api-versioning#677, official support is coming and is also here. pop on over for more details

commonsensesoftware avatar Mar 19 '22 22:03 commonsensesoftware