Skip to content

Commit c6ab9be

Browse files
committed
Adapt ApplicableTo changes, fix tests
1 parent 36f9936 commit c6ab9be

File tree

4 files changed

+10
-9
lines changed

4 files changed

+10
-9
lines changed

src/Elastic.Markdown/Myst/Directives/AppliesSwitch/AppliesSwitchBlock.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
33
// See the LICENSE file in the project root for more information
44

5-
using System.Linq;
65
using Elastic.Documentation.AppliesTo;
6+
using Elastic.Documentation.Configuration.Products;
77
using Elastic.Markdown.Diagnostics;
88
using Elastic.Markdown.Helpers;
99

@@ -61,17 +61,17 @@ public override void FinalizeAndValidate(ParserContext context)
6161
AppliesSwitchGroupKey = appliesSwitch?.GetGroupKey();
6262

6363
// Auto-generate sync key from applies_to definition if not provided
64-
SyncKey = Prop("sync") ?? GenerateSyncKey(AppliesToDefinition);
64+
SyncKey = Prop("sync") ?? GenerateSyncKey(AppliesToDefinition, Build.ProductsConfiguration);
6565
Selected = PropBool("selected");
6666
}
6767

68-
public static string GenerateSyncKey(string appliesToDefinition)
68+
public static string GenerateSyncKey(string appliesToDefinition, ProductsConfiguration productsConfiguration)
6969
{
7070
// Parse the YAML to get the ApplicableTo object, then use its hash
7171
// This ensures both simple syntax and YAML objects produce consistent sync keys
7272
try
7373
{
74-
var applicableTo = YamlSerialization.Deserialize<ApplicableTo>(appliesToDefinition);
74+
var applicableTo = YamlSerialization.Deserialize<ApplicableTo>(appliesToDefinition, productsConfiguration);
7575
if (applicableTo != null)
7676
{
7777
// Use the object's hash for a consistent, unique identifier

src/Elastic.Markdown/Myst/Directives/DirectiveHtmlRenderer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ private static void WriteAppliesItem(HtmlRenderer renderer, AppliesItemBlock blo
287287
{
288288
try
289289
{
290-
var applicableTo = YamlSerialization.Deserialize<ApplicableTo>(yaml);
290+
var applicableTo = YamlSerialization.Deserialize<ApplicableTo>(yaml, block.Build.ProductsConfiguration);
291291
if (applicableTo.Diagnostics is null)
292292
return applicableTo;
293293
foreach (var (severity, message) in applicableTo.Diagnostics)

src/Elastic.Markdown/Myst/YamlSerialization.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,5 @@ public static T Deserialize<T>(string yaml, ProductsConfiguration products)
3636
[YamlSerializable(typeof(Setting))]
3737
[YamlSerializable(typeof(AllowedValue))]
3838
[YamlSerializable(typeof(SettingMutability))]
39+
[YamlSerializable(typeof(ApplicableTo))]
3940
public partial class DocsBuilderYamlStaticContext;

tests/Elastic.Markdown.Tests/Directives/ApplicabilitySwitchTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@ public void NormalizesSyncKeyOrder()
194194

195195
foreach (var (definition1, definition2) in testCases)
196196
{
197-
var key1 = AppliesItemBlock.GenerateSyncKey(definition1);
198-
var key2 = AppliesItemBlock.GenerateSyncKey(definition2);
197+
var key1 = AppliesItemBlock.GenerateSyncKey(definition1, Block!.Build.ProductsConfiguration);
198+
var key2 = AppliesItemBlock.GenerateSyncKey(definition2, Block!.Build.ProductsConfiguration);
199199
key1.Should().Be(key2, $"Sync keys should be the same for '{definition1}' and '{definition2}'");
200200
}
201201
}
@@ -214,8 +214,8 @@ public void GeneratesConsistentSyncKeysForYamlObjects()
214214

215215
foreach (var (yamlObject, equivalentSyntax) in testCases)
216216
{
217-
var key1 = AppliesItemBlock.GenerateSyncKey(yamlObject);
218-
var key2 = AppliesItemBlock.GenerateSyncKey(equivalentSyntax);
217+
var key1 = AppliesItemBlock.GenerateSyncKey(yamlObject, Block!.Build.ProductsConfiguration);
218+
var key2 = AppliesItemBlock.GenerateSyncKey(equivalentSyntax, Block!.Build.ProductsConfiguration);
219219
key1.Should().Be(key2, $"Sync keys should be the same for YAML object '{yamlObject}' and equivalent syntax '{equivalentSyntax}'");
220220

221221
// Also verify the key has the expected format

0 commit comments

Comments
 (0)