引用

通过Nuget下载 Swashbuckle.AspNetCore 

 

修改Startup.cs

 

ConfigureServices Method添加以下

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo { Title = "My API", Version = "v1" });
                // Set the comments path for the Swagger JSON and UI.
                var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
                var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
                c.IncludeXmlComments(xmlPath);
            });

 

Configure Method添加以下

            app.UseSwagger();
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
            });

 

为了能正常输出我们的XML注释,需要再修改项目的 .csproj文件

 

  <PropertyGroup>
    <GenerateDocumentationFile>true</GenerateDocumentationFile>
    <NoWarn>$(NoWarn);1591</NoWarn>
  </PropertyGroup>

打开访问 https://<url>:<port>/swagger/index.html 就可以进入主页

微信截图_20200111000042.png

        /// <summary>
        /// 获取JWT TOKEN
        /// </summary>
        /// <remarks>
        /// Sample request:
        ///
        ///     POST /Token
        ///     {
        ///        "code": "002",
        ///        "pwd": "222222",
        ///     }
        ///
        /// </remarks>
        /// <param name="code">用户主键ID</param>
        /// <param name="pwd">用户密码</param>
        /// <returns>ComplexToken模型</returns>
        /// <response code="201">返回一个ComplexToken模型,里面包含了Token,RefreshToken以及他们各自的过期时间</response>
        [HttpGet]
        [ProducesResponseType(StatusCodes.Status201Created)]

 

库地址:https://github.com/swagger-api/swagger-ui 

评论

想当第一个评论家吗?

提交评论