question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ODataController controllers missing from swagger UI

See original GitHub issue

I am working on a POC with OData on AspNetCore Microsoft.AspNetCore.OData

I am trying to add Swagger UI to document The API

I am working with this versions : Swashbuckle.AspNetCore.Swagger 1.1 Swashbuckle.AspNetCore.SwaggerGen 1.1 Swashbuckle.AspNetCore.SwaggerGenUI 1.1

My problem is the ODataController is missing from the Swagger UI.

I have found some forum thread and the workaround was to add Annotations to the ODataController [ApiExplorerSettings(IgnoreApi = false )] If I do that the Api is not working since the routes are not defined . has ApiExplorer enabled, but is using conventional routing. Only actions which use attribute routing support ApiExplorer.

so the only solution I have found to see the ODataController is to also add : [Route("v1/api/[controller]")]

But if I do that I lose the Odata.context informations (in the json results) that are vital to give the total number of results without paging “@odata.context”: “http://localhost:29860/v1/api/$metadata#Products”, “@odata.count”: 4,

What can I do to make swagger work with OdataController without loosing all Odata annotations on the results ?

Thank you by advance for your attention

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:16
  • Comments:29 (2 by maintainers)

github_iconTop GitHub Comments

12reactions
antgustechcommented, Jul 20, 2018

Same issue here. My regular Controllers show up in Swagger but not my OData controllers.

4reactions
fededimcommented, Jul 30, 2020

I managed to make Swagger compatible with ODataController by following the code in this repository. I had only to change SetOutputFormatters in Startup.cs in this way:

      private static void SetOutputFormatters(IServiceCollection services)
       {
           services.AddMvcCore(options =>
           {
               IEnumerable<ODataOutputFormatter> outputFormatters =
                   options.OutputFormatters.OfType<ODataOutputFormatter>()
                       .Where(formatter => formatter.SupportedMediaTypes.Count == 0);

               IEnumerable<ODataInputFormatter> inputFormatters =
                   options.InputFormatters.OfType<ODataInputFormatter>()
                       .Where(formatter => formatter.SupportedMediaTypes.Count == 0);

               foreach (var outputFormatter in outputFormatters)
               {
                   outputFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/odata"));
                   outputFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/json"));
               }

               foreach (var inputFormatter in inputFormatters)
               {
                   inputFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/odata"));
                   inputFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/json"));
              
               }

           });
       }
Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to load Swagger API documentation with ODATA ...
We are trying to generate the swagger UI with OData and NSwag but we are ended up with lot of issues. We are...
Read more >
Solved: Adding New Controllers Not Showing in UI
Solved: Currently, I have 4 controllers/categories on my UI ready and working. However, I have 7 controllers in my folder.
Read more >
Show only specific APIs on Swagger — Asp.Net Core
It is pretty common to have Web APIs with tons of Controllers and methods and, sometimes, it is necessary to hide non-public APIs...
Read more >
Enabling Endpoint Routing in OData
I had been unable to get my OData endpoints to show in my API's swagger page targeted at .net core 3.1. This blog...
Read more >
OData with .NET 6
In this tutorial, I will give you how to create Web API using .NET 6 and OData. We will create simple CRUD of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found