RicoSuter / NSwag

The Swagger/OpenAPI toolchain for .NET, ASP.NET Core and TypeScript.
http://NSwag.org
MIT License
6.71k stars 1.24k forks source link

OData ASP.NET Core support #730

Open Yavor81 opened 7 years ago

Yavor81 commented 7 years ago

Hi, Do you plan to add support for generating Swagger spec when using OData controllers in ASP.NET Core app? As you probably know, OData provides a uniform way to query and manipulate data sets through CRUD operations. I am currently using this package (unofficial) for enabling OData controllers but I want to add support for this protocol in the generated swagger spec using NSwag. I see with another OData enabled Swagger spec (via Swashbuckle.OData) that NSwag client code generation manages to handle these endpoints, once they are defined correctly. The question is how to add support for OData on the server side when using the .UseSwaggerUi middleware in ASP.NET Core?

RicoSuter commented 7 years ago

Duplicate: https://github.com/NSwag/NSwag/issues/669

I think this is doable without much effort, however I am currently working on other parts of NSwag... Can you provide some sample controllers so that I can check this? Is there some documentation for this unofficial package?

Yavor81 commented 7 years ago

Hi, Thank you for your quick reply. I cannot find any documentation for this package. Probably the reason is that it is just a wrapper around the non .NET Core implementation. Here is a sample project that I am using as a guide for setting up the pipeline to use the OData protocol. It is not using the above-mentioned package directly but something similar, which is home-grown, The idea, however, is the same.

Yavor81 commented 7 years ago

Hi again, Is there any information about the NSwag application model, how the entire flow goes. I am evaluating the effort to add OData support for NSwag, how complex it would be.

skarpovru commented 6 years ago

A few weeks ago Microsoft has released .Net Core version of OData WebApi library (https://www.nuget.org/packages/Microsoft.AspNetCore.OData/7.0.0-beta1). No need for unofficial package anymore. They use ODataQueryOptions input parameter in controllers to pass a query ($filter, $orderby, $top, $skip keywords) https://github.com/OData/WebApi/blob/feature/netcore/src/Microsoft.AspNetCore.OData/Query/ODataQueryOptionsOfTEntity.cs

A second option - EnableQuery attribute on the action.

Controller action sample:

public async Task<IActionResult> GetAsync(
            ODataQueryOptions<User> options,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            IQueryable<User> users = await _userManager.QueryAsync(cancellationToken);

            return PageResult(users, options);
        }
rodrigo-silva commented 6 years ago

This is very interesting. The implementation in http://swashbuckleodata.azurewebsites.net/swagger/ui/index is what I'm interested to. I'm using Microsoft.AspNetCore.OData and I'm wondering how to install Swashbuckle.OData, because it seems to me it workd with Swashbuckle instead of Swashbuckle.AspNetCore. Does anyone had installe Swashbuckle.OData with Swashbuckle.AspNetCore?

Best

RicoSuter commented 6 years ago

Ref: https://stackoverflow.com/questions/51527176/is-it-possible-to-use-swagger-with-aspnetcore-odata

OculiViridi commented 6 years ago

@RSuter I'm interested too in using NSwag in combination with the official Microsoft.AspNetCore.OData package (currently at v7.0.1). I see the SO question but have you already tried it without issues or are you planning to give an official support in NSwag for OData?

Thanks!

figuerres commented 5 years ago

an item to note is that so far i have only found Swashbuckle to have an Option for OData and swashbuckle has problems with securing access to the pages. for really main stream use i think both are needed. Some folks may not like OData but used right it can help with data access.