diff --git a/ApiDoctor.Console/Program.cs b/ApiDoctor.Console/Program.cs index 8779286b..5e72b829 100644 --- a/ApiDoctor.Console/Program.cs +++ b/ApiDoctor.Console/Program.cs @@ -2645,8 +2645,8 @@ private static async Task GeneratePermissionFilesAsync(GeneratePermissionF int foundPermissionTablesOrBlocks = 0, foundHttpRequestBlocks = 0; bool finishedParsing = false, isBootstrapped = false, ignorePermissionTableUpdate = false, foundAllPermissionTables = false, mergePermissions = false; - int insertionStartLine = -1, insertionEndLine = -1, httpRequestStartLine = -1, httpRequestEndLine = -1, - boilerplateStartLine = -1, boilerplateEndLine = -1, permissionsHeaderIndex = -1, codeBlockAnnotationEndLine = -1; + int insertionStartLine = -1, insertionEndLine = -1, httpRequestStartLine = -1, httpRequestEndLine = -1, boilerplateStartLine = -1, + boilerplateEndLine = -1, permissionsHeaderIndex = -1, codeBlockAnnotationEndLine = -1, permissionsBlockLineCount = -1; string[] requestUrlsForPermissions = null; for (var currentIndex = 0; currentIndex < originalFileContents.Length && !finishedParsing; currentIndex++) { @@ -2666,44 +2666,10 @@ private static async Task GeneratePermissionFilesAsync(GeneratePermissionF ignorePermissionTableUpdate = true; } - // Extract HTML comment - if (codeBlockAnnotationEndLine != -1 && (requestUrlsForPermissions != null || !mergePermissions)) - { - var htmlComment = insertionStartLine == codeBlockAnnotationEndLine - ? originalFileContents[insertionStartLine] - : string.Join(" ", originalFileContents.Skip(insertionStartLine).Take(codeBlockAnnotationEndLine + 1 - insertionStartLine)); - var metadataJsonString = DocFile.StripHtmlCommentTags(htmlComment); - var annotation = CodeBlockAnnotation.ParseMetadata(metadataJsonString); - if (annotation.BlockType == CodeBlockType.Permissions) - { - requestUrlsForPermissions = annotation?.RequestUrls; - mergePermissions = annotation?.MergePermissions ?? false; - } - else - { - insertionStartLine = -1; - codeBlockAnnotationEndLine = -1; - } - } - - var nextLine = currentIndex + 1 < originalFileContents.Length ? originalFileContents[currentIndex + 1].Trim() : ""; - if (currentLine.StartsWith("")) - { - codeBlockAnnotationEndLine = currentIndex; - } - } - else if (insertionStartLine >= 0 && currentLine.EndsWith("-->")) - { - codeBlockAnnotationEndLine = currentIndex; - } - else if (currentLine.Contains("[!INCLUDE [permissions-table](", StringComparison.OrdinalIgnoreCase)) // bootstrapping already took place + if (currentLine.Contains("[!INCLUDE [permissions-table](", StringComparison.OrdinalIgnoreCase)) // bootstrapping already took place { foundPermissionTablesOrBlocks++; + insertionEndLine = currentIndex; // [!INCLUDE [permissions-table]... is the end of the insertion block if (ignorePermissionTableUpdate) { FancyConsole.WriteLine(ConsoleColor.Yellow, $"Skipping update of permissions table ({foundPermissionTablesOrBlocks}) in {docFile.DisplayName}"); @@ -2712,13 +2678,65 @@ private static async Task GeneratePermissionFilesAsync(GeneratePermissionF } isBootstrapped = true; + if (!options.BootstrappingOnly) { - insertionEndLine = currentIndex; // [!INCLUDE [permissions-table]... is the end of the insertion block - parseStatus = (requestUrlsForPermissions?.Length ?? 0) == 0 - ? PermissionsInsertionState.FindHttpRequestHeading - : PermissionsInsertionState.InsertPermissionBlock; - break; + // find the permissions block start line + var previousContents = ""; + for (var i = currentIndex; i > 0; i--) + { + var lineContents = originalFileContents[i].Trim(); + if (lineContents.EndsWith("-->")) + { + codeBlockAnnotationEndLine = i; + } + else if (lineContents.StartsWith("