实践 - .NerCore Api 使用 Swagger
1. 创建 webapi 项目
2. 默认运行效果
可能会出现异常:net::ERR_CONNECTION_RESET
3. 安装包
安装包:Swashbuckle.AspNetCore
4. 配置Swagger
https://github.com/domaindrivendev/Swashbuckle.AspNetCore
public void ConfigureServices(IServiceCollection services) { services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "My API", Version = "v1" }); }); ... } public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { ... app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1"); }); ... }
5. 效果