diff --git a/src/libraries/Microsoft.PowerFx.Connectors/OpenApiExtensions.cs b/src/libraries/Microsoft.PowerFx.Connectors/OpenApiExtensions.cs index 8553cf4921..a754b80cc7 100644 --- a/src/libraries/Microsoft.PowerFx.Connectors/OpenApiExtensions.cs +++ b/src/libraries/Microsoft.PowerFx.Connectors/OpenApiExtensions.cs @@ -722,6 +722,11 @@ internal static OptionSet TryAddOptionSet(this SymbolTable symbolTable, OptionSe throw new ArgumentNullException("optionSet"); } + if (symbolTable == null) + { + return optionSet; + } + string name = optionSet.EntityName; // No existing symbols with that name diff --git a/src/tests/Microsoft.PowerFx.TexlFunctionExporter.Shared/SwaggerFileIdentification.cs b/src/tests/Microsoft.PowerFx.TexlFunctionExporter.Shared/SwaggerFileIdentification.cs index f8a4f91028..1370fa81ba 100644 --- a/src/tests/Microsoft.PowerFx.TexlFunctionExporter.Shared/SwaggerFileIdentification.cs +++ b/src/tests/Microsoft.PowerFx.TexlFunctionExporter.Shared/SwaggerFileIdentification.cs @@ -4,8 +4,10 @@ using System; using System.Collections.Generic; using System.Data; +using System.Globalization; using System.IO; using System.Linq; +using System.Text.RegularExpressions; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Readers; using Microsoft.OpenApi.Readers.Exceptions; @@ -110,7 +112,21 @@ public static Dictionary LocateSwaggerFiles(string[] folders, st } else { - throw new InvalidDataException($"Two documents with same number of operations, can't determine which one to select {new KeyValuePair errors)>>(swagger.Key, docs).GetString()}"); + int firstVersion = GetVersion(first.location); + int secondVersion = GetVersion(second.location); + + if (firstVersion > secondVersion) + { + list2.Add(swagger.Key, first); + } + else if (firstVersion < secondVersion) + { + list2.Add(swagger.Key, second); + } + else + { + throw new InvalidDataException($"Two documents with same number of operations, can't determine which one to select {new KeyValuePair errors)>>(swagger.Key, docs).GetString()}"); + } } } } @@ -128,6 +144,15 @@ public static Dictionary LocateSwaggerFiles(string[] folders, st return list2; } + // searches '[v or V]' pattern + private static readonly Regex _versionRegex = new Regex(@"\b[vV](?[0-9]+)\\", RegexOptions.Compiled); + + private static int GetVersion(string str) + { + Match m = _versionRegex.Match(str); + return m.Success && int.TryParse(m.Groups["v"].Value, CultureInfo.InvariantCulture.NumberFormat, out int ver) ? ver : 0; + } + private static void ParseSwagger(string folder, string swaggerFile, Dictionary errors)>> list) { (OpenApiDocument doc, List errors) = ReadSwagger(swaggerFile);