domaindrivendev - Swashbuckle.AspNetCore 10.0.2

Swagger tools for documenting APIs built on ASP.NET Core

PM> Install-Package Swashbuckle.AspNetCore -Version 10.0.2 -Source https://www.myget.org/F/domaindrivendev/api/v3/index.json

Copy to clipboard

> nuget.exe install Swashbuckle.AspNetCore -Version 10.0.2 -Source https://www.myget.org/F/domaindrivendev/api/v3/index.json

Copy to clipboard

> dotnet add package Swashbuckle.AspNetCore --version 10.0.2 --source https://www.myget.org/F/domaindrivendev/api/v3/index.json

Copy to clipboard
<PackageReference Include="Swashbuckle.AspNetCore" Version="10.0.2" />
Copy to clipboard
source https://www.myget.org/F/domaindrivendev/api/v3/index.json

nuget Swashbuckle.AspNetCore  ~> 10.0.2
Copy to clipboard

> choco install Swashbuckle.AspNetCore --version 10.0.2 --source https://www.myget.org/F/domaindrivendev/api/v2

Copy to clipboard
Import-Module PowerShellGet
Register-PSRepository -Name "domaindrivendev" -SourceLocation "https://www.myget.org/F/domaindrivendev/api/v2"
Install-Module -Name "Swashbuckle.AspNetCore" -RequiredVersion "10.0.2" -Repository "domaindrivendev" 
Copy to clipboard

Swashbuckle.AspNetCore

NuGet NuGet Downloads

Build status Code coverage OpenSSF Scorecard

Help Wanted

OpenAPI (Swagger) tooling for APIs built with ASP.NET Core.

Generate beautiful API documentation, including a UI to explore and test operations, directly from your application code.

In addition to its Swagger 2.0 and OpenAPI 3.0/3.1 generator, Swashbuckle.AspNetCore also provides an embedded version of the awesome swagger-ui project that's powered by the generated OpenAPI JSON documents. This means you can complement your API with living documentation that's always in sync with the latest code. Best of all, it requires minimal coding and maintenance, allowing you to focus on building an awesome API.

But that's not all!

Once you have an API that can describe itself with a OpenAPI document, you've opened the treasure chest of OpenAPI-based tools including a client generator that can be targeted to a wide range of popular platforms. See swagger-codegen for more details.

[!IMPORTANT]
Version 10.0 of Swashbuckle.AspNetCore introduces breaking changes due to upgrading our dependency on Microsoft.OpenApi to version 2.x.x to add support for generating OpenAPI 3.1 documents. Please see Migrating to Swashbuckle.AspNetCore v10 for more details.

Compatibility

Swashbuckle Version ASP.NET Core OpenAPI/Swagger Versions Microsoft.OpenApi swagger-ui Redoc
CI Swashbuckle.AspNetCore version >= 8.0.0 3.1, 3.0, 2.0 Microsoft.OpenApi version swagger-ui version Redoc version
Latest Swashbuckle.AspNetCore version >= 8.0.0 3.1, 3.0, 2.0 Microsoft.OpenApi version swagger-ui version Redoc version
Last v9 Swashbuckle.AspNetCore version 9.0.x, 8.0.x 3.0, 2.0 Microsoft.OpenApi version swagger-ui version Redoc version
Last v8 Swashbuckle.AspNetCore version 9.0.x, 8.0.x, 2.3.x 3.0, 2.0 Microsoft.OpenApi version swagger-ui version Redoc version

Getting Started

First install the kitchen-sink NuGet package into your ASP.NET Core application:

dotnet add package Swashbuckle.AspNetCore

Next, register the OpenAPI (Swagger) generator in your application's startup path, defining one or more OpenAPI documents. For example:

using Microsoft.OpenApi;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddMvc();

builder.Services.AddSwaggerGen(options =>
{
    options.SwaggerDoc("v1", new OpenApiInfo { Title = "My API", Version = "v1" });
});

var app = builder.Build();

app.UseSwagger();

app.Run();

snippet source | anchor

Ensure your API endpoints and any parameters are decorated with [Http*] and [From*] attributes, where appropriate.

[HttpPost]
public void CreateProduct([FromBody] Product product)
{
    // Implementation goes here
}

[HttpGet]
public IEnumerable<Product> SearchProducts([FromQuery] string keywords)
{
    // Implementation goes here
    return [];
}

snippet source | anchor

[!NOTE] If you omit the explicit parameter bindings, the generator will describe them as "query" parameters by default.

