Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ignore 3rd party Controller Actions in Swagger

I have an ASP.NET Core 2.1 Web App that serves DevExpress Reports over a Web API interface.

I'd like to use swagger to be able to show consumers the usage and provide some helpful info about my Web API. However, Swagger crashes with the following error:

NotSupportedException: Ambiguous HTTP method for action - DevExpress.AspNetCore.Reporting.QueryBuilder.QueryBuilderController.Invoke (DevExpress.AspNetCore.Reporting.v18.2). Actions require an explicit HttpMethod binding for Swagger 2.0

The problem is that Swagger tries to analyze the API contained in DevExpress' QueryBuilderController. However, I don't want swagger to analyze these 3rd party controllers. My question now is how to filter/disable 3rd party libraries in swagger?

Thanks Sven

like image 904
Sven Avatar asked Oct 16 '25 04:10

Sven


1 Answers

I got it working using a custom DocInclusionPredicate as suggested here.

Example code:

services.AddSwaggerGen(c =>
{
      c.DocInclusionPredicate((docName, apiDesc) =>
      {
          // Filter out 3rd party controllers
          var assemblyName = ((ControllerActionDescriptor)apiDesc.ActionDescriptor).ControllerTypeInfo.Assembly.GetName().Name;
          var currentAssemblyName = GetType().Assembly.GetName().Name;
          return currentAssemblyName == assemblyName;
      });
      c.SwaggerDoc("v1", new Info { Title = "FileService API", Version = "v1" });
});
like image 142
Sven Avatar answered Oct 18 '25 22:10

Sven



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!