• 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>

    修改项目属性

  • 相关阅读:
    Chrome使用指南
    Vue2.x-踩坑记
    C# WinForm listView 多行删除 操作
    Winform中DataGridView多行删除
    20211026_阿里云服务器引流限制ssl的问题
    docker commit
    docker build
    docker build与docker commit
    阿里云Docker镜像仓库(Docker Registry)
    Docker Nginx安装(centos7)
  • 原文地址:https://www.cnblogs.com/zldqpm/p/10678223.html
Copyright © 2020-2023  润新知