Then, expose the OpenAPI JSON document endpoint(s) using one of following methods:

  • Add endpoints if you're using endpoint-based routing:

// Your own endpoints go here, and then...
app.MapSwagger();

snippet source | anchor

  • Adding the OpenAPI middleware:

app.UseSwagger();

snippet source | anchor

At this point, you can launch your application and view the generated OpenAPI document at /swagger/v1/swagger.json.

Finally, you can optionally add the swagger-ui middleware to expose interactive documentation, specifying the OpenAPI document(s) to power it from:

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

snippet source | anchor

Now you can restart your application and view the auto-generated, interactive documentation at /swagger.

System.Text.Json (STJ) vs Newtonsoft.Json (Json.NET)

In versions of Swashbuckle.AspNetCore prior to 5.0.0, Swashbuckle.AspNetCore would generate Schemas (descriptions of the data types exposed by an API) based on the behavior of the Newtonsoft.Json serializer. This made sense because that was the serializer that shipped with ASP.NET Core at the time. However, since ASP.NET Core 3.0, ASP.NET Core introduces a new serializer, System.Text.Json (STJ) out-of-the-box.

If you want to use Newtonsoft.Json instead, you must install a separate package and explicitly opt-in. By default Swashbuckle.AspNetCore will assume that you're using the System.Text.Json serializer and generate schemas based on its behavior. If you're using Newtonsoft.Json, then you'll need to install a separate Swashbuckle.AspNetCore package, Swashbuckle.AspNetCore.Newtonsoft to explicitly opt-in.

Below is an example of how to do this for ASP.NET Core MVC:

dotnet add package Swashbuckle.AspNetCore.Newtonsoft

services.AddMvc();

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

services.AddSwaggerGenNewtonsoftSupport();

snippet source | anchor

Swashbuckle, ApiExplorer, and Routing

Swashbuckle relies heavily on ApiExplorer, the API metadata layer that ships with ASP.NET Core. If you're using the AddMvc(...) helper methods to bootstrap the MVC stack, then API Explorer will be automatically registered and Swashbuckle.AspNetCore should work without issue.

However, if you're using AddMvcCore(...) for a more paired-down MVC stack, you'll need to explicitly add the API Explorer services:

services.AddMvcCore()
        .AddApiExplorer();

snippet source | anchor

Additionally, if you are using conventional routing (as opposed to attribute routing), any controllers and the actions on those controllers that use conventional routing will not be represented in API Explorer, which means Swashbuckle won't be able to find those controllers and generate OpenAPI operations for them.

For instance:

app.UseMvc(routes =>
{
    // SwaggerGen won't find controllers that are routed via this technique.
    routes.MapRoute("default", "{controller=Home}/{action=Index}/{id?}");
});

snippet source | anchor

You must use attribute routing for any controllers that you want represented in your OpenAPI document(s):

[Route("example")]
public class ExampleController : Controller
{
    [HttpGet("")]
    public IActionResult DoStuff()
    {
        // Your implementation
        return Empty;
    }
}

snippet source | anchor

Refer to the ASP.NET Core MVC routing documentation for more information.

Components

Swashbuckle.AspNetCore consists of multiple components that can be used together or individually depending on your needs.

At its core, there's an OpenAPI generator, middleware to expose OpenAPI (Swagger) documentation as JSON endpoints, and a packaged version of the swagger-ui. These three packages can be installed with the Swashbuckle.AspNetCore "metapackage" and will work together (see Getting Started) to provide API documentation that is automatically generated from your code.

Additionally, there are add-on packages (CLI tools, an alternate UI using Redoc etc.) that you can install and configure as needed.

"Core" Packages

Package NuGet Description
Swashbuckle.AspNetCore.Swagger NuGet Exposes OpenAPI JSON endpoints. It expects an implementation of ISwaggerProvider to be registered in the DI container, which it queries to retrieve OpenApiDocument instance(s) that are then exposed as serialized JSON.
Swashbuckle.AspNetCore.SwaggerGen NuGet Injects an implementation of ISwaggerProvider that can be used by the above component. This particular implementation generates OpenApiDocument instance(s) from your application endpoints (controllers, minimal endpoints etc.).
Swashbuckle.AspNetCore.SwaggerUI NuGet Exposes an embedded version of swagger-ui. You specify the API endpoints where it can obtain OpenAPI documents from, and it uses them to power interactive documentation for your API.

Additional Packages

