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/访问,效果如下图:

  • 相关阅读:
    Vue数据双向绑定原理
    JS递归
    JS数据结构-链表
    JS数据结构-树
    React性能优化手段
    Django请求的生命周期
    Devops-git初识
    Django数据迁移的问题
    无监控,不运维!运维监控工具平台建设总结
    数据库-数据类型及主键外键
  • 原文地址:https://www.cnblogs.com/zmaiwxl/p/9050715.html
Copyright © 2011-2022 走看看