Skip to content

Replace YamlDotNet with SharpYaml (source-gen + reflection fallback)#7

Merged
phil-scott-78 merged 2 commits into
mainfrom
sharpyaml-migration
May 24, 2026
Merged

Replace YamlDotNet with SharpYaml (source-gen + reflection fallback)#7
phil-scott-78 merged 2 commits into
mainfrom
sharpyaml-migration

Conversation

@phil-scott-78
Copy link
Copy Markdown
Contributor

What

Replaces YamlDotNet 16.3.0 with SharpYaml 3.7.0 across all YAML deserialization: front matter, data files (DataFileLoader), and the _llms.yaml / _redirects.yml sidecar readers. YamlDotNet is removed entirely.

How it's wired

  • Source-gen + reflection backup. Built-in front-matter records (DocFrontMatter, BlogFrontMatter) deserialize through a source-generated YamlSerializerContext (PenningtonYamlContext). The DocSite/BlogSite templates register their own contexts; end users opt in with services.AddPenningtonYamlContext(MyContext.Default). Any type no context covers falls back to reflection.
  • Robust fallback. The reflection path pins an explicit ReflectionYamlTypeInfoResolver.Default, so it works regardless of SharpYaml's IsReflectionEnabledByDefault switch.
  • Dispatch, not combine. A source-gen context rejects foreign options, so PenningtonYamlContextProvider routes each type to the context that knows it (or reflection) rather than chaining contexts into one resolver.
  • Security at the event level. FrontMatterParser enforces the anchor/alias/non-standard-tag policy in a single SharpYaml event pass (replacing SafeYamlParser + BufferedYamlParser, both deleted), and reports unknown keys with line numbers. Strict mode throws from that scan after emitting warnings, so it behaves identically for source-gen and reflection types.

Example

examples/MultipleSourcesExample now registers a custom BlogFrontMatterYamlContext via AddPenningtonYamlContext, exercising the user opt-in path alongside the built-in context and reflection fallback in one host.

Verification

  • dotnet build Pennington.slnx — clean, 0 warnings.
  • dotnet test Pennington.slnx — 801 unit + 131 Roslyn + 40 TreeSitter + 48 integration pass (9 pre-existing skips). Covers diagnostics line numbers, strict-mode throw, and the anchor/.NET-type-tag security tests.
  • dotnet run --project docs/Pennington.Docs -- build — 475 pages, exit 0.
  • dotnet run --project examples/MultipleSourcesExample -- build — blog pages render their BlogFrontMatter-sourced titles through the registered context.

Note for AOT

The reflection fallback (data files, sidecar POCOs) is the default for non-AOT builds. Under PublishAot, those would need <SharpYamlIsReflectionEnabledByDefault>true</...> or the types registered in a context; the front-matter types are already AOT-safe via source-gen.

Swap YamlDotNet 16.3.0 for SharpYaml 3.7.0 across front matter, data files,
and the llms/redirect sidecar readers.

Built-in front-matter records deserialize through a source-generated
YamlSerializerContext (PenningtonYamlContext); the DocSite/BlogSite templates
ship their own contexts; users opt in via AddPenningtonYamlContext. Any type no
context covers falls back to reflection through an explicit
ReflectionYamlTypeInfoResolver, so the fallback works regardless of SharpYaml's
IsReflectionEnabledByDefault switch.

FrontMatterParser enforces the anchor/alias/tag security policy with a single
SharpYaml event pass (replacing SafeYamlParser/BufferedYamlParser) and reports
unknown keys with line numbers. Strict mode throws from that scan after emitting
warnings, so it works uniformly for source-gen and reflection types.
MultipleSourcesExample registers BlogFrontMatterYamlContext via
AddPenningtonYamlContext, exercising the user opt-in source-gen path alongside
the built-in context (DocFrontMatter) and reflection fallback in one host.
@phil-scott-78 phil-scott-78 merged commit 5f7fb2c into main May 24, 2026
5 checks passed
@phil-scott-78 phil-scott-78 deleted the sharpyaml-migration branch May 24, 2026 23:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant