You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SwaggerConfigurationExtension.cs 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. namespace Diligent.WebAPI.Host.Extensions
  2. {
  3. public static class SwaggerConfigurationExtension
  4. {
  5. public static void ConfigureSwagger(this WebApplicationBuilder builder)
  6. {
  7. IServiceCollection services = builder.Services;
  8. services.AddVersionedApiExplorer(setup =>
  9. {
  10. setup.GroupNameFormat = "'v'VVV";
  11. setup.SubstituteApiVersionInUrl = true;
  12. });
  13. services.AddSwaggerGen(options =>
  14. {
  15. var xmlFilename = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
  16. options.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, xmlFilename));
  17. }
  18. );
  19. services.ConfigureOptions<SwaggerConfigureOptions>();
  20. services.AddApiVersioning(options =>
  21. {
  22. options.AssumeDefaultVersionWhenUnspecified = true;
  23. options.ReportApiVersions = true;
  24. options.DefaultApiVersion = new ApiVersion(1, 0);
  25. options.ApiVersionReader = new UrlSegmentApiVersionReader();
  26. });
  27. }
  28. public static void ConfigureSwagger(this WebApplication app)
  29. {
  30. if (app.Environment.IsDevelopment())
  31. {
  32. app.UseSwagger();
  33. app.UseSwaggerUI(options =>
  34. {
  35. options.SwaggerEndpoint("/swagger/v1/swagger.json", "v1");
  36. options.SwaggerEndpoint("/swagger/v2/swagger.json", "v2");
  37. options.RoutePrefix = string.Empty;
  38. });
  39. }
  40. }
  41. }
  42. }