RicoSuter / NSwag

The Swagger/OpenAPI toolchain for .NET, ASP.NET Core and TypeScript.
http://NSwag.org
MIT License
6.78k stars 1.29k forks source link

IApplicationBuilder' does not contain a definition for 'UseSwaggerWithApiExplorer' and no extension #1844

Closed deepakkumpala closed 5 years ago

deepakkumpala commented 5 years ago

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?)

RicoSuter commented 5 years ago

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

deepakkumpala commented 5 years ago

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?

RicoSuter commented 5 years ago

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")

dlucazeau commented 5 years ago

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.

RicoSuter commented 5 years ago

Article is updated, thanks @daveabrock :-)