ASP.NET Core › API Documentation with Swagger/OpenAPI
How do you add global metadata (like a description, contact info, and license) to the top level of a generated OpenAPI document?
IntermediateAnswer
SwaggerDoc's OpenApiInfo object accepts a Title, Version, Description, Contact, and License, populating the top-level info section of the OpenAPI document and Swagger UI's header -- giving consumers essential context (who maintains the API, how to get support, licensing terms) beyond just the endpoint-level details.
builder.Services.AddSwaggerGen(c => {
c.SwaggerDoc("v1", new OpenApiInfo {
Title = "Order Management API",
Version = "v1",
Description = "Handles order creation, tracking, and fulfillment.",
Contact = new OpenApiContact { Name = "API Support", Email = "api-support@company.com" },
License = new OpenApiLicense { Name = "Proprietary" }
});
});Real-world example A public API's Swagger UI header prominently displays a support email and a clear description of the API's purpose, reducing the number of basic 'what does this API do' support inquiries the team receives.