Azure / Azure/azure-api-management-policy-toolkit
`CheckHeaderConfig` forces `Values` be defined, but should be optional
- Dominant language
- C#
- Stars
- 94
- Forks
- 36
- Avg merge
- 2d 6m
- Merged PRs (30d)
- 6
Description
### Report
According to https://learn.microsoft.com/en-us/azure/api-management/check-header-policy the `CheackHeader` policy does not require values.
We use this policy to check the presence of a header, but not enforce a specific value. For example:
context.CheckHeader(new CheckHeaderConfig()
{
Name = "x-correlation-id",
FailCheckErrorMessage = "Bad request. Missing correlation id in headers",
FailCheckHttpCode = 400,
IgnoreCase = false,
Values = []
});
### Expected Behavior
The `Values` param does not need to be specified, or an empty array be permitted - in either case the resultant XML `` element would not contain any `` elements
### Actual Behavior
`Values` is required, so must be provided. When it is, but left as empty, then the following error is encountered on compilation:
> error APIM2007: Required 'Values' parameter for 'check-header' policy is empty but needs at least one element
Due to the above error the resultant XML does not include the `` output
### Steps to Reproduce the Problem
This should be a minimum viable example:
```CSHARP
using Microsoft.Azure.ApiManagement.PolicyToolkit.Authoring;
using Microsoft.Azure.ApiManagement.PolicyToolkit.Authoring.Expressions;
namespace SomeNamespace
{
[Document(Scope = DocumentScope.Api)]
public class AllOperations : IDocument
{
public void Inbound(IInboundContext context)
{
context.Base();
context.CheckHeader(new CheckHeaderConfig()
{
Name = "x-correlation-id",
FailCheckErrorMessage = "Bad request. Missing correlation id in headers",
FailCheckHttpCode = 400,
IgnoreCase = false,
Values = []
});
}
}
}
```
### Component
Compiler
### Version
Main
### Contact Details
_No response_
### Additional Information
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.