Nswag: IApplicationBuilder' does not contain a definition for 'UseSwaggerWithApiExplorer' and no extension

Created on 20 Dec 2018  路  5Comments  路  Source: RicoSuter/NSwag

I am using .NET Core2.1 to developer Web API

I have added Nuget - NSwag.AspNetCore

'IApplicationBuilder' does not contain a definition for 'UseSwaggerWithApiExplorer' and no extension method 'UseSwaggerWithApiExplorer' accepting a first argument of type 'IApplicationBuilder' could be found (are you missing a using directive or an assembly reference?)

question

Most helpful comment

Please, update this article.
Few days later a method is now obsolete. It is very difficult to first use this toolchain with this gap between package and examples.

All 5 comments

UseSwaggerWithApiExplorer is deprectated, you should use AddOpenApiDocument(), UseSwagger() and UseSwaggerUi3()

It works when I add below code

  app.UseSwagger(); // registers the two documents in separate routes
  app.UseSwaggerUi3(); // registers a single Swagger UI (v3) with the two documents

But it fails and hows error Fetch error undefined undefined as below when I add code as shown below

 // Add Swagger 2.0 document serving middleware
        app.UseSwagger(options =>
        {
            options.DocumentName = "swagger";
            options.Path = "/swagger/v1/swagger.json";
        });

        // Add web UIs to interact with the document
        app.UseSwaggerUi3(options =>
        {
            // Define web UI route
            options.Path = "/swagger";

            // Define OpenAPI/Swagger document route (defined with UseSwaggerWithApiExplorer)
            options.DocumentPath = "/swagger/v1/swagger.json";
        });
        app.UseReDoc(options =>
        {
            options.Path = "/redoc";
            options.DocumentPath = "/swagger/v1/swagger.json";
        });

        // app.UseSwaggerUi3(); // registers a single Swagger UI (v3) with the two documents
        app.UseSwaggerUi3(options =>
        {
            // Add multiple OpenAPI/Swagger documents to the Swagger UI 3 web frontend
            options.SwaggerRoutes.Add(new SwaggerUi3Route("Swagger", "/swagger/v1/swagger.json"));

            // Define web UI route
            options.Path = "/swagger_all";
        });

What exactly is these lines? do I have to create file entitled swagger.json some where in project folder?

I think in your case the DocumentName in UseSwagger is wrong:

        options.DocumentName = "swagger";

it must match the document name registered in AddSwaggerDocument (default: "v1")

Please, update this article.
Few days later a method is now obsolete. It is very difficult to first use this toolchain with this gap between package and examples.

Article is updated, thanks @daveabrock :-)

Was this page helpful?
0 / 5 - 0 ratings