Package NuGet Description
Swashbuckle.AspNetCore.Annotations NuGet Includes a set of custom attributes that can be applied to controllers/endpoints, actions and models to enrich the generated documentation.
Swashbuckle.AspNetCore.Cli NuGet Provides a command line interface (CLI) for retrieving OpenAPI documents directly from an application start-up assembly and then writing to a file.
Swashbuckle.AspNetCore.ReDoc NuGet Exposes an embedded version of the Redoc UI (an alternative to swagger-ui).

Community Packages

These packages are provided by the .NET open-source community.

Package NuGet Description
Swashbuckle.AspNetCore.Filters NuGet Some useful Swashbuckle.AspNetCore filters which add additional documentation, e.g. request and response examples, authorization information, etc. See its README for more details.
Unchase.Swashbuckle.AspNetCore.Extensions NuGet Some useful extensions (filters), which add additional documentation, e.g. hide PathItems for unaccepted roles, fix enumerations for client code generation, etc. See its README for more details.
MicroElements.Swashbuckle.FluentValidation NuGet Use FluentValidation rules instead of ComponentModel attributes to augment generated OpenAPI schemas.
MMLib.SwaggerForOcelot NuGet Aggregate documentations over microservices directly on Ocelot API Gateway.

Configuration and Customization

The steps described above will get you up and running with minimal set up. However, Swashbuckle.AspNetCore offers a lot of flexibility to customize as you see fit.

Check out the table below for the full list of possible configuration options.

Component Configuration and Customization
Swashbuckle.AspNetCore.Swagger Change the Path for OpenAPI JSON Endpoints
Modify OpenAPI with Request Context
Serialize OpenAPI JSON in the 3.1 format
Serialize Swagger JSON in the 2.0 format
Working with Virtual Directories and Reverse Proxies
Customizing how the OpenAPI document is serialized
Swashbuckle.AspNetCore.SwaggerGen Assign Explicit OperationIds
List Operations Responses
Flag Required Parameters and Schema Properties
Handle Forms and File Uploads
Handle File Downloads
Include Descriptions from XML Comments
Provide Global API Metadata
Generate Multiple OpenAPI Documents
Omit Obsolete Operations and/or Schema Properties
Omit Arbitrary Operations
Customize Operation Tags (e.g. for UI Grouping)
Change Operation Sort Order (e.g. for UI Sorting)
Customize Schema Ids
Override Schema for Specific Types
Extend Generator with Operation, Schema & Document Filters
Add Security Definitions and Requirements
Add Security Definitions and Requirements for Bearer auth
Inheritance and Polymorphism
Swashbuckle.AspNetCore.SwaggerUI Change Relative Path to the UI
Change Document Title
Change CSS or JS Paths
List Multiple OpenAPI Documents
Apply swagger-ui Parameters
Inject Custom JavaScript
Inject Custom CSS
Customize index.html
Enable OAuth2.0 Flows
Use client-side request and response interceptors
Swashbuckle.AspNetCore.Annotations Install and Enable Annotations
Enrich Operation Metadata
Enrich Response Metadata
Enrich Parameter Metadata
Enrich RequestBody Metadata
Enrich Schema Metadata
Apply Schema Filters to Specific Types
Add Tag Metadata
Swashbuckle.AspNetCore.Cli Retrieve OpenAPI Directly from a Startup Assembly
Use the CLI Tool with a Custom Host Configuration
Swashbuckle.AspNetCore.ReDoc Change Relative Path to the UI
Change Document Title
Apply Redoc Parameters
Inject Custom CSS
Customize index.html
  • .NETFramework 8.0
    • Microsoft.Extensions.ApiDescription.Server (>= 8.0.0)
    • Swashbuckle.AspNetCore.Swagger (>= 10.0.2)
    • Swashbuckle.AspNetCore.SwaggerGen (>= 10.0.2)
    • Swashbuckle.AspNetCore.SwaggerUI (>= 10.0.2)
  • .NETFramework 9.0
    • Microsoft.Extensions.ApiDescription.Server (>= 9.0.0)
    • Swashbuckle.AspNetCore.Swagger (>= 10.0.2)
    • Swashbuckle.AspNetCore.SwaggerGen (>= 10.0.2)
    • Swashbuckle.AspNetCore.SwaggerUI (>= 10.0.2)
  • .NETFramework 10.0
    • Microsoft.Extensions.ApiDescription.Server (>= 10.0.0)
    • Swashbuckle.AspNetCore.Swagger (>= 10.0.2)
    • Swashbuckle.AspNetCore.SwaggerGen (>= 10.0.2)
    • Swashbuckle.AspNetCore.SwaggerUI (>= 10.0.2)

