在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
Swaggerui 可以为我们的webapi提供美观的在线文档,如下图: 实现步骤:
1 // Register the Swagger generator, defining one or more Swagger documents 2 services.AddSwaggerGen(c => 3 { 4 c.SwaggerDoc("v1", new Info 5 { 6 Version = "v1", 7 Title = "ToDo API", 8 Description = "A simple example ASP.NET Core Web API", 9 TermsOfService = "None", 10 Contact = new Contact { Name = "Shayne Boyer", Email = "", Url = "https://twitter.com/spboyer" }, 11 License = new License { Name = "Use under LICX", Url = "https://example.com/license" } 12 }); 13 14 //Set the comments path for the swagger json and ui. 15 var basePath = PlatformServices.Default.Application.ApplicationBasePath; 16 var xmlPath = Path.Combine(basePath, "MyWebApiCore.xml"); 17 c.IncludeXmlComments(xmlPath); 18 }); 19 } 20 21 // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 22 public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) 23 { 24 loggerFactory.AddConsole(Configuration.GetSection("Logging")); 25 loggerFactory.AddDebug(); 26 27 app.UseMvc(); 28 app.UseSwagger(); 29 app.UseSwaggerUI(c => 30 { 31 c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1"); 32 }); 33 }
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论