Asp.net 코어 WebApi 사용 허세

1, 설치 :

NuGet : 검색 자신감, 설치 Swashbuckle.AspNetCore

 

 

 2, 구성 XML 파일 : 오른쪽 프로젝트 - --xml 문서를 생성, 위치 XML 문서를 기록하고 3 단계에서 XML 문서의 이름을 변경

 

 3, 미들웨어 구성 자신감

// This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
            //注册Swagger生成器,定义一个和多个Swagger 文档
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1.0", new Info { Title = "My Demo API", Version = "1.0" });
                c.IncludeXmlComments(System.IO.Path.Combine(System.AppContext.BaseDirectory, "SwaggerCoreApi.xml"));
            });
        }
View Code
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseMvc();
            app.UseSwagger();
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1.0/swagger.json", "My Demo API (V 1.0)");
            });
        }
View Code

4、启动更改:右键项目--调试--启动浏览器中输入:swagger  点保存。

 

 5、配置好后直接启动api就可以看到效果了。

 

参考:https://www.cnblogs.com/lucky_hu/p/11130209.html

代码地址:https://github.com/bill1411/mybase/tree/master/Solution/CoreApi

추천

출처www.cnblogs.com/yhnet/p/12156823.html