.net core Swashback添加所需的请求头

.net core Swashback添加所需的请求头,.net-core,swagger,swashbuckle,.net Core,Swagger,Swashbuckle,我正在实现一个RESTAPI,其中我们使用Swashback作为消费者文档。在资源的PUT端点上,我们要求使用者发送一个带有资源先前ETag的If-Match头 我们希望将此添加到Swashback文档中,但似乎没有找到如何添加的方法。我们如何向Swashbuckle中添加某些端点的If匹配头 韩国 Thomas您可以使用IOperationFilter执行此操作,下面是一个示例代码: public class AddRequiredHeaderParameters : IOperati

我正在实现一个RESTAPI,其中我们使用Swashback作为消费者文档。在资源的PUT端点上,我们要求使用者发送一个带有资源先前ETag的If-Match头

我们希望将此添加到Swashback文档中,但似乎没有找到如何添加的方法。我们如何向Swashbuckle中添加某些端点的If匹配头

韩国


Thomas

您可以使用
IOperationFilter
执行此操作,下面是一个示例代码:

    public class AddRequiredHeaderParameters : IOperationFilter
    {
        public void Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription)
        {                
            if (operation.operationId == "ValueProvider_Put")
            {
                if (operation.parameters == null)
                    operation.parameters = new List<NonBodyParameter>();
                operation.parameters.Add(HeaderParam("CID", "101"));                    
            }
        }

        public IParameter HeaderParam(string name, string defaultValue, bool required = true, string type = "string", string description = "")
        {
            return new NonBodyParameter
            {
                Name = name,
                In = "header",
                Default = defaultValue,
                Type = type,
                Description = description,
                Required = required
            };
        }
    }
公共类AddRequiredHeaderParameters:IOperationFilter
{
public void Apply(操作,SchemaRegistry SchemaRegistry,apisdescription apisdescription)
{                
if(operation.operationId==“ValueProvider\u Put”)
{
if(operation.parameters==null)
operation.parameters=新列表();
操作。参数。添加(HeaderParam(“CID”,“101”);
}
}
公共IPParameter HeaderParam(字符串名称,字符串默认值,bool required=true,字符串类型=“string”,字符串描述=“”)
{
返回新的非body参数
{
Name=Name,
In=“header”,
默认值=默认值,
类型=类型,
描述=描述,
必需的=必需的
};
}
}
我这里有一个工作样本:

下面是它在UI中的外观:

和的可能副本