Table of Contents

RestfulSwaggerOptions Class

Definition

Namespace
Codebelt.Extensions.Swashbuckle.AspNetCore
Assemblies
Codebelt.Extensions.Swashbuckle.AspNetCore.dll
Source
src/Codebelt.Extensions.Swashbuckle.AspNetCore/RestfulSwaggerOptions.cs

Provides programmatic configuration for the AddRestfulSwagger(IServiceCollection, Action<RestfulSwaggerOptions>) method.

public class RestfulSwaggerOptions : IValidatableParameterObject, IParameterObject
Inheritance
object
RestfulSwaggerOptions
Implements

Examples

Customize Swagger generation and UI settings for a RESTful API. The RestfulSwaggerOptions type bundles all configuration aspects: OpenAPI document metadata, XML documentation loading, and schema generation options. This example shows how to configure core settings:

using System;
using Codebelt.Extensions.Swashbuckle.AspNetCore;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;

namespace MySwaggerExample;

public class Program
{
    public static void Main(string[] args)
    {
        var builder = WebApplication.CreateBuilder(args);

        builder.Services.AddControllers();
        builder.Services.AddEndpointsApiExplorer();

        // Configure RestfulSwaggerOptions with customized settings
        builder.Services.AddRestfulSwagger(rawOptions =>
        {
            // Explicitly declare RestfulSwaggerOptions type
            RestfulSwaggerOptions options = rawOptions;

            // Configure document metadata through OpenApiInfo property
            options.OpenApiInfo.Title = "My REST API";
            options.OpenApiInfo.Description = "A sample API documentation";
            options.OpenApiInfo.Contact.Name = "API Support";

            // Enable XML documentation comments
            options.XmlDocumentations.AddByType<Program>();

            // Configure Swagger generation through Settings
            options.Settings.UseAllOfToExtendReferenceSchemas();
        });

        var app = builder.Build();

        if (string.Equals(app.Environment.EnvironmentName, "Development", StringComparison.OrdinalIgnoreCase))
        {
            app.UseSwagger();
            app.UseSwaggerUI();
        }

        app.MapControllers();
        app.Run();
    }
}

Constructors

Name Description
RestfulSwaggerOptions()

Initializes a new instance of the RestfulSwaggerOptions class.

Properties

Name Description
IncludeControllerXmlComments

Flag to indicate if controller XML comments (i.e. summary) should be used to assign Tag descriptions. Don't set this flag if you're customizing the default tag for operations via TagActionsBy.

JsonSerializerOptionsFactory

Gets or sets the function delegate that will resolve a JsonSerializerOptions instance.

OpenApiInfo

Gets or sets the open API information that may be configured.

Settings

Gets or sets the SwaggerGenOptions used to configure Swagger.

XmlDocumentations

Gets or sets a list of XML documentations to apply to a Swagger document.

Methods

Name Description
ValidateOptions()

Determines whether the public read-write properties of this instance are in a valid state.