You could use expressions to conditionally set the value on the global scope.
For example, if I know that the template for the swaggerUI on all my APIs is going to be "/swagger" I can use that to determine how to set the headers on the global scope.
I can go into the code editor for my global scope and add my CORS policy like this:
<cors>
<allowed-origins>
<origin>@{
bool swaggerPage = context.Operation.UrlTemplate == "/swagger";
if(swaggerPage) {
return "*";
}
else {
return null;
}
}</origin>
</allowed-origins>
<allowed-methods>
<method>GET</method>
<method>POST</method>
</allowed-methods>
</cors>
Expressions are created using C# 7, though only a subset of types are available. There is a lot of flexibility here to adjust your policies based on the request context. You can read about the options available in the docs: https://learn.microsoft.com/en-us/azure/api-management/api-management-policy-expressions