OpenApiInfoOptions Class
Definition
- Namespace
- Codebelt.Extensions.Swashbuckle.AspNetCore
- Assemblies
- Codebelt.Extensions.Swashbuckle.AspNetCore.dll
Represents a proxy for configuring an Open API Info Object that provides metadata about an Open API endpoint.
public class OpenApiInfoOptions
- Inheritance
-
objectOpenApiInfoOptions
Examples
Configure OpenAPI document metadata to appear in the Swagger UI and specification. This example shows a typical setup: you call AddRestfulSwagger with a setup action, access the OpenApiInfo property to retrieve the configuration options, and then set standard OpenAPI metadata fields like title, version, description, contact information, and license. These values are merged into the generated OpenAPI specification document and displayed in the Swagger UI header and information section:
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();
// Use OpenApiInfoOptions to set document metadata
builder.Services.AddRestfulSwagger(options =>
{
// Cast to OpenApiInfoOptions to demonstrate type usage
OpenApiInfoOptions apiInfo = options.OpenApiInfo;
apiInfo.Title = "Product API";
apiInfo.Description = "API for managing product inventory";
apiInfo.Contact.Name = "API Support";
apiInfo.License.Name = "MIT";
});
var app = builder.Build();
if (string.Equals(app.Environment.EnvironmentName, "Development", StringComparison.OrdinalIgnoreCase))
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.MapControllers();
app.Run();
}
}
Properties
| Name | Description |
|---|---|
| Contact | The contact information for the exposed API. |
| Description | A short description of the application. |
| Extensions | This object MAY be extended with Specification Extensions. |
| License | The license information for the exposed API. |
| TermsOfService | A URL to the Terms of Service for the API. |
| Title | The title of the application. |