Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ambiguites in AspNet Core 2.0 using Swagger in Web API

I am trying to use Swagger in an AspNet Core 2 Web API. I have one sample that works based on:

https://docs.microsoft.com/en-us/aspnet/core/tutorials/web-api-help-pages-using-swagger?tabs=visual-studio

However, when I try to use the same approach in another service I get compile error:

2>Startup.cs(41,17,41,27): error CS0121:

The call is ambiguous between the following methods or properties: 'Microsoft.AspNetCore.Builder.SwaggerBuilderExtensions.UseSwagger(Microsoft.AspNetCore.Builder.IApplicationBuilder, System.Action)'

and

'Microsoft.AspNetCore.Builder.SwaggerBuilderExtensions.UseSwagger(Microsoft.AspNetCore.Builder.IApplicationBuilder, string, System.Action)'

2>Done building project "SocialNetwork.Api.csproj" -- FAILED.

The target call is in Startup.cs in the Configure method.

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }

        // Enable middleware to serve generated Swagger as a JSON endpoint.
        app.UseSwagger(); // Ambiguous

        // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.), specifying the Swagger JSON endpoint.
        app.UseSwaggerUI(c =>
        {
            c.SwaggerEndpoint("/swagger/v1/swagger.json", "SocialNetwork API V1");
        });

        app.UseMvc();
    }

Does anyone have insight on this? Any help would be greatly appreciated. Thank you.

like image 469
user3802434 Avatar asked Nov 03 '17 17:11

user3802434


People also ask

How to integrate Swagger UI with ASP NET Core web API?

The Swashbuckle package has an embedded version of Swagger UI, so that it can be hosted in our ASP.NET Core app using a middleware. Each public action method in the controllers is available in the Swagger UI. We can use the Swashbuckle package to integrate Swagger into our .NET Core Web API project.

Where is Swagger API documentation in Visual Studio 2019?

Otherwise, in middleware, we have SwaggerEndpoint "/swagger/v1/swagger.json" so you can enter in the browser like "http://localhost:44392/api/swagger". From this article, we have learned the Web API documentation using Swagger & ASP.NET Core With Visual Studio 2019.

What is the difference between nswag and Swagger?

Swashbuckle.AspNetCore is an open source project for generating Swagger documents for ASP.NET Core Web APIs. NSwag is another open source project for generating Swagger documents and integrating Swagger UI or ReDoc into ASP.NET Core web APIs.

What is Swagger UI and Swagger used for?

Swagger used to reduce the work needed while integrating an API. Similarly, it also helps API developers to document their APIs quickly and effectively. Swagger UI offers a web-based UI that provides information about the service, using the generated OpenAPI specification.


1 Answers

I uninstalled Swagger and just installed the SwashBuckle.AspNetCore because it already implements the Swagger object inside. that is why it is calling ambigious.

like image 195
Jerick Luigi Eñano Avatar answered Dec 08 '22 05:12

Jerick Luigi Eñano