コード例 #1
0
        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();

            var badRows = records.Count(r => string.IsNullOrEmpty(r.Name));

            if (badRows > 0)
            {
                var tableHeaders = $"|{ string.Join("|", table.ColumnHeaders)}|";
                if (badRows == records.Count)
                {
                    issues.Warning(ValidationErrorCode.MarkdownParserError, $"Failed to parse any rows out of table with headers: {tableHeaders}");
                    return(Enumerable.Empty <ParameterDefinition>());
                }

                issues.Warning(ValidationErrorCode.ParameterParserError, $"Failed to parse {badRows} row(s) in table with headers: {tableHeaders}");
                records = records.Where(r => !string.IsNullOrEmpty(r.Name)).ToList();
            }

            return(records);
        }
コード例 #2
0
 private TableDecoder FindDecoderFromShape(IMarkdownTable table)
 {
     // TODO: Attempt to match this table based on the columns that are available
     return(new TableDecoder {
         Type = TableBlockType.Unknown
     });
 }
コード例 #3
0
        public static string ValueForColumn(this string[] rowValues, IMarkdownTable table, string[] possibleHeaderNames, List <string> usedColumns = null, bool removeMarkdownSyntax = true)
        {
            if (usedColumns == null)
            {
                usedColumns = new List <string>();
            }

            var headers = table.ColumnHeaders;

            foreach (var headerName in possibleHeaderNames.Except(usedColumns))
            {
                int index = headers.IndexOf(headerName);
                if (index >= 0 && index < rowValues.Length)
                {
                    // Check to see if we need to clean up / remove any formatting marks
                    string tableCellContents = rowValues[index];

                    if (removeMarkdownSyntax && !string.IsNullOrEmpty(tableCellContents))
                    {
                        tableCellContents = converter.Transform(tableCellContents).TrimEnd();
                    }
                    usedColumns.Add(headerName);
                    return(tableCellContents);
                }
            }

            Debug.WriteLine("Failed to find header matching '{0}' in table with headers: {1}",
                            possibleHeaderNames.ComponentsJoinedByString(","),
                            table.ColumnHeaders.ComponentsJoinedByString(","));
            return(null);
        }
コード例 #4
0
        public static string ValueForColumn(this string[] rowValues, IMarkdownTable table, params string[] possibleHeaderNames)
        {
            var headers = table.ColumnHeaders;

            foreach (var headerName in possibleHeaderNames)
            {
                int index = headers.IndexOf(headerName);
                if (index >= 0 && index < rowValues.Length)
                {
                    // Check to see if we need to clean up / remove any formatting marks
                    string tableCellContents = rowValues[index];
                    if (null != tableCellContents)
                    {
                        return(tableCellContents.Trim(' ', '`', '*', '_'));
                    }
                    else
                    {
                        return(null);
                    }
                }
            }

            Debug.WriteLine("Failed to find header matching '{0}' in table with headers: {1}",
                            possibleHeaderNames.ComponentsJoinedByString(","),
                            table.ColumnHeaders.ComponentsJoinedByString(","));
            return(null);
        }
コード例 #5
0
        private static IEnumerable <EnumerationDefinition> ParseEnumerationTable(IMarkdownTable table)
        {
            var records = from r in table.RowValues
                          select new EnumerationDefinition
            {
                Value       = r.ValueForColumn(table, "Value"),
                Description = r.ValueForColumn(table, "Description")
            };

            return(records);
        }
コード例 #6
0
        private static IEnumerable <EnumerationDefinition> ParseEnumerationTable(IMarkdownTable table, TableDecoder decoder)
        {
            var records = from r in table.RowValues
                          select new EnumerationDefinition
            {
                Value       = r.ValueForColumn(table, decoder.ParseRule.ColumnNames["value"]),
                Description = r.ValueForColumn(table, decoder.ParseRule.ColumnNames["description"])
            };

            return(records);
        }
