Skip to content

Commit

Permalink
Correctly extract permissions table when the HTML metadata spans more…
Browse files Browse the repository at this point in the history
… than one line
  • Loading branch information
millicentachieng committed Dec 3, 2024
1 parent 7e3329f commit 80fddf5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion ApiDoctor.Console/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static class PermissionsConstants
" For details about delegated and application permissions, see [Permission types](/graph/permissions-overview#permission-types). To learn more about these permissions, see the [permissions reference](/graph/permissions-reference).";
public const string MultipleTableBoilerPlateText = "The following tables show the least privileged permission or permissions required to call this API on each supported resource type." +
" Follow [best practices](/graph/permissions-overview#best-practices-for-using-microsoft-graph-permissions) to request least privileged permissions." +
" For details about delegated and application permissions, see [Permission types](/graph/permissions-overview#permission-types). To learn more about these permissions, see the [permissions reference](/graph/permissions-reference).";
" For details about delegated and application permissions, see [Permission types](/graph/permissions-overview#permission-types). To learn more about these permissions, see the [permissions reference](/graph/permissions-reference).";
}
public static readonly Regex FunctionParameterRegex = new(@"(?<=\=)[^)]+(?=\))", RegexOptions.Compiled, TimeSpan.FromSeconds(5));
public static readonly Regex QueryOptionSegementRegex = new(@"(\$.*)", RegexOptions.Compiled, TimeSpan.FromSeconds(5));
Expand Down
12 changes: 7 additions & 5 deletions ApiDoctor.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2647,7 +2647,7 @@ private static async Task<bool> GeneratePermissionFilesAsync(GeneratePermissionF
bool finishedParsing = false, isBootstrapped = false, ignorePermissionTableUpdate = false,
foundAllPermissionTables = false, mergePermissions = false, hasBoilerplateText = false;
int insertionStartLine = -1, insertionEndLine = -1, httpRequestStartLine = -1, httpRequestEndLine = -1, boilerplateStartLine = -1,
boilerplateEndLine = -1, permissionsHeaderIndex = -1, codeBlockAnnotationEndLine = -1, permissionsBlockLineCount = -1;
boilerplateEndLine = -1, permissionsHeaderIndex = -1, codeBlockAnnotationEndLine = -1, permissionsBlockLineCount = -1, permissionsTableStartLine = -1;
string[] requestUrlsForPermissions = null;
for (var currentIndex = 0; currentIndex < originalFileContents.Length && !finishedParsing; currentIndex++)
{
Expand All @@ -2662,8 +2662,8 @@ private static async Task<bool> GeneratePermissionFilesAsync(GeneratePermissionF
}
break;
case PermissionsInsertionState.FindInsertionStartLine:
if (foundPermissionTablesOrBlocks == 0 && currentLine.Equals(Constants.PermissionsConstants.DefaultBoilerPlateText, StringComparison.OrdinalIgnoreCase)
|| currentLine.Equals(Constants.PermissionsConstants.MultipleTableBoilerPlateText, StringComparison.OrdinalIgnoreCase))
if (foundPermissionTablesOrBlocks == 0 && (currentLine.Equals(Constants.PermissionsConstants.DefaultBoilerPlateText, StringComparison.OrdinalIgnoreCase)
|| currentLine.Equals(Constants.PermissionsConstants.MultipleTableBoilerPlateText, StringComparison.OrdinalIgnoreCase)))
{
hasBoilerplateText = true;
boilerplateStartLine = boilerplateEndLine = currentIndex;
Expand All @@ -2674,6 +2674,7 @@ private static async Task<bool> GeneratePermissionFilesAsync(GeneratePermissionF
{
isBootstrapped = true;
foundPermissionTablesOrBlocks++;
permissionsTableStartLine = currentIndex;
insertionEndLine = currentIndex; // [!INCLUDE [permissions-table]... is the end of the insertion block

if (!options.BootstrappingOnly)
Expand Down Expand Up @@ -2717,6 +2718,7 @@ private static async Task<bool> GeneratePermissionFilesAsync(GeneratePermissionF
}
else if (currentLine.Contains('|') && currentLine.Contains("Permission type", StringComparison.OrdinalIgnoreCase)) // found the permissions table
{
permissionsTableStartLine = currentIndex;
foundPermissionTablesOrBlocks++;
var annotation = ExtractCodeBlockAnnotationForPermissionsTable(
docFile.DisplayName,
Expand Down Expand Up @@ -2848,7 +2850,7 @@ private static async Task<bool> GeneratePermissionFilesAsync(GeneratePermissionF
var permissionFileContents = string.Empty;
if (!isBootstrapped)
{
var existingPermissionsTable = originalFileContents.Skip(insertionStartLine + 2).Take(insertionEndLine - insertionStartLine - 1);
var existingPermissionsTable = originalFileContents.Skip(permissionsTableStartLine).Take(insertionEndLine - permissionsTableStartLine + 1);
permissionFileContents = $"{includeFileMetadata}{ConvertToThreeColumnPermissionsTable(existingPermissionsTable, docFile.DisplayName)}";
}

Expand Down Expand Up @@ -2950,7 +2952,7 @@ private static async Task<bool> GeneratePermissionFilesAsync(GeneratePermissionF
: insertionStartLine + permissionsBlockLineCount - 1;
originalFileContents = newFileContents;
insertionStartLine = insertionEndLine = httpRequestStartLine = httpRequestEndLine =
codeBlockAnnotationEndLine = permissionsBlockLineCount = -1;
codeBlockAnnotationEndLine = permissionsBlockLineCount = permissionsTableStartLine = -1;
mergePermissions = false;
requestUrlsForPermissions = null;
foundHttpRequestBlocks = 0;
Expand Down

0 comments on commit 80fddf5

Please sign in to comment.