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

  • 相关阅读:
    rsync+sersync实现文件同步
    HTTP 响应码
    ipv4和ipv6的区别
    查看linux系统版本信息
    MQ基础知识学习
    自动化测试的框架介绍和选择
    python(目录)
    分布式和集群
    raid 工作模式 raid0 raid1 raid10 raid5
    CentOS Docker安装
  • 原文地址:https://www.cnblogs.com/zmaiwxl/p/9050715.html
Copyright © 2011-2022 走看看