From f8a77621c742658bc645db1856fb46bff727cbd9 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Mon, 23 Nov 2026 15:00:52 +0100 Subject: [PATCH 1/3] Keep applies-item badges for keys without a value SharpYaml reads `{ self:, ece: ga 4.2 }` as a key named `self:` with the colon kept. The converter then dropped it as unknown, so the tab label lost its Self-managed badge. The converter now strips the colon from keys that have no value, including in nested mappings. Co-Authored-By: Claude Sonnet 5.5 --- .../Converters/ApplicableToYamlConverter.cs | 16 +++++++++- ...lowMappings_KeysWithoutAValue.verified.txt | 31 +++++++++++++++++++ ...dersEveryBadgeInTheTabLabels.verified.html | 22 +++++++++++++ .../ApplicableToYamlSnapshotTests.cs | 13 ++++++++ .../Directives/ApplicabilitySwitchTests.cs | 22 +++++++++++++ 5 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 tests/Elastic.Markdown.Tests/.snapshots/AppliesTo/ApplicableToYamlSnapshotTests/Read_FlowMappings_KeysWithoutAValue.verified.txt create mode 100644 tests/Elastic.Markdown.Tests/.snapshots/Directives/ApplicabilitySwitchEmptyValueKeysTests/RendersEveryBadgeInTheTabLabels.verified.html diff --git a/src/Elastic.Documentation.Configuration/Converters/ApplicableToYamlConverter.cs b/src/Elastic.Documentation.Configuration/Converters/ApplicableToYamlConverter.cs index a572c3ecab..e47295eec9 100644 --- a/src/Elastic.Documentation.Configuration/Converters/ApplicableToYamlConverter.cs +++ b/src/Elastic.Documentation.Configuration/Converters/ApplicableToYamlConverter.cs @@ -140,8 +140,22 @@ private static void MergeAppliesToListScalarLine( dictionary[key] = string.IsNullOrEmpty(val) ? null : val; } - private ApplicableTo FinalizeApplicableTo(Dictionary dictionary, List<(Severity, string)> diagnostics) + // SharpYaml reads `{ self:, ece: ga }` as a key named `self:` (colon kept) when a comma follows the empty + // value. YAML defines it as key `self` with no value, so strip the colon or the key is dropped as unknown. + private static Dictionary NormalizeEmptyValueKeys(Dictionary dictionary) { + var normalized = new Dictionary(dictionary.Comparer); + foreach (var (key, value) in dictionary) + { + var name = value is null && key.Length > 1 && key.EndsWith(':') ? key[..^1] : key; + normalized[name] = value is Dictionary nested ? NormalizeEmptyValueKeys(nested) : value; + } + return normalized; + } + + private ApplicableTo FinalizeApplicableTo(Dictionary rawDictionary, List<(Severity, string)> diagnostics) + { + var dictionary = NormalizeEmptyValueKeys(rawDictionary); var applicableTo = new ApplicableTo(); var keys = dictionary.Keys.Select(x => x.Replace('_', '-')).ToArray(); diff --git a/tests/Elastic.Markdown.Tests/.snapshots/AppliesTo/ApplicableToYamlSnapshotTests/Read_FlowMappings_KeysWithoutAValue.verified.txt b/tests/Elastic.Markdown.Tests/.snapshots/AppliesTo/ApplicableToYamlSnapshotTests/Read_FlowMappings_KeysWithoutAValue.verified.txt new file mode 100644 index 0000000000..5951e2141d --- /dev/null +++ b/tests/Elastic.Markdown.Tests/.snapshots/AppliesTo/ApplicableToYamlSnapshotTests/Read_FlowMappings_KeysWithoutAValue.verified.txt @@ -0,0 +1,31 @@ +yaml: { self:, ece: ga 4.2 } +json: [{"type":"deployment","sub_type":"self","lifecycle":"ga","version":"all"},{"type":"deployment","sub_type":"ece","lifecycle":"ga","version":"4.2\u002B"}] +text: deployment: self=all, ece=ga 4.2+, + +yaml: { ess:, ece: } +json: [{"type":"deployment","sub_type":"ece","lifecycle":"ga","version":"all"},{"type":"deployment","sub_type":"ess","lifecycle":"ga","version":"all"}] +text: deployment: ece=all, ess=all + +yaml: { self:, eck: } +json: [{"type":"deployment","sub_type":"self","lifecycle":"ga","version":"all"},{"type":"deployment","sub_type":"eck","lifecycle":"ga","version":"all"}] +text: deployment: self=all, eck=all + +yaml: { eck:, self: } +json: [{"type":"deployment","sub_type":"self","lifecycle":"ga","version":"all"},{"type":"deployment","sub_type":"eck","lifecycle":"ga","version":"all"}] +text: deployment: self=all, eck=all + +yaml: { self:, ece:, eck: } +json: [{"type":"deployment","sub_type":"self","lifecycle":"ga","version":"all"},{"type":"deployment","sub_type":"ece","lifecycle":"ga","version":"all"},{"type":"deployment","sub_type":"eck","lifecycle":"ga","version":"all"}] +text: deployment: self=all, ece=all, eck=all + +yaml: { stack:, serverless: } +json: [{"type":"stack","sub_type":"stack","lifecycle":"ga","version":"all"},{"type":"serverless","sub_type":"elasticsearch","lifecycle":"ga","version":"all"},{"type":"serverless","sub_type":"observability","lifecycle":"ga","version":"all"},{"type":"serverless","sub_type":"security","lifecycle":"ga","version":"all"},{"type":"serverless","sub_type":"vectordb","lifecycle":"ga","version":"all"}] +text: stack: all, serverless: elasticsearch=all, observability=all, security=all, vectordb=all + +yaml: { deployment: { self:, ece: ga 4.2 } } +json: [{"type":"deployment","sub_type":"self","lifecycle":"ga","version":"all"},{"type":"deployment","sub_type":"ece","lifecycle":"ga","version":"4.2\u002B"}] +text: deployment: self=all, ece=ga 4.2+, + +yaml: { serverless: { elasticsearch:, security: ga } } +json: [{"type":"serverless","sub_type":"elasticsearch","lifecycle":"ga","version":"all"},{"type":"serverless","sub_type":"security","lifecycle":"ga"}] +text: serverless: elasticsearch=all, security=ga, diff --git a/tests/Elastic.Markdown.Tests/.snapshots/Directives/ApplicabilitySwitchEmptyValueKeysTests/RendersEveryBadgeInTheTabLabels.verified.html b/tests/Elastic.Markdown.Tests/.snapshots/Directives/ApplicabilitySwitchEmptyValueKeysTests/RendersEveryBadgeInTheTabLabels.verified.html new file mode 100644 index 0000000000..9a6f243894 --- /dev/null +++ b/tests/Elastic.Markdown.Tests/.snapshots/Directives/ApplicabilitySwitchEmptyValueKeysTests/RendersEveryBadgeInTheTabLabels.verified.html @@ -0,0 +1,22 @@ +
+ + +
+