Owners

Richie Morris

Authors

domaindrivendev

Project URL

https://github.com/domaindrivendev/Swashbuckle.AspNetCore

License

Unknown

Tags

swagger openapi documentation discovery help webapi aspnet aspnetcore

Info

1894 total downloads
1 downloads for version 10.0.2
Download (3.32 KB)
Found on the current feed only

Package history

Version Size Last updated Downloads Mirrored?
10.1.0 3.32 KB Fri, 12 Dec 2025 14:25:41 GMT 0
10.1.0-preview.2092 3.34 KB Thu, 11 Dec 2025 16:41:50 GMT 1
10.1.0-preview.2090 3.34 KB Wed, 10 Dec 2025 11:18:22 GMT 1
10.1.0-preview.2088 3.34 KB Wed, 10 Dec 2025 11:02:13 GMT 2
10.1.0-preview.2086 3.34 KB Wed, 10 Dec 2025 10:59:10 GMT 1
10.1.0-preview.2085 3.34 KB Wed, 10 Dec 2025 10:45:17 GMT 1
10.1.0-preview.2084 3.34 KB Wed, 10 Dec 2025 10:43:08 GMT 1
10.1.0-preview.2083 3.34 KB Wed, 10 Dec 2025 10:38:09 GMT 0
10.1.0-preview.2082 3.34 KB Wed, 10 Dec 2025 10:37:37 GMT 1
10.1.0-preview.2080 3.33 KB Wed, 10 Dec 2025 10:32:38 GMT 1
10.0.2 3.32 KB Thu, 27 Nov 2025 15:29:24 GMT 1
10.0.2-preview.2077 3.34 KB Wed, 10 Dec 2025 10:26:17 GMT 1
10.0.1 3.32 KB Wed, 12 Nov 2025 22:15:46 GMT 9
10.0.0 3.31 KB Tue, 11 Nov 2025 15:03:23 GMT 11
9.0.6 3.27 KB Thu, 02 Oct 2025 10:25:41 GMT 36
9.0.5 3.26 KB Mon, 29 Sep 2025 09:00:37 GMT 34
9.0.4 3.26 KB Wed, 27 Aug 2025 08:54:17 GMT 58
9.0.3 3.26 KB Tue, 08 Jul 2025 14:08:03 GMT 75
9.0.2 3.26 KB Tue, 08 Jul 2025 10:57:38 GMT 61
9.0.1 3.26 KB Fri, 13 Jun 2025 17:17:48 GMT 79
9.0.0 3.12 KB Fri, 13 Jun 2025 15:42:56 GMT 60
8.1.4 3.25 KB Wed, 04 Jun 2025 08:36:25 GMT 74
8.1.3 3.25 KB Tue, 03 Jun 2025 09:00:28 GMT 79
8.1.1 3.23 KB Thu, 10 Apr 2025 13:00:50 GMT 74
8.1.0 3.23 KB Mon, 31 Mar 2025 12:35:13 GMT 65
8.0.0 3.23 KB Tue, 18 Mar 2025 18:14:04 GMT 72
7.3.2 3.23 KB Tue, 18 Mar 2025 08:57:01 GMT 76
7.3.1 3.24 KB Thu, 27 Feb 2025 19:22:12 GMT 74
7.3.0 3.24 KB Wed, 26 Feb 2025 11:18:50 GMT 75
7.2.0 3.23 KB Tue, 10 Dec 2024 17:22:32 GMT 61
7.1.0 2.6 KB Mon, 25 Nov 2024 11:32:53 GMT 76
7.0.0 2.6 KB Tue, 12 Nov 2024 20:25:37 GMT 64
6.9.0 2.59 KB Tue, 15 Oct 2024 10:56:57 GMT 72
6.8.1 2.31 KB Mon, 30 Sep 2024 08:51:33 GMT 72
6.8.0 2.31 KB Mon, 23 Sep 2024 09:51:49 GMT 83
6.7.3 2.32 KB Mon, 26 Aug 2024 08:35:00 GMT 74
6.7.2 2.32 KB Sat, 24 Aug 2024 11:14:28 GMT 79
6.7.1 2.31 KB Sun, 18 Aug 2024 07:30:01 GMT 74
6.7.0 2.31 KB Thu, 01 Aug 2024 10:12:26 GMT 66
6.6.2 2.31 KB Tue, 21 May 2024 16:46:08 GMT 80
6.6.1 2.31 KB Tue, 14 May 2024 08:49:48 GMT 70