Search code examples
asp.netasp.net-coreswaggerodataswagger-ui

Removing OData schema from swagger. Asp.net Core Web Api 5.0


How can I remove extra scheme objects that are being generated by OData from swagger asp.net core web api 5.0


Solution

  • I ran into the same situation and built the functionality into a framework I wrote. The answer is that you need to create an IDocumentFilter. Here's a sample based on .net 6:

    https://github.com/ikemtz/NRSRx/blob/master/src/IkeMtz.NRSRx.Core.OData/ODataCommonDocumentFilter.cs

    In your startup.cs do the following:

       .AddSwaggerGen(swaggerGenOptions =>
            {
              swaggerGenOptions.DocumentFilter<ODataCommonDocumentFilter>();
            });