zoukankan      html  css  js  c++  java
  • .NET CORE API Swagger

      新建一个core api  项目,使用nuget搜索Swashbuckle.AspNetCore   安装

     修改项目生成属性

    修改启动Startup

     public void ConfigureServices(IServiceCollection services)
            {
                services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
    
                #region Swagger
                services.AddSwaggerGen(c =>
                {
                    c.SwaggerDoc("v1", new Info
                    {
                        Version = "v0.1.0",
                        Title = "Blog.Core API",
                        Description = "框架说明文档",
                        TermsOfService = "None",
                        Contact = new Swashbuckle.AspNetCore.Swagger.Contact { Name = "core-test", Email = "1165220871@qq.com", Url = "" }
                    });
                    var basePath = Microsoft.DotNet.PlatformAbstractions.ApplicationEnvironment.ApplicationBasePath;
                    var xmlPath = Path.Combine(basePath, "core-test.xml");//这个就是上面图片中xml文件名
                    c.IncludeXmlComments(xmlPath, true);//默认的第二个参数是false,这个是controller的注释,记得修改
                });
                #endregion
    
            }
    
       public void Configure(IApplicationBuilder app, IHostingEnvironment env)
            {
                if (env.IsDevelopment())
                {
                    app.UseDeveloperExceptionPage();
                    #region Swagger
                    app.UseSwagger();
                    app.UseSwaggerUI(c =>
                    {
                        c.SwaggerEndpoint("/swagger/v1/swagger.json", "ApiHelp V1");
                    });
                    #endregion
                }
                app.UseMvc();
            }

    现在默认启动的路径是http://localhost:60442/api/values,需要修改一下launchSettings.json文件

    然后直接启动项目

      

  • 相关阅读:
    MySQL严格模式总结
    python筛选关键字---error
    将pem证书转换成p12格式证书
    ## 游戏网关源码赏析
    pid获取
    顺序io_磁盘队列
    nsq源码阅读3_编译nsqd
    nsq源码阅读2_核心数据结构
    nsq源码阅读1_目录结构
    如何设计Mqtt的Retain?
  • 原文地址:https://www.cnblogs.com/li-lun/p/9579982.html
Copyright © 2011-2022 走看看