zoukankan      html  css  js  c++  java
  • .net core webapi 中使用Swagger

    1.添加Swashbuckle.AspNetCore安装包

    方式1:使用程序包管理器控制台,安装命令:Install-Package Swashbuckle.AspNetCore 

    方式2:在Nuget包管理器:输入Swashbuckle.AspNetCore,下载安装。如下图:

    2.在Startup 文件中添加配置:

      // This method gets called by the runtime. Use this method to add services to the container.
            public void ConfigureServices(IServiceCollection services)
            {
                services.AddMvc();
                services.AddSwaggerGen(c =>
                                       {
                                           c.SwaggerDoc("v1", new Info { Title = "My API", Version = "v1" });
                                       });
    
            }
    

      

     public void Configure(IApplicationBuilder app, IHostingEnvironment env)
            {
                if (env.IsDevelopment())
                {
                    app.UseDeveloperExceptionPage();
                }
                // Enable middleware to serve generated Swagger as a JSON endpoint.
                app.UseSwagger();
    
                // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.), specifying the Swagger JSON endpoint.
                app.UseSwaggerUI(c =>
                                 {
                                     c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
                                 });
    
                app.UseMvc();
            }
    

    3.输入地址访问http://localhost:52408/swagger/访问,效果如下图:

  • 相关阅读:
    文件操作
    集合和深浅copy #
    货郎担问题TSP(dp解法)
    luoguP3413 SAC#1
    luoguP3413 SAC#1
    poj1681 Painter's Problem(gauss+dfs判定)
    日常(身怀绝技的大家)
    poj1830 开关问题(gauss)
    poj1830 开关问题(gauss)
    poj1222 EXTENDED LIGHTS OUT(gauss)
  • 原文地址:https://www.cnblogs.com/zmaiwxl/p/9050715.html
Copyright © 2011-2022 走看看