Skip to content

Fix JsonSchemaFlattenAttribute duplicate fields with multiple inheritance levels#1899

Open
lahma wants to merge 1 commit intoRicoSuter:masterfrom
lahma:fix/1870-flatten-duplicate-fields
Open

Fix JsonSchemaFlattenAttribute duplicate fields with multiple inheritance levels#1899
lahma wants to merge 1 commit intoRicoSuter:masterfrom
lahma:fix/1870-flatten-duplicate-fields

Conversation

@lahma
Copy link
Copy Markdown
Collaborator

@lahma lahma commented Mar 7, 2026

Summary

  • When using [JsonSchemaFlatten] on a class with multiple levels of inheritance (e.g., Test : Test2 : Test1), properties from intermediate ancestors were duplicated — appearing both in the flattened schema's properties and in an allOf section
  • Root cause: the recursive GenerateInheritance call checked each ancestor type's own flatten setting, so unflatten ancestors created allOf entries despite the top-level type being flattened
  • Added FlattenAncestorProperties method that recursively walks the entire inheritance chain and flattens all properties into the target schema without creating allOf entries

Test plan

  • 2 new tests in FlattenInheritanceHierarchyTests.cs:
    • [JsonSchemaFlatten] attribute with 3-level inheritance → no duplicates, no allOf, all properties present
    • FlattenInheritanceHierarchy setting with 3-level inheritance → same behavior
  • All 6 existing flatten tests still pass
  • All 450 tests pass with no regressions

Fixes #1870

🤖 Generated with Claude Code

…ance

When using [JsonSchemaFlatten] on a class with multiple levels of
inheritance (e.g., A : B : C), properties from intermediate ancestors
were duplicated - appearing both in the flattened schema's properties
and in an allOf section. This happened because the recursive
GenerateInheritance call used the ancestor's own flatten setting instead
of continuing to flatten.

Added FlattenAncestorProperties method that recursively flattens all
ancestor properties without creating allOf entries.

Fixes RicoSuter#1870

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

JsonSchemaFlattenAttribute generates duplicate fields when multiple inheritance levels

1 participant