api post输入 输出 参数配置
services.AddControllers(options => { options.ModelMetadataDetailsProviders.Add(new ModelBindingMetadataProvider()); }).AddNewtonsoftJson(options => { //忽略循环引用 options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; // 返回数据首字母不小写 DefaultContractResolver默认大写,CamelCasePropertyNamesContractResolver是小写 options.SerializerSettings.ContractResolver = new DefaultContractResolver(); options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";//设置时间格式 }) .AddJsonOptions(options => { //让post输入参数的首字母为大写,如果不加默认为小写 options.JsonSerializerOptions.PropertyNamingPolicy = null; //options.JsonSerializerOptions.Converters.Add(new MyCustomJsonConverter()); });
配置本地查看的接口路径:
#region Swagger Api文档 第三方接口 只在开发下显示 app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/V1/swagger.json", "XHS.Build.SmartCity V1"); c.RoutePrefix = "swagger1";//根目录后加一层访问路径,与launchsettings.json 中的launchUrl保持一致 如果是IIS发布可以注释该语句,并打开launchSettings.launchUrl c.DocExpansion(Swashbuckle.AspNetCore.SwaggerUI.DocExpansion.None);//折叠Api }); #endregion
swagger配置: