Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

38 rindas
1.4 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Threading.Tasks;
  6. using Microsoft.Extensions.DependencyInjection;
  7. using Microsoft.OpenApi.Models;
  8. namespace DataVAPI.ConfigureSwagger
  9. {
  10. public static class ConfigureSwagger
  11. {
  12. public static void AddSwaggerUp(this IServiceCollection services)
  13. {
  14. if (services == null) throw new ArgumentNullException(nameof(services));
  15. //注册Swagger
  16. services.AddSwaggerGen(c =>
  17. {
  18. c.SwaggerDoc("V1", new OpenApiInfo
  19. {
  20. Title = "黑菠萝DataV接口文档",
  21. Version = "v1",
  22. Description = $"服务API HTTP API V1",
  23. });
  24. c.OrderActionsBy(o => o.RelativePath);
  25. // 获取xml注释文件的目录
  26. var xmlPath = Path.Combine(AppContext.BaseDirectory, "DataVAPI.xml");
  27. c.IncludeXmlComments(xmlPath, true);//默认的第二个参数是false,这个是controller的注释,记得修改
  28. // 获取xml注释文件的目录
  29. var xmlPathModel = Path.Combine(AppContext.BaseDirectory, "DataVAPI.Model.xml");
  30. c.IncludeXmlComments(xmlPathModel, true);//默认的第二个参数是false,这个是controller的注释,记得修改
  31. });
  32. }
  33. }
  34. }