• .net core 中如何使用swagger?


    **1.ConfigureServices方法中注册服务**
    
    services.AddSwaggerGen(c =>
    {
      c.SwaggerDoc("v1", new OpenApiInfo
      {
        Version = "v1",
        Title = "Bingle API",
        Description = "一个简单的ASP.NET Core Web API",
        TermsOfService = new Uri("https://www.cnblogs.com/niguang"),
        Contact = new OpenApiContact
        {
          Name = "bingle",
          Email = string.Empty,
          Url = new Uri("https://www.cnblogs.com/niguang/"),
        },
        License = new OpenApiLicense
        {
          Name = "许可证",
          Url = new Uri("https://www.cnblogs.com/niguang/"),
        }
      });
      //为 Swagger JSON and UI设置xml文档注释路径
      var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
      var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
      c.IncludeXmlComments(xmlPath);
    });
    
    **2.Configure中启用服务**
    
    app.UseSwagger();
    app.UseSwaggerUI(c =>
    {
      c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
    });
    
    3.设置:选中项目--属性--生成--输出选项卡勾选“XML文档文件”
    
    4.配置完成,运行查看即可:https://localhost:44396/swagger/index.html
    
    
  • 相关阅读:
    【SDOI2014】数表
    【洛谷P4735】最大异或和
    FFT学习笔记
    【SHOI2008】堵塞的交通
    HDU 1754 I Hate It 线段树
    hdu 1166 敌兵布阵 ( 线段树或者树状数组)
    hdu 5339 Untitled dfs
    The mook jong
    hdu 5363 Key Set 快速幂
    HDU 1983 Kaitou Kid
  • 原文地址:https://www.cnblogs.com/niguang/p/13025164.html
Copyright © 2020-2023  润新知