Skip to content

Move YAML to SharpYaml and report unknown keys as errors - #4506

Merged
theletterf merged 2 commits into
mainfrom
feature/move-to-sharpyaml
Oct 20, 2026
Merged

theletterf merged 2 commits into
mainfrom
feature/move-to-sharpyaml

Conversation

@Mpdreamz

@Mpdreamz Mpdreamz commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

YAML parsing moves from YamlDotNet to SharpYaml. A typo in any YAML config now fails the build with a location and a correction, instead of being silently dropped.

Affects: Configuration, Release notes, Authoring

Prompt summary: Replace YamlDotNet with SharpYaml across the configuration, changelog, and Markdown front matter pipelines, and make unmapped YAML keys a build-breaking diagnostic rather than a silent no-op.

Why

YamlDotNet's source generator (Vecc.YamlDotNet.Analyzers.StaticGenerator) requires every serializable type to be listed by hand, and nothing in the pipeline reported an unmapped key back to the author. A typo like path_prefx in navigation.yml deserialized without error, the field it meant to set stayed at its default, and the mistake surfaced later as a confusing navigation bug instead of a build failure at the point of the typo.

What

Unknown keys fail the build with a location and a correction

Every YAML config file — docset.yml, navigation.yml, products.yml, changelog entries, changelog bundles, and Markdown front matter — now reports an unmapped key through YamlUnmappedMemberDiagnostics, with a Levenshtein-distance suggestion when one is close enough, or the full list of valid keys when it is not. For example, a navigation.yml with path_prefx: get-started instead of path_prefix: get-started now fails with:

Unknown key 'path_prefx' in $.toc[0]. Did you mean 'path_prefix'?

A key that is not a near match lists the real options instead of guessing:

Unknown key 'colour_scheme' in $.toc[0]. Valid keys: children, dropdown, external, island, navigation_title, path_prefix, section, toc.

A changelog entry with desciption: instead of description: fails with a line and column, since changelog entries parse from committed files on disk:

changelog/123.yaml: (Lin: 2, Col: 0, Chr: 31) - (Lin: 2, Col: 12, Chr: 43): (3,1) Unknown key 'desciption'. Did you mean 'description'?

The same check runs inside a changelog bundle's nested products: list, with the path to the offending entry included:

bundles/9.3.0.yaml: (Lin: 2, Col: 4, Chr: 41) - (Lin: 2, Col: 11, Chr: 48): (3,5) Unknown key 'taget' in $.products[0]. Did you mean 'target'?

And Markdown front matter catches the same class of mistake, for example navigaton_title: instead of navigation_title::

Unknown key 'navigaton_title'. Did you mean 'navigation_title'?

A small, fixed set of legacy front matter keys (type, comment) stay tolerated as hints rather than errors, via YamlUnknownKeyPolicies.ToleratedAsHint, so older content does not break on a key the author never controlled.

YAML and JSON serialization now share one API surface

SharpYaml's source generator, YamlSerializerContext, mirrors System.Text.Json's JsonSerializerContext closely enough that the two now share types directly. YamlStaticContext sets PropertyNamingPolicy = JsonKnownNamingPolicy.SnakeCaseLower — the same enum System.Text.Json.Serialization defines for JSON — and SharpYaml's UnmappedMemberHandling and PreferredObjectCreationHandling are JsonUnmappedMemberHandling and JsonObjectCreationHandling values, not SharpYaml-specific ones. A converter or naming policy written for one serializer now reads correctly for the other, and a contributor who already knows System.Text.Json's source-generation attributes already knows most of SharpYaml's.

SharpYaml over YamlDotNet

SharpYaml's generator discovers every type reachable from a root [YamlSerializable] registration on its own; YamlDotNet's required every nested type listed explicitly, so adding a field of a new type meant a second edit in the generator config to keep it working. Unmapped-key reporting with suggestions is a feature of the generator itself rather than something this repo had to build against YamlDotNet to begin with. The migration also removes a workaround for a YamlDotNet multi-line string bug — | block literals round-trip correctly under SharpYaml — and a manual trailing-newline fix-up that the old writer needed and the new one does not.

Trailing fixes from the migration

A handful of config DTOs stayed internal after the pass that made their siblings public to satisfy SharpYaml's generator, which requires public types for public serialization members; BundleBackportsYaml is now public like the rest of Elastic.Documentation.Configuration.Changelog. Three files in Elastic.Changelog still referenced YamlDotNet.Core for YamlException after the swap. Two changelog tests asserted on hardcoded YAML indentation that changed because SharpYaml's writer indents a sequence under its parent mapping key, where YamlDotNet's default was indentless; the assertions now match the new, equally valid, output. A third changelog test normalizes its fixture's line endings, since SharpYaml only picks the block-literal style for a description free of \r, and a Windows checkout of the raw string literal otherwise broke the assertion. elastic/curator's ex_reindex.md has a navigation_tite typo that YamlDotNet silently ignored; it now reports as a hint instead of an error for that one file and points at the fix, elastic/curator#1798, and still errors everywhere else.

