Reputation: 171
I am implementing a REST api where we use Swashbuckle as the consumer documentation. On our PUT endpoints for our resources we require that the consumer sends an If-Match header with the previous ETag of the resource.
We want to add this to the Swashbuckle documentation but do not seem to find how. How can we add to Swashbuckle that for certain endpoints the If-Match header is required?
Kr,
Thomas
Upvotes: 3
Views: 5231
Reputation: 17594
You can do that using an IOperationFilter
here is a sample code:
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
};
}
}
I have a working sample here:
And here is how it looks in the UI:
Upvotes: 3