Skip to content

Commit

Permalink
Merge branch 'main' into lucgen/norel2
Browse files Browse the repository at this point in the history
  • Loading branch information
LucGenetier authored Nov 27, 2024
2 parents aac108b + ef55044 commit 7e0825f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -110,7 +112,21 @@ public static Dictionary<string, string> LocateSwaggerFiles(string[] folders, st
}
else
{
throw new InvalidDataException($"Two documents with same number of operations, can't determine which one to select {new KeyValuePair<string, List<(string folder, string location, OpenApiDocument document, List<string> 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<string, List<(string folder, string location, OpenApiDocument document, List<string> errors)>>(swagger.Key, docs).GetString()}");
}
}
}
}
Expand All @@ -128,6 +144,15 @@ public static Dictionary<string, string> LocateSwaggerFiles(string[] folders, st
return list2;
}

// searches '<space>[v or V]<number>' pattern
private static readonly Regex _versionRegex = new Regex(@"\b[vV](?<v>[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<string, List<(string folder, string location, OpenApiDocument document, List<string> errors)>> list)
{
(OpenApiDocument doc, List<string> errors) = ReadSwagger(swaggerFile);
Expand Down

0 comments on commit 7e0825f

Please sign in to comment.