0

I'm using Swashbuckle in an ASP .NET MVC application which is configured with additional operation filters like so:

 GlobalConfiguration.Configuration
                .EnableSwagger(c => {
                    c.OperationFilter<FooOpeartionFilter>();
                    c.OperationFilter<BarOpeartionFilter>();
                    //other confs
                    ...

In my .NET client application, I would like to automatically create API client code based on a .NET MvcApplication.dll which includes the Controller definitions.

For this I use NSWAG. I run firstly webapi2openapi to generate the openapi.json document

nswag webapi2openapi /assembly:MvcApplication.dll /output:MvcApplication.OpenApi.json 

and then for creation of the client c# code:

nswag run configuration.nswag

with the configuration.nswag pointing to the MvcApplication.OpenApi.json

  "documentGenerator": {
    "fromDocument": {
      "url": "PATH\MvcApplication.OpenApi.json"
    }
  },

but the created openAPI document MvcApplication.OpenApi.json is lacking of changes to the API which the additional OperationFilters are providing. As I understand, this is expected as the Operation filters are added on asp .net application startup and we create the .json from a static .dll.

Is there a way to include the operation filters to the created MvcApplication.OpenApi.json based on a MvcApplication.dll? Is this possible? I have search for answer in the nswag help and navigated to Command: webapi2openapi, but non of the listed parameters seems to add those operation filters. Or maybe should I change my ASP .NET code and use NSWAG instead of swashbuckle?

Artur
  • 128
  • 10
  • 1
    You are mixing nswag in the cli and swashbuckle in the actual app - nswag will not pick up any swashbuckle filters. This will only work with ASP.NET Core and nswag in the app + nswag as cli... – Rico Suter Sep 30 '20 at 20:09
  • Yes, that's the current state - nswag in client, Swashbuckle in the app. Work's well when generating the client code directly from running app, but I want to change it to generate the client code from the app static .dll, so the client code would not be depend on running app. Ok, so as I understand the only solution here is to move the app code from Swashbuckle to nswag and rewrite the swashbuckle OperationFilters to nswag OperationProcessors. Thanks, for the response. – Artur Oct 01 '20 at 07:48
  • Maybe swashbuckle also has a cli to gen the spec outside and then use that as input for the nswag client gen via cli – Rico Suter Oct 01 '20 at 09:40

0 Answers0