/// <summary> /// 配置 /// </summary> /// <param name="options"></param> public void Configure(SwaggerGenOptions options) { foreach (var group in apiExplorer.ApiDescriptionGroups.Items) { options.SwaggerDoc(group.GroupName, new OpenApiInfo { Title = $"{thisService.Name}", Version = "v" + ApiExplorerGroupNameConvention.GetApiVersion(group.GroupName).ToString() }); } }
/// <summary> /// 添加请求头 /// </summary> /// <param name="operation"></param> /// <param name="context"></param> public void Apply(OpenApiOperation operation, OperationFilterContext context) { string GetVersionName() => ApiExplorerGroupNameConvention.GetApiVersion(context.ApiDescription.GroupName).ToString(); if (operation.Parameters == null) { operation.Parameters = new List <OpenApiParameter>(); } var apiversion = new OpenApiParameter { In = ParameterLocation.Header, Required = false, Name = this.HeaderName, Style = ParameterStyle.Simple, Description = "api版本,不填则对应1.0", Schema = new OpenApiSchema { Type = "string", Default = new OpenApiString(GetVersionName()) } }; operation.Parameters.Add(apiversion); }