Verify

./build.sh unit-test
# Elastic.Documentation.Configuration.Tests/UnknownYamlKeyTests.cs — docset.yml, navigation.yml, products.yml typo cases
# Elastic.Changelog.Tests/Serialization/UnknownKeyTests.cs — changelog entry and bundle typo cases
# Elastic.Markdown.Tests/FrontMatter/YamlFrontMatterTests.cs — front matter typo, legacy-key, and curator-typo-override cases

Note: A docset.yml, navigation.yml, products.yml, changelog entry, changelog bundle, or Markdown front matter file with a key that was previously silently ignored now fails the build instead of swallowing the typo. Fix the typo, or add the key to its DTO if it is meant to be read. elastic/curator#1798 is the first content fix this surfaced.

@Mpdreamz
Mpdreamz requested a review from a team as a code owner October 19, 2026 10:57
@Mpdreamz
Mpdreamz requested a review from akira28 October 19, 2026 10:57
@github-actions

Copy link
Copy Markdown
Contributor

@Mpdreamz
Mpdreamz force-pushed the feature/move-to-sharpyaml branch from 472a4d8 to 5ffe9e8 Compare October 20, 2026 10:27
@Mpdreamz Mpdreamz added feature and removed breaking labels Oct 20, 2026
Replace YamlDotNet and its static generator with SharpYaml 3.16.0, which supports source-generated, AOT-safe deserialization and reports unmapped members with a path, position and suggestion.

Unknown keys are now errors with a message such as `Unknown key 'fiel' in $.toc[1]. Did you mean 'file'?`, reported at the key's file line. Config files without a collector throw one exception listing every unknown key. Hand-written converters report through the same path, so a mistyped toc entry is no longer dropped silently. A per-key policy hook tolerates keys that content repositories still use (`platforms`, `warning`, `tip`, `important`, `type`, `comment`) as hints, tracked in [elastic/docs-eng-team#1075](elastic/docs-eng-team#1075) and [elastic/docs-eng-team#1076](elastic/docs-eng-team#1076). `meta_title` is now a first-class `YamlFrontMatter` field rather than a tolerated key.

SharpYaml 3.16.0 also lets changelog fields serialize as `|` block literals again and removes the trailing-newline workaround. `OpenApiReader` now reads the scalar value of quoted path keys, which the migration had broken for specs such as `cloud-billing.yaml`.

`BundleBackportsYaml` stayed `internal` while its sibling DTOs went `public` for the generator, so the generated public `YamlTypeInfo<BundleBackportsYaml>` accessor tripped `CS0053`; it is `public` now like the rest. Three `Elastic.Changelog` files still had `using YamlDotNet.Core;` for `YamlException`; they now use `SharpYaml`. A changelog bundling test and a frontmatter test asserted the old writer's indentation and an outdated tolerated-key list; both now match SharpYaml's actual output.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Co-Authored-By: Claude Sonnet 5 <[email protected]>
Co-authored-by: Cursor <[email protected]>
@Mpdreamz
Mpdreamz force-pushed the feature/move-to-sharpyaml branch from 33d9d4b to 5008fe2 Compare October 20, 2026 11:12
…ont matter

The hub-whats-new.yml cache was keyed by path only, so after a typo the
cached error replayed on every watch-mode build until a restart. Key the
cached parse by the file content as well.

Comment-only front matter deserializes to null, and ProcessYamlFrontMatter
dereferenced it. Read it as empty front matter.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01TjZFCvQhL3DdrcjFKU6jDT
@theletterf
theletterf merged commit 923ce19 into main Oct 20, 2026
32 checks passed
@theletterf
theletterf deleted the feature/move-to-sharpyaml branch October 20, 2026 12:14
reakaleek added a commit that referenced this pull request Oct 22, 2026
…move

#4506 replaced YamlDotNet with SharpYaml, so `YamlMember` no longer resolves in `PublishEnvironment`. The merged CI build failed to compile on every OS.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
reakaleek added a commit that referenced this pull request Oct 22, 2026
* Send page feedback through the AWS WAF SDK when an environment sets its URL

The web ACL can require an `aws-waf-token` cookie on `/docs/_api/v1/page-feedback`. A plain `fetch()` cannot solve the challenge. `waf_integration_url` in `config/assembler.yml` now flows into `window.__DOCS_CONFIG__`, and `<page-feedback>` loads that SDK and sends the `PUT` through `AwsWafIntegration.fetch`. With no URL, nothing loads and the call uses plain `fetch()`. If the SDK fails to load, the submit shows the normal error state.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

* Use `YamlPropertyName` for `waf_integration_url` after the SharpYaml move

#4506 replaced YamlDotNet with SharpYaml, so `YamlMember` no longer resolves in `PublishEnvironment`. The merged CI build failed to compile on every OS.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

---------

Co-authored-by: Jan Calanog <[email protected]>
Co-authored-by: Claude Sonnet 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants