fix: dedupe properties when allOf override redefines nested array items (#1218)#1457
Merged
Merged
Conversation
…ms (#1218) When an `allOf` branch overrides a nested array's `items` with `oneOf`, the merged schema ends up with both `properties` (from the original items) and `oneOf` (from the override) as siblings. The renderer was emitting both, duplicating the shared properties. Fix mirrors Redoc's `SchemaModel.initOneOf` behavior: when sibling fields appear alongside `oneOf`/`anyOf`, fold them into each branch via allOf-merge so each branch is self-contained, then render only the branches. Applied at three combo-render sites in createSchema.ts: items.allOf merge path, top-level oneOf+properties path, and top-level allOf merge path. Adds a regression unit test and a `/allof-array-items-oneof-override` demo fixture under demo/examples/tests/allOf.yaml for manual verification.
|
Size Change: +7.92 kB (+0.35%) Total Size: 2.29 MB 📦 View Changed
ℹ️ View Unchanged
|
|
Visit the preview URL for this PR (updated for commit 2729748): https://docusaurus-openapi-36b86--pr1457-b2vww6hm.web.app (expires Wed, 13 May 2026 14:40:46 GMT) 🔥 via Firebase Hosting GitHub Action 🌎 Sign: bf293780ee827f578864d92193b8c2866acd459f |
The plugin's compile-time fix only covered the createSchema.ts paths. The runtime theme component (Schema/index.tsx) has the same combo-render pattern at four sites: Items, renderChildren, and two SchemaNode allOf branches. Apply the same foldSiblingsIntoBranches helper consistently.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
allOfbranch overrides a nested array'sitemswithoneOf, shared base properties were rendered twice (once at the array-item level, once inside each oneOf branch).foldSiblingsIntoBranches()increateSchema.tsthat mirrors Redoc'sSchemaModel.initOneOf: when sibling fields appear alongsideoneOf/anyOf, fold them into each branch via allOf-merge so each branch is self-contained, then render only the branches.items.allOfmerge path, top-leveloneOf+propertiespath, and top-levelallOfmerge path.Behavior change
Existing schemas that combine
oneOf/anyOfwith sibling properties (viaallOfor directly) will now render the sibling properties inside each branch tab instead of separately below the tabs. This is the semantically correct interpretation (the constraints apply to every variant) and matches Redoc's output. 9 existing snapshots updated to reflect this — see the__snapshots__diff.Test plan
should not duplicate shared item properties when items.allOf combines base + oneOf (#1218)createSchema.test.tscases passdemo/examples/tests/allOf.yaml→/allof-array-items-oneof-override(GeoJSON-styleFeatureCollectionBase/PointFeature/PolygonFeature/CustomFeatureCollection) generates cleanly viayarn workspace demo gen-api-docs testsyarn startallOf+oneOf+ shared properties (e.g., discriminator examples, allof-multiple-oneof)🤖 Generated with Claude Code