'Swashbuckle is over-documenting my dotnet6 web api with OData and Api versions of the same controller

Here's the critical part of my Startup class:

     services.AddControllers().AddOData(opt => 
          opt.Count().Filter().Expand().Select().OrderBy().SetMaxTop(750)
     );

If I leave it at the above, I get all my controllers documented as API controllers. While I can pass in the OData parameters for $top, $select etc, and they work, I am also wanting to get a response with the wrapped payload, as conforming to the OData standard.

This does the trick:

     services.AddControllers().AddOData(opt => 
          opt.Count().Filter().Expand().Select().OrderBy().SetMaxTop(750)
              .AddRouteComponents("odata", MyEdmModel) //gives me proper OData responses
     );

However my classes are documented twice, under both /api and /odata endpoints

The endpoints aren't necessarily incorrect (they do work) but how can I separate out my controllers?

This used to not be a problem for me under the old .NET Framework style Web API 2.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source