Skip to content

Commit

Permalink
Merged PR 159641: support for colspans in param tables
Browse files Browse the repository at this point in the history
support for "table sections" delineated with column spans containing a single cell with a bolded title
  • Loading branch information
daspek committed Jul 25, 2018
1 parent 9033781 commit c370305
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
1 change: 0 additions & 1 deletion ApiDoctor.Validation/DocFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,6 @@ protected bool ParseMarkdownBlocks(IssueLogger issues)
catch (Exception ex)
{
issues.Error(ValidationErrorCode.MarkdownParserError, $"Failed to parse table.", ex);
throw;
}
}

Expand Down
35 changes: 25 additions & 10 deletions ApiDoctor.Validation/TableSpec/tablespecconverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,16 +175,31 @@ private static IEnumerable<ErrorDefinition> ParseErrorTable(IMarkdownTable table

private static IEnumerable<ParameterDefinition> ParseParameterTable(IMarkdownTable table, ParameterLocation location, TableDecoder decoder, IssueLogger issues, bool navigationProperties = false)
{
var records = table.RowValues.Select(r => new ParameterDefinition
{
Name = r.ValueForColumn(table, decoder.ParseRule.ColumnNames["name"]),
Type = r.ValueForColumn(table, decoder.ParseRule.ColumnNames["type"]).ParseParameterDataType(defaultValue: ParameterDataType.String),
Description = r.ValueForColumn(table, decoder.ParseRule.ColumnNames["description"]),
Required = r.ValueForColumn(table, decoder.ParseRule.ColumnNames["description"]).IsRequired(),
Optional = r.ValueForColumn(table, decoder.ParseRule.ColumnNames["description"]).IsOptional(),
Location = location,
IsNavigatable = navigationProperties,
}).ToList();
// tables sometimes have column spans to delineate different sections of the table. for instance:
//
// | Name | Type | Description
// |------|--------|--------------
// | one | int | first number
// | two | int | second number
// | **fancy numbers**
// | pi | double | third number
//
// our markdown parser captures this as a regular row with all the columns, except with &nbsp; for all the blanks.
// we try to infer such rows by looking for a **bold** first cell, followed by nbsp in all the other cells.
// see below.

var records = table.RowValues.
Where(r => !r[0].StartsWith("**") || r.Skip(1).Any(c => c != "&nbsp;")). // see comment above
Select(r => new ParameterDefinition
{
Name = r.ValueForColumn(table, decoder.ParseRule.ColumnNames["name"]),
Type = r.ValueForColumn(table, decoder.ParseRule.ColumnNames["type"]).ParseParameterDataType(defaultValue: ParameterDataType.String),
Description = r.ValueForColumn(table, decoder.ParseRule.ColumnNames["description"]),
Required = r.ValueForColumn(table, decoder.ParseRule.ColumnNames["description"]).IsRequired(),
Optional = r.ValueForColumn(table, decoder.ParseRule.ColumnNames["description"]).IsOptional(),
Location = location,
IsNavigatable = navigationProperties,
}).ToList();

var badRows = records.Count(r => string.IsNullOrEmpty(r.Name));
if (badRows > 0)
Expand Down

0 comments on commit c370305

Please sign in to comment.