From 9de11753a982359180041128d8ca6c04b3db0dd7 Mon Sep 17 00:00:00 2001 From: Fabrizio Ferri Benedetti Date: Mon, 12 May 2025 10:40:59 +0200 Subject: [PATCH 1/5] Return null if applies to is empty and emit warning --- .../Myst/FrontMatter/ApplicableTo.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Elastic.Markdown/Myst/FrontMatter/ApplicableTo.cs b/src/Elastic.Markdown/Myst/FrontMatter/ApplicableTo.cs index a085ce6b3..c2e00fdd9 100644 --- a/src/Elastic.Markdown/Myst/FrontMatter/ApplicableTo.cs +++ b/src/Elastic.Markdown/Myst/FrontMatter/ApplicableTo.cs @@ -122,10 +122,17 @@ public class ApplicableToConverter : IYamlTypeConverter public object? ReadYaml(IParser parser, Type type, ObjectDeserializer rootDeserializer) { + var warnings = new List(); + var applicableTo = new ApplicableTo(); + if (parser.TryConsume(out var value)) { if (string.IsNullOrWhiteSpace(value.Value)) - return ApplicableTo.All; + { + warnings.Add("The 'applies_to' field is present but empty. No applicability will be assumed."); + return null; + } + if (string.Equals(value.Value, "all", StringComparison.InvariantCultureIgnoreCase)) return ApplicableTo.All; } @@ -134,10 +141,6 @@ public class ApplicableToConverter : IYamlTypeConverter if (deserialized is not Dictionary { Count: > 0 } dictionary) return null; - - var applicableTo = new ApplicableTo(); - var warnings = new List(); - var keys = dictionary.Keys.OfType().ToArray(); var oldStyleKeys = keys.Where(k => k.StartsWith(':')).ToList(); if (oldStyleKeys.Count > 0) From f282917eea67260ea3fbbc125072cdbd3a19d520 Mon Sep 17 00:00:00 2001 From: Fabrizio Ferri Benedetti Date: Mon, 12 May 2025 10:43:42 +0200 Subject: [PATCH 2/5] Update docs --- docs/syntax/applies.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/syntax/applies.md b/docs/syntax/applies.md index fafffc829..5ca89b4bb 100644 --- a/docs/syntax/applies.md +++ b/docs/syntax/applies.md @@ -47,14 +47,14 @@ discontinued 9.2.0 all ``` -`all` and empty string mean generally available for all active versions +`all` means generally available for all active versions ```yaml applies_to: serverless: all ``` -`all` and empty string can also be specified at a version level +`all` can also be specified at a version level ```yaml applies_to: @@ -62,7 +62,7 @@ applies_to: serverless: beta ``` -Both are equivalent, note `all` just means we won't be rendering the version portion in the html. +Note `all` just means we won't be rendering the version portion in the HTML. ## Structured model From dcbd4d7b53394f1d0f26448140803c1e11fb9fae Mon Sep 17 00:00:00 2001 From: Fabrizio Ferri Benedetti Date: Mon, 12 May 2025 10:44:23 +0200 Subject: [PATCH 3/5] Add test --- tests/authoring/Applicability/AppliesToFrontMatter.fs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/authoring/Applicability/AppliesToFrontMatter.fs b/tests/authoring/Applicability/AppliesToFrontMatter.fs index 7932d3b14..357e75bfa 100644 --- a/tests/authoring/Applicability/AppliesToFrontMatter.fs +++ b/tests/authoring/Applicability/AppliesToFrontMatter.fs @@ -186,3 +186,11 @@ applies_to: Stack=AppliesCollection.op_Explicit "ga 9.1.0", Product=AppliesCollection.op_Explicit "coming 9.5, discontinued 9.7" )) + +type ``parses empty applies_to as null`` () = + static let markdown = frontMatter """ +applies_to: +""" + [] + let ``does not render label`` () = + markdown |> appliesTo null From b8b5db95bb01b3e4f65351e5414e6f495a353575 Mon Sep 17 00:00:00 2001 From: Fabrizio Ferri Benedetti Date: Tue, 20 May 2025 09:42:25 +0200 Subject: [PATCH 4/5] Fix error --- tests/authoring/Applicability/AppliesToFrontMatter.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/authoring/Applicability/AppliesToFrontMatter.fs b/tests/authoring/Applicability/AppliesToFrontMatter.fs index 357e75bfa..7054e6bab 100644 --- a/tests/authoring/Applicability/AppliesToFrontMatter.fs +++ b/tests/authoring/Applicability/AppliesToFrontMatter.fs @@ -193,4 +193,4 @@ applies_to: """ [] let ``does not render label`` () = - markdown |> appliesTo null + markdown |> appliesTo (Unchecked.defaultof) From 17ca7002cbddf99a931635cc4683e3fd307c9fb8 Mon Sep 17 00:00:00 2001 From: Fabrizio Ferri Benedetti Date: Tue, 20 May 2025 09:49:04 +0200 Subject: [PATCH 5/5] Fix tests --- tests/authoring/Applicability/AppliesToFrontMatter.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/authoring/Applicability/AppliesToFrontMatter.fs b/tests/authoring/Applicability/AppliesToFrontMatter.fs index 7054e6bab..d8292b522 100644 --- a/tests/authoring/Applicability/AppliesToFrontMatter.fs +++ b/tests/authoring/Applicability/AppliesToFrontMatter.fs @@ -23,7 +23,7 @@ applies_to: """ [] let ``apply matches expected`` () = - markdown |> appliesTo ApplicableTo.All + markdown |> appliesTo (Unchecked.defaultof) type ``apply default to top level arguments`` () = static let markdown = frontMatter """