Table of Contents

Class UserAgentDocumentOptions

Namespace
Codebelt.Extensions.Swashbuckle.AspNetCore
Assembly
Codebelt.Extensions.Swashbuckle.AspNetCore.dll

Provides programmatic configuration for the UserAgentDocumentFilter class.

public class UserAgentDocumentOptions : IParameterObject
Inheritance
UserAgentDocumentOptions
Implements

Examples

Control the documentation of user-agent header in the OpenAPI specification. This example demonstrates the full setup workflow: you call AddSwaggerGen with a setup action, then call AddUserAgent with a configuration action, and within that action you configure the UserAgentDocumentOptions to control whether the header is required and what description appears in the API documentation. The configured options are then applied globally to all endpoints in the generated OpenAPI specification:

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();

        builder.Services.AddSwaggerGen(options =>
        {
            // Configure user-agent header documentation using UserAgentDocumentOptions
            options.AddUserAgent(userAgentOptionsParam =>
            {
                // Cast to UserAgentDocumentOptions to demonstrate type usage
                UserAgentDocumentOptions userAgentOptions = userAgentOptionsParam;
                
                userAgentOptions.Required = true;
                userAgentOptions.Description = "Client application identifier";
            });
        });

        var app = builder.Build();

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

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

Constructors

UserAgentDocumentOptions()

Initializes a new instance of the UserAgentDocumentOptions class.

public UserAgentDocumentOptions()

Remarks

The following table shows the initial property values for an instance of UserAgentDocumentOptions.

PropertyInitial Value
DescriptionThe identifier of the calling client.
ExampleYour-Awesome-Client/1.0.0
Requiredfalse

Properties

Description

Gets or sets the description of the User-Agent field.

public string Description { get; set; }

Property Value

string

The description of the User-Agent field.

Example

Gets or sets the example to associate with the User-Agent field.

public string Example { get; set; }

Property Value

string

The example to associate with the User-Agent field.

Required

Gets or sets whether the User-Agent field is mandatory.

public bool Required { get; set; }

Property Value

bool

true if the User-Agent field is mandatory; otherwise, false.