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.
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.
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.
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.
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.
I uninstalled Swagger and just installed the SwashBuckle.AspNetCore because it already implements the Swagger object inside. that is why it is calling ambigious.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With