Content A

+
+ + +
+

Content B

+
+
diff --git a/tests/Elastic.Markdown.Tests/AppliesTo/ApplicableToYamlSnapshotTests.cs b/tests/Elastic.Markdown.Tests/AppliesTo/ApplicableToYamlSnapshotTests.cs index 7c7d85dd80..82ca22945a 100644 --- a/tests/Elastic.Markdown.Tests/AppliesTo/ApplicableToYamlSnapshotTests.cs +++ b/tests/Elastic.Markdown.Tests/AppliesTo/ApplicableToYamlSnapshotTests.cs @@ -305,6 +305,19 @@ public void Read_Sequences_MergeMappingsAndKeyValueLines() => "- 'deployment: ga'\n- 'deployment: beta'" ]).Should().MatchSnapshot(); + [Test] + public void Read_FlowMappings_KeysWithoutAValue() => + Table([ + "{ self:, ece: ga 4.2 }", + "{ ess:, ece: }", + "{ self:, eck: }", + "{ eck:, self: }", + "{ self:, ece:, eck: }", + "{ stack:, serverless: }", + "{ deployment: { self:, ece: ga 4.2 } }", + "{ serverless: { elasticsearch:, security: ga } }" + ]).Should().MatchSnapshot(); + [Test] public void Read_Stack_ValueShapes() => Table([ diff --git a/tests/Elastic.Markdown.Tests/Directives/ApplicabilitySwitchTests.cs b/tests/Elastic.Markdown.Tests/Directives/ApplicabilitySwitchTests.cs index b886a5f642..9da47dcfb6 100644 --- a/tests/Elastic.Markdown.Tests/Directives/ApplicabilitySwitchTests.cs +++ b/tests/Elastic.Markdown.Tests/Directives/ApplicabilitySwitchTests.cs @@ -104,6 +104,28 @@ public void ItemIndicesAreZeroBased() public void RendersHtml() => Html.Should().MatchHtmlSnapshot(DocsHtml.Body()); } +// Reproduces elastic/docs-builder#5007: a key with no value followed by a comma lost its badge in the tab label. +[InheritsTests] +public class ApplicabilitySwitchEmptyValueKeysTests() : DirectiveTest( + """ +:::::{applies-switch} + +::::{applies-item} { self:, ece: ga 4.2 } +Content A +:::: + +::::{applies-item} { ess:, ece: } +Content B +:::: + +::::: +""" +) +{ + [Test] + public void RendersEveryBadgeInTheTabLabels() => Html.Should().MatchHtmlSnapshot(DocsHtml.Body()); +} + [InheritsTests] public class MultipleApplicabilitySwitchTests() : DirectiveTest( """ From 49960973a1fd4e4c68d5250158e84baa1fd65b5a Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Mon, 23 Nov 2026 15:10:02 +0100 Subject: [PATCH 2/3] Remove the converter workaround for empty-value keys SharpYaml fixes the flow-mapping scanner upstream in commit 1e41a26, which no release contains yet. The tests stay and fail until the next SharpYaml release is pinned. Co-Authored-By: Claude Fable 5.2 --- .../Converters/ApplicableToYamlConverter.cs | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/src/Elastic.Documentation.Configuration/Converters/ApplicableToYamlConverter.cs b/src/Elastic.Documentation.Configuration/Converters/ApplicableToYamlConverter.cs index e47295eec9..a572c3ecab 100644 --- a/src/Elastic.Documentation.Configuration/Converters/ApplicableToYamlConverter.cs +++ b/src/Elastic.Documentation.Configuration/Converters/ApplicableToYamlConverter.cs @@ -140,22 +140,8 @@ private static void MergeAppliesToListScalarLine( dictionary[key] = string.IsNullOrEmpty(val) ? null : val; } - // SharpYaml reads `{ self:, ece: ga }` as a key named `self:` (colon kept) when a comma follows the empty - // value. YAML defines it as key `self` with no value, so strip the colon or the key is dropped as unknown. - private static Dictionary NormalizeEmptyValueKeys(Dictionary dictionary) + private ApplicableTo FinalizeApplicableTo(Dictionary dictionary, List<(Severity, string)> diagnostics) { - var normalized = new Dictionary(dictionary.Comparer); - foreach (var (key, value) in dictionary) - { - var name = value is null && key.Length > 1 && key.EndsWith(':') ? key[..^1] : key; - normalized[name] = value is Dictionary nested ? NormalizeEmptyValueKeys(nested) : value; - } - return normalized; - } - - private ApplicableTo FinalizeApplicableTo(Dictionary rawDictionary, List<(Severity, string)> diagnostics) - { - var dictionary = NormalizeEmptyValueKeys(rawDictionary); var applicableTo = new ApplicableTo(); var keys = dictionary.Keys.Select(x => x.Replace('_', '-')).ToArray(); From f41c60ac24922001ac461ce9ac41e9a0f279af86 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Mon, 23 Nov 2026 15:37:29 +0100 Subject: [PATCH 3/3] Restore the empty-value key workaround as a temporary fix The SharpYaml release that fixes the flow-mapping scanner has no date yet. The converter strips the colon again until then, and a TODO links the follow-up that removes it. Co-Authored-By: Claude Fable 5.2 --- .../Converters/ApplicableToYamlConverter.cs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Elastic.Documentation.Configuration/Converters/ApplicableToYamlConverter.cs b/src/Elastic.Documentation.Configuration/Converters/ApplicableToYamlConverter.cs index a572c3ecab..37159c460a 100644 --- a/src/Elastic.Documentation.Configuration/Converters/ApplicableToYamlConverter.cs +++ b/src/Elastic.Documentation.Configuration/Converters/ApplicableToYamlConverter.cs @@ -140,8 +140,23 @@ private static void MergeAppliesToListScalarLine( dictionary[key] = string.IsNullOrEmpty(val) ? null : val; } - private ApplicableTo FinalizeApplicableTo(Dictionary dictionary, List<(Severity, string)> diagnostics) + // TODO: remove once SharpYaml ships a release after 3.17.0 (https://github.com/elastic/docs-eng-team/issues/1236). + // SharpYaml 3.17.0 reads `{ self:, ece: ga }` as a key named `self:` (colon kept) when a comma follows the + // empty value. YAML defines it as key `self` with no value, so strip the colon or the key is dropped as unknown. + private static Dictionary NormalizeEmptyValueKeys(Dictionary dictionary) { + var normalized = new Dictionary(dictionary.Comparer); + foreach (var (key, value) in dictionary) + { + var name = value is null && key.Length > 1 && key.EndsWith(':') ? key[..^1] : key; + normalized[name] = value is Dictionary nested ? NormalizeEmptyValueKeys(nested) : value; + } + return normalized; + } + + private ApplicableTo FinalizeApplicableTo(Dictionary rawDictionary, List<(Severity, string)> diagnostics) + { + var dictionary = NormalizeEmptyValueKeys(rawDictionary); var applicableTo = new ApplicableTo(); var keys = dictionary.Keys.Select(x => x.Replace('_', '-')).ToArray();