コード例 #7
0
        private static IEnumerable <AuthScopeDefinition> ParseAuthScopeTable(IMarkdownTable table)
        {
            var records = from r in table.RowValues
                          select new AuthScopeDefinition
            {
                Scope       = r.ValueForColumn(table, "Scope Name"),
                Title       = r.ValueForColumn(table, "Title"),
                Description = r.ValueForColumn(table, "Description"),
                Required    = r.ValueForColumn(table, "Required").ToBoolean()
            };

            return(records);
        }
コード例 #8
0
        private static IEnumerable <ParameterDefinition> ParseHeadersTable(IMarkdownTable table)
        {
            var records = from r in table.RowValues
                          select new ParameterDefinition
            {
                Name        = r.ValueForColumn(table, "Name", "Header Name"),
                Type        = JsonDataType.String,
                Description = r.ValueForColumn(table, "Description"),
                Location    = ParameterLocation.Header
            };

            return(records);
        }
コード例 #9
0
        /// <summary>
        /// Convert a markdown table into ErrorDefinition objects
        /// </summary>
        /// <param name="table"></param>
        /// <returns></returns>
        private static IEnumerable <ErrorDefinition> ParseErrorTable(IMarkdownTable table)
        {
            var records = from r in table.RowValues
                          select new ErrorDefinition
            {
                HttpStatusCode    = r.ValueForColumn(table, "HTTP Code"),
                HttpStatusMessage = r.ValueForColumn(table, "HTTP Error Message"),
                ErrorCode         = r.ValueForColumn(table, "Error Code"),
                Description       = r.ValueForColumn(table, "Error Message")
            };

            return(records);
        }
コード例 #10
0
        private static IEnumerable <AuthScopeDefinition> ParseAuthScopeTable(IMarkdownTable table, TableDecoder decoder)
        {
            var records = from r in table.RowValues
                          select new AuthScopeDefinition
            {
                Scope       = r.ValueForColumn(table, decoder.ParseRule.ColumnNames["scope"]),
                Title       = r.ValueForColumn(table, decoder.ParseRule.ColumnNames["title"]),
                Description = r.ValueForColumn(table, decoder.ParseRule.ColumnNames["description"]),
                Required    = r.ValueForColumn(table, decoder.ParseRule.ColumnNames["required"]).ToBoolean()
            };

            return(records);
        }
コード例 #11
0
        /// <summary>
        /// Convert a markdown table into ErrorDefinition objects
        /// </summary>
        /// <param name="table"></param>
        /// <returns></returns>
        private static IEnumerable <ErrorDefinition> ParseErrorTable(IMarkdownTable table, TableDecoder decoder)
        {
            var records = from r in table.RowValues
                          select new ErrorDefinition
            {
                HttpStatusCode    = r.ValueForColumn(table, decoder.ParseRule.ColumnNames["httpStatusCode"]),
                HttpStatusMessage = r.ValueForColumn(table, decoder.ParseRule.ColumnNames["httpStatusMessage"]),
                ErrorCode         = r.ValueForColumn(table, decoder.ParseRule.ColumnNames["errorCode"]),
                Description       = r.ValueForColumn(table, decoder.ParseRule.ColumnNames["description"])
            };

            return(records);
        }
コード例 #12
0
        private static IEnumerable <ParameterDefinition> ParseParameterTable(IMarkdownTable table, ParameterLocation location)
        {
            var records = from r in table.RowValues
                          select new ParameterDefinition
            {
                Name        = r.ValueForColumn(table, "Parameter Name", "Property Name", "Name"),
                Type        = r.ValueForColumn(table, "Type", "Value").ToDataType(),
                Description = r.ValueForColumn(table, "Description"),
                Location    = location,
                Required    = r.ValueForColumn(table, "Description").IsRequired()
            };

            return(records);
        }
