in src/Microsoft.OpenApi/Services/OpenApiFilterService.cs [25:113]
public static Func<string, OperationType?, OpenApiOperation, bool> CreatePredicate(string operationIds = null,
string tags = null, Dictionary<string, List<string>> requestUrls = null, OpenApiDocument source = null)
{
Func<string, OperationType?, OpenApiOperation, bool> predicate;
if (requestUrls != null && (operationIds != null || tags != null))
{
throw new InvalidOperationException("Cannot filter by Postman collection and either operationIds and tags at the same time.");
}
if (!string.IsNullOrEmpty(operationIds) && !string.IsNullOrEmpty(tags))
{
throw new InvalidOperationException("Cannot specify both operationIds and tags at the same time.");
}
if (operationIds != null)
{
if (operationIds == "*")
{
predicate = (url, operationType, operation) => true; // All operations
}
else
{
var operationIdsArray = operationIds.Split(',');
predicate = (url, operationType, operation) => operationIdsArray.Contains(operation.OperationId);
}
}
else if (tags != null)
{
var tagsArray = tags.Split(',');
if (tagsArray.Length == 1)
{
var regex = new Regex(tagsArray[0]);
predicate = (url, operationType, operation) => operation.Tags.Any(tag => regex.IsMatch(tag.Name));
}
else
{
predicate = (url, operationType, operation) => operation.Tags.Any(tag => tagsArray.Contains(tag.Name));
}
}
else if (requestUrls != null)
{
var operationTypes = new List<string>();
if (source != null)
{
var apiVersion = source.Info.Version;
var sources = new Dictionary<string, OpenApiDocument> {{ apiVersion, source}};
var rootNode = CreateOpenApiUrlTreeNode(sources);
// Iterate through urls dictionary and fetch operations for each url
foreach (var path in requestUrls)
{
var serverList = source.Servers;
var url = FormatUrlString(path.Key, serverList);
var openApiOperations = GetOpenApiOperations(rootNode, url, apiVersion);
if (openApiOperations == null)
{
continue;
}
// Add the available ops if they are in the postman collection. See path.Value
foreach (var ops in openApiOperations)
{
if (path.Value.Contains(ops.Key.ToString().ToUpper()))
{
operationTypes.Add(ops.Key + url);
}
}
}
}
if (!operationTypes.Any())
{
throw new ArgumentException("The urls in the Postman collection supplied could not be found.");
}
// predicate for matching url and operationTypes
predicate = (path, operationType, operation) => operationTypes.Contains(operationType + path);
}
else
{
throw new InvalidOperationException("Either operationId(s),tag(s) or Postman collection need to be specified.");
}
return predicate;
}