Tingle.AspNetCore.Swagger 4.7.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Tingle.AspNetCore.Swagger --version 4.7.0                
NuGet\Install-Package Tingle.AspNetCore.Swagger -Version 4.7.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Tingle.AspNetCore.Swagger" Version="4.7.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Tingle.AspNetCore.Swagger --version 4.7.0                
#r "nuget: Tingle.AspNetCore.Swagger, 4.7.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Tingle.AspNetCore.Swagger as a Cake Addin
#addin nuget:?package=Tingle.AspNetCore.Swagger&version=4.7.0

// Install Tingle.AspNetCore.Swagger as a Cake Tool
#tool nuget:?package=Tingle.AspNetCore.Swagger&version=4.7.0                

Tingle.AspNetCore.Swagger

[!CAUTION] This documentation for Tingle.AspNetCore.Swagger may not cover the most recent version of the code. Use it sparingly

See https://github.com/tinglesoftware/dotnet-extensions/issues/221

Swagger is a specification for documenting your API and specifies the format (URL, method, and representation) used to describe REST web services. This library is used to generate API documentation as well as add API documentation UI through ReDoc.

The library includes the Swashbuckle.AspNetCore.SwaggerGen library which is a Swagger generator that builds the SwaggerDocument objects directly from your routes, controllers, and models. It is combined with the Swagger endpoint middleware to automatically expose Swagger JSON.

Swashbuckle relies heavily on ApiExplorer (the API metadata layer that ships with ASP.NET Core). If using AddMvcCore for a more pared down MVC stack, you'll need to explicitly add the ApiExplorer service.

In ConfigureServices method of Program.cs, add MvcCore service, the ApiExplorer service, and register the Swagger generator defining one or more Swagger documents.

// Add swagger documents generation
builder.Services.AddSwaggerGen(options =>
{
    options
        .AddDocuments(services.BuildServiceProvider(), ConstStrings.ApiDocsTitle, System.IO.File.ReadAllText("apidesc.md"))
        .AlwaysShowAuthorizationFailedResponse()
        .AlwaysShowBadRequestResponse();

    options.IncludeXmlComments<Program>();
});

In the Configure method of Program.cs, insert middleware to expose the generated Swagger as JSON endpoints.

// Add swagger schema docs
app.MapSwagger(options => options.PreSerializeFilters.Add((swaggerDoc, httpRequest) => swaggerDoc.Host = httpRequest.Host.Value));

In the code snippet above, the SwaggerDocument and the current HttpRequest are passed to the filter thus providing a lot of flexibility. The filter will be executed prior to serializing the document.

ReDoc functionalities are described in the sections below:

ReDoc

ReDoc adds API documentation UI. It can be used to document complex request/response payloads. It also supports nested schemas and displays them in place with the ability to collapse or expand.

This library is used to add ReDoc middleware to the HTTP request pipeline. This adds API documentation UI.

Setup

Add the following code logic to Program.cs

// Add ReDoc services
builder.Services.AddReDoc(o =>
{
    o.DocumentTitle = ConstStrings.ApiDocsTitle;
    o.DefaultDocumentName = $"v{ConstStrings.ApiVersion2}";
});

var app = builder.Build();

// Add API documentation UI via ReDoc
app.MapReDoc();
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
5.0.0 89 11/19/2024
4.14.1 297 10/14/2024
4.14.0 377 9/16/2024
4.13.0 623 8/13/2024
4.12.0 184 8/7/2024
4.11.2 323 7/15/2024
4.11.1 377 6/26/2024
4.11.0 303 6/6/2024
4.10.1 102 6/5/2024
4.10.0 205 5/27/2024
4.9.0 327 5/16/2024
4.8.0 356 5/5/2024
4.7.0 600 3/25/2024