Asp net core 2 0 swashbuckle odd path truncation


ASP.NET is a popular programming language used for web applications. It provides a framework for developing dynamic websites, web , and web APIs. One of the key features of ASP.NET is its ability to handle routing and URL mapping, which allows developers to create clean and user-friendly URLs.

: Swashbuckle Odd Path Truncation

One common issue that developers face when using ASP.NET Core 2.0 with Swashbuckle is odd path truncation. Swashbuckle is a popular library used for generating Swagger documentation for ASP.NET Core APIs. However, in some cases, it may truncate the paths of the API endpoints, resulting in incorrect routing and broken links.

To solve the odd path truncation issue with Swashbuckle in ASP.NET Core 2.0, you can follow these steps:

Step 1: Install Swashbuckle.AspNetCore Package

First, you need to install the Swashbuckle.AspNetCore NuGet package in your ASP.NET Core . You can do this by adding the following line to your project's .csproj file:

After adding the package reference, restore the NuGet packages in your project.

Step 2: Configure Swagger in Startup.cs

Next, you need to configure Swagger in your ASP.NET Core project's Startup.cs file. Open the Startup.cs file and add the following code to the ConfigureServices :

services.AddSwaggerGen(c =>
    c.SwaggerDoc("v1", new OpenApiInfo { Title = "My API", Version = "v1" });

This code configures Swagger to documentation for your API with the specified title and version.

Step 3: Enable Swagger UI

To enable Swagger UI in your ASP.NET Core project, add the following code to the Configure method in your Startup.cs file:

app.UseSwaggerUI(c =>
    c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");

This code enables the Swagger UI and specifies the endpoint for the Swagger JSON file.

Step 4: Fix Odd Path Truncation

If you are still experiencing odd path truncation issues with Swashbuckle, you can try the following workaround:

1. Open the SwaggerConfig.cs file in your project.

2. Locate the ConfigureSwaggerGen method.

3. Add the following code the ConfigureSwaggerGen method:

c.ResolveConflictingActions(apiDescriptions => apiDescriptions.First());

This code resolves any conflicting in the API descriptions by selecting the first action.


In this article, we discussed the odd path truncation issue with Swashbuckle in ASP.NET Core 2.0 and provided a solution to fix it. By following the steps outlined above, you can ensure that your API endpoints are correctly routed and the Swagger documentation is generated accurately.

Rate this post

Leave a Reply

Your email address will not be published. Required fields are marked *

Table of Contents