コード例 #13
0
        private static IEnumerable <ParameterDefinition> ParseParameterTable(IMarkdownTable table, ParameterLocation location, TableDecoder decoder, bool navigationProperties = false)
        {
            var records = from r in table.RowValues
                          select 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(),
                Location      = location,
                IsNavigatable = navigationProperties
            };

            return(records);
        }
コード例 #14
0
        private static IEnumerable <ParameterDefinition> ParseParameterTable(IMarkdownTable table, ParameterLocation location, TableDecoder decoder, IssueLogger issues, bool navigationProperties = false)
        {
            // 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)
            {
                var tableHeaders = $"|{ string.Join("|", table.ColumnHeaders)}|";
                if (badRows == records.Count)
                {
                    issues.Warning(ValidationErrorCode.MarkdownParserError, $"Failed to parse any rows out of table with headers: {tableHeaders}\nTable was parsed as {decoder.ParseAs}, which requires a name column called one of the following: {{ {String.Join(",", decoder.ParseRule.ColumnNames["name"])} }}");
                    return(Enumerable.Empty <ParameterDefinition>());
                }

                issues.Warning(ValidationErrorCode.ParameterParserError, $"Failed to parse {badRows} row(s) in table with headers: {tableHeaders}");
                records = records.Where(r => !string.IsNullOrEmpty(r.Name)).ToList();
            }

            return(records);
        }
コード例 #15
0
        private static IEnumerable <EnumerationDefinition> ParseEnumerationTable(IMarkdownTable table, TableDecoder decoder)
        {
            List <EnumerationDefinition> records = new List <EnumerationDefinition>();

            foreach (var r in table.RowValues)
            {
                var usedColumns = new List <string>();
                records.Add(new EnumerationDefinition
                {
                    MemberName   = r.ValueForColumn(table, decoder.ParseRule.ColumnNames["memberName"], usedColumns),
                    NumericValue = r.ValueForColumn(table, decoder.ParseRule.ColumnNames["numericValue"], usedColumns).ToInt32(),
                    Description  = r.ValueForColumn(table, decoder.ParseRule.ColumnNames["description"], usedColumns),
                    TypeName     = decoder.Stamp,
                    IsFlags      = decoder.IsFlags,
                });
            }

            return(records);
        }
コード例 #16
0
 private TableDecoder FindDecoderFromShape(IMarkdownTable table)
 {
     // TODO: Attempt to match this table based on the columns that are available
     return new TableDecoder { Type = TableBlockType.Unknown };
 }
コード例 #17
0
 private static IEnumerable<EnumerationDefinition> ParseEnumerationTable(IMarkdownTable table)
 {
     var records = from r in table.RowValues
                   select new EnumerationDefinition
                   {
                       Value = r.ValueForColumn(table, "Value"),
                       Description = r.ValueForColumn(table, "Description")
                   };
     return records;
 }
コード例 #18
0
        /// <summary>
        /// Convert a markdown table into ErrorDefinition objects
        /// </summary>
        /// <param name="table"></param>
        /// <returns></returns>
        private static IEnumerable<ErrorDefinition> ParseErrorTable(IMarkdownTable table, TableDecoder decoder)
        {
            var records = from r in table.RowValues
                          select new ErrorDefinition
                          {
                              HttpStatusCode = r.ValueForColumn(table, decoder.ParseRule.ColumnNames["httpStatusCode"]),
                              HttpStatusMessage = r.ValueForColumn(table, decoder.ParseRule.ColumnNames["httpStatusMessage"]),
                              ErrorCode = r.ValueForColumn(table, decoder.ParseRule.ColumnNames["errorCode"]),
                              Description = r.ValueForColumn(table, decoder.ParseRule.ColumnNames["description"])
                          };

            return records;
        }
