zoukankan      html  css  js  c++  java
  • net core swagger接口

    net swagger接口

    引用NuGet包

    Install-Package Swashbuckle.AspNetCore //控制台
    Microsoft.Extensions.PlatformAbstractions //包管理,用来获取xml根目录

    Startup

     public void ConfigureServices(IServiceCollection services)
            {
                services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
                services.AddSwaggerGen(c =>
                {
                    //var basePath = Path.GetDirectoryName(typeof(Program).Assembly.Location);//获取应用程序所在目录(绝对,不受工作目录影响,建议采用此方法获取路径)
                    //var xmlPath = Path.Combine(basePath, "swaggerApi.xml");
                    //c.IncludeXmlComments(xmlPath);
                    c.SwaggerDoc("v1", new Info
                    {
    
                        Version = "v1",
                        Title = "测试接口",
                        Description = "一个测试接口",
                        TermsOfService = "None",
                        Contact = new Contact
                        {
                            Name = "Shayne Boyer",
                            Email = string.Empty,
                            Url = "https://twitter.com/spboyer"
                        },
                        License = new License
                        {
                            Name = "Use under LICX",
                            Url = "https://example.com/license"
                        }
                    });
                });
                services.ConfigureSwaggerGen(c =>
                {
                    c.IncludeXmlComments(GetXmlSwaggerCommentsFilePath());
                });
            }
    
            private string GetXmlSwaggerCommentsFilePath()
            {
                var app = PlatformServices.Default.Application;
                return Path.Combine(app.ApplicationBasePath, Path.ChangeExtension(app.ApplicationName, "xml"));
            }

    csproj

    <PropertyGroup>
        <GenerateDocumentationFile>true</GenerateDocumentationFile>
        <NoWarn>$(NoWarn);1591</NoWarn>
      </PropertyGroup>
    
      <PropertyGroup>
        <DocumentationFile>bin$(Configuration)$(TargetFramework)$(AssemblyName).xml</DocumentationFile>
        <NoWarn>1701;1702;1591;</NoWarn>
      </PropertyGroup>

    修改项目属性

  • 相关阅读:
    U盘安装Ubuntu 14.04 LTS
    VS2013配置OPENCV2.4.9(OPENCV3.X)
    make、makefile、cmake、qmake对比
    Google C++ Style
    Ubuntu16.04搜狗输入法无法输入中文
    Ubuntu16.04安装使用wineqq
    Ubuntu卸载软件
    [机器学习入门篇]-梯度下降法
    [机器学习入门篇]-正则化
    2014年度最受好评的十佳工具
  • 原文地址:https://www.cnblogs.com/zldqpm/p/10678223.html
Copyright © 2011-2022 走看看