Skip to content

Commit

Permalink
Log error if json or http block is not preceded by HTML comment metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
millicentachieng committed Feb 5, 2024
1 parent 9ce27cb commit 15c041a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
14 changes: 14 additions & 0 deletions ApiDoctor.Validation/DocFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,20 @@ protected bool ParseMarkdownBlocks(IssueLogger issues)
issues.Message($"Found description: {methodDescription}");
}
}
else if (block.BlockType == BlockType.codeblock && (block.CodeLanguage == "json" || block.CodeLanguage == "http"))
{
//If the previous block is html (metadata)
var previousBlockIndex = i - 1;
if (previousBlockIndex >= 0)
{
var previousBlock = this.OriginalMarkdownBlocks[previousBlockIndex];
if (null != previousBlock && previousBlock.BlockType != BlockType.html)
{
issues.Error(ValidationErrorCode.MissingMetadataBlock,
$"Missing metadata for code block:{Environment.NewLine}{block}");
}
}
}
else if (block.BlockType == BlockType.html)
{
// If the next block is a codeblock we've found a metadata + codeblock pair
Expand Down
1 change: 1 addition & 0 deletions ApiDoctor.Validation/Error/validationerror.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ public enum ValidationErrorCode

AmbiguousExample,
HttpMethodOutOfRange,
MissingMetadataBlock,

DeduplicationWasUnsuccessful,
IncorrectSampleKey,
Expand Down

0 comments on commit 15c041a

Please sign in to comment.