コード例 #19
0
 private static IEnumerable<EnumerationDefinition> ParseEnumerationTable(IMarkdownTable table, TableDecoder decoder)
 {
     var records = from r in table.RowValues
                   select new EnumerationDefinition
                   {
                       Value = r.ValueForColumn(table, decoder.ParseRule.ColumnNames["value"]),
                       Description = r.ValueForColumn(table, decoder.ParseRule.ColumnNames["description"])
                   };
     return records;
 }
コード例 #20
0
 private static IEnumerable<AuthScopeDefinition> ParseAuthScopeTable(IMarkdownTable table, TableDecoder decoder)
 {
     var records = from r in table.RowValues
                   select new AuthScopeDefinition
                   {
                       Scope = r.ValueForColumn(table, decoder.ParseRule.ColumnNames["scope"]),
                       Title = r.ValueForColumn(table, decoder.ParseRule.ColumnNames["title"]),
                       Description = r.ValueForColumn(table, decoder.ParseRule.ColumnNames["description"]),
                       Required = r.ValueForColumn(table, decoder.ParseRule.ColumnNames["required"]).ToBoolean()
                   };
     return records;
 }
コード例 #21
0
 private static TableBlockType TableShapeMatch(IMarkdownTable table)
 {
     return TableBlockType.Unknown;
 }
コード例 #22
0
 private static IEnumerable<ParameterDefinition> ParseHeadersTable(IMarkdownTable table)
 {
     var records = from r in table.RowValues
                   select new ParameterDefinition
                   {
                       Name = r.ValueForColumn(table, "Name", "Header Name"),
                       Type = JsonDataType.String,
                       Description = r.ValueForColumn(table, "Description"),
                       Location = ParameterLocation.Header
                   };
     return records;
 }
コード例 #23
0
        /// <summary>
        /// Convert a markdown table into ErrorDefinition objects
        /// </summary>
        /// <param name="table"></param>
        /// <returns></returns>
        private static IEnumerable<ErrorDefinition> ParseErrorTable(IMarkdownTable table)
        {
            var records = from r in table.RowValues
                          select new ErrorDefinition
                          {
                              HttpStatusCode = r.ValueForColumn(table, "HTTP Code"),
                              HttpStatusMessage = r.ValueForColumn(table, "HTTP Error Message"),
                              ErrorCode = r.ValueForColumn(table, "Error Code"),
                              Description = r.ValueForColumn(table, "Error Message")
                          };

            return records;
        }
コード例 #24
0
 private static TableBlockType TableShapeMatch(IMarkdownTable table)
 {
     return(TableBlockType.Unknown);
 }
コード例 #25
0
 private static IEnumerable<ParameterDefinition> ParseParameterTable(IMarkdownTable table, ParameterLocation location, TableDecoder decoder, bool navigationProperties = false)
 {
     var records = from r in table.RowValues
                   select 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(),
                       Location = location,
                       IsNavigatable = navigationProperties
                   };
     return records;
 }
コード例 #26
0
 private static IEnumerable<ParameterDefinition> ParseParameterTable(IMarkdownTable table, ParameterLocation location)
 {
     var records = from r in table.RowValues
                   select new ParameterDefinition
                   {
                       Name = r.ValueForColumn(table, "Parameter Name", "Property Name", "Name"),
                       Type = r.ValueForColumn(table, "Type", "Value").ToDataType(),
                       Description = r.ValueForColumn(table, "Description"),
                       Location = location,
                       Required = r.ValueForColumn(table, "Description").IsRequired()
                   };
     return records;
 }
コード例 #27
0
 private static IEnumerable<AuthScopeDefinition> ParseAuthScopeTable(IMarkdownTable table)
 {
     var records = from r in table.RowValues
                   select new AuthScopeDefinition
                   {
                       Scope = r.ValueForColumn(table, "Scope Name"),
                       Title = r.ValueForColumn(table, "Title"),
                       Description = r.ValueForColumn(table, "Description"),
                       Required = r.ValueForColumn(table, "Required").ToBoolean()
                   };
     return records;
 }