Swagger API documentation for a project with CQRS, mediatr pattern.
I couldn't change the logo of Swagger and descriptions to the methods in endpoints class.
Loading
Swagger API documentation for a project with CQRS, mediatr pattern.
I couldn't change the logo of Swagger and descriptions to the methods in endpoints class.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Mohamed Azarudeen ZRank #297 · 8.5K reputationPosted Jul 4, 2023, 6:04 AM EDT
Hi Ganesh
To customize the Swagger API documentation for a project with CQRS and MediatR pattern, you can use the Swashbuckle.AspNetCore library, which integrates Swagger with ASP.NET Core. Swashbuckle.AspNetCore allows you to modify various aspects of the generated Swagger UI, including the logo and method descriptions.
Here's how you can achieve this:
Install the required NuGet package:
In your
Startup.csfile, add the necessary configurations for Swashbuckle.AspNetCore.using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.OpenApi.Models; public class Startup { // ... other configurations ... public void ConfigureServices(IServiceCollection services) { // Register MediatR and CQRS related services here services.AddControllers(); // Register the Swagger generator with a custom configuration services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "Your API Title", Version = "v1", Description = "Your API Description", Contact = new OpenApiContact { Name = "Your Name", Email = "[email protected]", }, License = new OpenApiLicense { Name = "Your License", Url = new Uri("https://example.com/license"), } }); // Include XML comments (if you have enabled XML documentation generation in your project properties) // string xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; // string xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); // c.IncludeXmlComments(xmlPath); // Customize the Swagger UI c.CustomOperationIds(apiDescription => { // Use CQRS/MediatR request class names for operation IDs instead of method names return apiDescription.TryGetMethodInfo(out var methodInfo) ? methodInfo.Name : null; }); // Add the path to the logo image (you can replace "logo.png" with your image path) c.AddSwaggerLogo("logo.png", "Your API Logo"); // Optional: Provide custom descriptions for each endpoint (method) // c.OperationFilter(); }); } // ... other configurations ... public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { // ... other middleware configurations ... app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "Your API V1"); c.RoutePrefix = string.Empty; // Set the Swagger UI to the root URL }); // ... other middleware configurations ... } }Hope this helps