-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathYamlSerialization.cs
More file actions
42 lines (36 loc) · 1.52 KB
/
YamlSerialization.cs
File metadata and controls
42 lines (36 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information
using Elastic.Documentation.AppliesTo;
using Elastic.Documentation.Configuration.Products;
using Elastic.Markdown.Myst.Directives.Contributors;
using Elastic.Markdown.Myst.Directives.Settings;
using Elastic.Markdown.Myst.FrontMatter;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.NamingConventions;
namespace Elastic.Markdown.Myst;
public static class YamlSerialization
{
public static T Deserialize<T>(string yaml, ProductsConfiguration products)
{
var input = new StringReader(yaml);
var deserializer = new StaticDeserializerBuilder(new DocsBuilderYamlStaticContext())
.IgnoreUnmatchedProperties()
.WithEnumNamingConvention(HyphenatedNamingConvention.Instance)
.WithTypeConverter(new SemVersionConverter())
.WithTypeConverter(new ProductConverter(products))
.WithTypeConverter(new ApplicableToYamlConverter(products.PublicReferenceProducts.Keys))
.Build();
var frontMatter = deserializer.Deserialize<T>(input);
return frontMatter;
}
}
[YamlStaticContext]
[YamlSerializable(typeof(YamlSettings))]
[YamlSerializable(typeof(SettingsGrouping))]
[YamlSerializable(typeof(Setting))]
[YamlSerializable(typeof(AllowedValue))]
[YamlSerializable(typeof(SettingMutability))]
[YamlSerializable(typeof(ApplicableTo))]
[YamlSerializable(typeof(ContributorEntry))]
public partial class DocsBuilderYamlStaticContext;