zoukankan      html  css  js  c++  java
  • .NetCore3.1配置Swagger==》显示接口XML以及实体XML

    一、在Startup中进行配置以及调用

    #region swagger接口帮助文档 在ConfigureServices中注册服务
    
                services.AddHttpClient();
                services.AddSingleton<MessageHandleService>();
                services.AddHostedService<MessageFileSaveService>();
                if (configuration["tencentIM:syncMessage"] == "1")
                {
                    services.AddHostedService<MessageManageService>();
                }
    
                services.AddSwaggerGen(c =>
                {
                    c.SwaggerDoc("v1", new OpenApiInfo
                    {
                        Title = "接口名称-自定义",
                        Version = "v1.0",
                        Description = "框架说明文档"
                    }
                    );
                    // 为 Swagger 设置xml文档注释路径
                    var basePath = AppContext.BaseDirectory;
                    //var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
              
              
              //当前接口目录下生成该文件 binDebug
    etcoreapp3.1MyDemo.WebApi.xml

    var xmlPath = Path.Combine(basePath, "MyDemo.WebApi.xml");
              if (File.Exists(xmlPath))
                    {
                        c.IncludeXmlComments(xmlPath, true);
                    }
              //当前接口目录下生成该文件 binDebug
    etcoreapp3.1MyDemo.Data.xml
                    var xmlModelPath = Path.Combine(basePath, "MyDemo.Data.xml");
              
    if (File.Exists(xmlModelPath))
              {
                 c.IncludeXmlComments(xmlModelPath);
              }
              });
              }
    #endregion
       public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
            {
                if (env.IsDevelopment())
                {
                    app.UseDeveloperExceptionPage();
                }
                else
                {
    
                }
    
                app.UseRouting();
            
           //将中间件添加到管道中
    app.UseSwagger(); app.UseSwaggerUI(option
    => { option.SwaggerEndpoint("/swagger/v1/swagger.json", "MyDemo-API"); }); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }

    二、配置XML文档的输出路径-右击项目-生成标志

     

     

     

     

  • 相关阅读:
    C# 中文件路径的操作
    字符串模式匹配KMP算法
    SLG游戏关卡设计
    android 源码包结构分析
    NIO的理解
    显示单位
    多线程时控制并发数据库操作的思路
    使用异常机制的建议
    合理的使用索引。《Map的使用》
    android源码的下载方法Windows
  • 原文地址:https://www.cnblogs.com/ABC-wangyuhan/p/14705876.html
Copyright © 2011-2022 走看看