-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomerQueryParameter.cs
More file actions
38 lines (35 loc) · 1.34 KB
/
CustomerQueryParameter.cs
File metadata and controls
38 lines (35 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using Microsoft.Extensions.Configuration;
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen;
using System.Collections.Generic;
namespace NetPro.Swagger
{
public class CustomerQueryParameter : IOperationFilter
{
private readonly IConfiguration _configuration;
public CustomerQueryParameter(IConfiguration configuration)
{
_configuration = configuration;
}
public void Apply(OpenApiOperation operation, OperationFilterContext context)
{
if (operation.Parameters == null)
{
operation.Parameters = new List<OpenApiParameter>();
}
var queryArray = _configuration.GetSection("SwaggerOption:Query").Get<List<OpenApiParameter>>();
if (queryArray == null) return;
foreach (var query in queryArray)
{
//本地localhost会导致自定义query或header无法显示,出现Could not render this component, see the console.错误,用网卡地址显示即可正常
operation.Parameters.Add(new OpenApiParameter
{
Name = query.Name,
In = ParameterLocation.Query,
Required = false,
Description = query.Description,
});
}
}
}
}