|
8 | 8 | using Elastic.Documentation.Configuration.TableOfContents;
|
9 | 9 | using Elastic.Documentation.Links;
|
10 | 10 | using Elastic.Documentation.Navigation;
|
| 11 | +using YamlDotNet.RepresentationModel; |
11 | 12 |
|
12 | 13 | namespace Elastic.Documentation.Configuration.Builder;
|
13 | 14 |
|
@@ -108,17 +109,33 @@ public ConfigurationFile(IDocumentationContext context)
|
108 | 109 | // read this later
|
109 | 110 | break;
|
110 | 111 | case "products":
|
111 |
| - var productIds = YamlStreamReader.ReadStringArray(entry.Entry); |
112 |
| - foreach (var productId in productIds) |
| 112 | + if (entry.Entry.Value is not YamlSequenceNode sequence) |
113 | 113 | {
|
114 |
| - if (!Builder.Products.AllById.ContainsKey(productId)) |
| 114 | + reader.EmitError("products must be a sequence", entry.Entry.Value); |
| 115 | + break; |
| 116 | + } |
| 117 | + |
| 118 | + foreach (var node in sequence.Children.OfType<YamlMappingNode>()) |
| 119 | + { |
| 120 | + YamlScalarNode? productId = null; |
| 121 | + foreach (var child in node.Children) |
115 | 122 | {
|
116 |
| - var message = |
117 |
| - $"Product \"{productId}\" not found in the product list. {new Suggestion(Builder.Products.All.Select(p => p.Id).ToHashSet(), productId).GetSuggestionQuestion()}"; |
118 |
| - reader.EmitError(message, entry.Entry.Value); |
| 123 | + if (child.Key is YamlScalarNode { Value: "id" } && child.Value is YamlScalarNode scalarNode) |
| 124 | + { |
| 125 | + productId = scalarNode; |
| 126 | + break; |
| 127 | + } |
119 | 128 | }
|
| 129 | + if (productId?.Value is null) |
| 130 | + { |
| 131 | + reader.EmitError("products must contain an id", node); |
| 132 | + break; |
| 133 | + } |
| 134 | + |
| 135 | + if (!Builder.Products.AllById.ContainsKey(productId.Value)) |
| 136 | + reader.EmitError($"Product \"{productId.Value}\" not found in the product list. {new Suggestion(Builder.Products.All.Select(p => p.Id).ToHashSet(), productId.Value).GetSuggestionQuestion()}", node); |
120 | 137 | else
|
121 |
| - _ = Products.Add(productId); |
| 138 | + _ = Products.Add(productId.Value); |
122 | 139 | }
|
123 | 140 | break;
|
124 | 141 | case "features":
|
|
0 commit comments