zoukankan      html  css  js  c++  java
  • dotnet webapi 中添加Swagger文档

        首先添加"SwaggerGenerator": "1.1.0","SwaggerUi": "1.1.0" 需要注意的是这两个组件是我对Swashbuckle的重新封装,因为当前版本对泛型会报错。

        在ConfigureServices 中添加:

       

     1 services.ConfigureSwaggerGen(options =>
     2             {
     3                
     4                 options.SwaggerDoc("v1",
     5                   new Info
     6                   {
     7                       Version = "v1",
     8                       Title = "ryan API",
     9                   }
    10               );
    11                 options.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, Assembly.GetEntryAssembly().GetName().Name+".xml"));
    12                 options.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, Assembly.GetEntryAssembly().GetName().Name + ".Application.xml"));
    13                 options.DescribeAllEnumsAsStrings();
    14             });

    在config方法中添加:

    1  if (HostingEnvironment.IsDevelopment())
    2             {
    3                 app.UseSwagger();
    4                 app.UseSwaggerUi(c=>c.SwaggerEndpoint("/swagger/v1/swagger.json", "V1 Docs"));
    5             }

    在controller中需要添加attribute,否则文档会生成失败。

    齐活,在浏览取中输入 http:{youhost}/swagger   即可访问了。

  • 相关阅读:
    POJ 1637:Sightseeing tour
    bzoj 3997: [TJOI2015]组合数学
    [CEOI2008]order
    【网络流24题】星际转移问题
    Codeforces Round #460 D. Karen and Cards
    bzoj 3142: [Hnoi2013]数列
    codeforces586B
    codeforces631B
    codeforces548B
    codeforces515B
  • 原文地址:https://www.cnblogs.com/ryansecreat/p/6094643.html
Copyright © 2011-2022 走看看