Skip to content

Commit c33fb91

Browse files
authored
fix: dedupe properties when allOf override redefines nested array items (#1218) (#1457)
* fix: dedupe properties when allOf override redefines nested array items (#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. * fix(theme): apply same dedupe fix in runtime Schema component (#1218) 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.
1 parent 5d386e3 commit c33fb91

5 files changed

Lines changed: 645 additions & 256 deletions

File tree

demo/examples/tests/allOf.yaml

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,40 @@ paths:
742742
type: string
743743
example: Resource created successfully
744744

745+
/allof-array-items-oneof-override:
746+
get:
747+
tags:
748+
- allOf
749+
summary: allOf override of nested array items with oneOf
750+
description: |
751+
Regression coverage for [issue #1218](https://github.com/PaloAltoNetworks/docusaurus-openapi-docs/issues/1218).
752+
753+
A schema extends a base via `allOf` and overrides a nested array's `items`
754+
with a `oneOf` of subtypes that each include the base's properties. Prior
755+
to the fix, the shared base properties (`id`, `type`, `geometry`) rendered
756+
twice — once at the array-item level and once inside each oneOf branch.
757+
758+
Schema:
759+
```yaml
760+
type: object
761+
allOf:
762+
- $ref: '#/components/schemas/FeatureCollectionBase'
763+
- type: object
764+
properties:
765+
features:
766+
items:
767+
oneOf:
768+
- $ref: '#/components/schemas/PointFeature'
769+
- $ref: '#/components/schemas/PolygonFeature'
770+
```
771+
responses:
772+
"200":
773+
description: A custom feature collection
774+
content:
775+
application/geo+json:
776+
schema:
777+
$ref: "#/components/schemas/CustomFeatureCollection"
778+
745779
components:
746780
schemas:
747781
# Enum schemas for allOf parameter tests
@@ -818,3 +852,65 @@ components:
818852
type: string
819853
description: The category of the book
820854
example: "Fiction"
855+
856+
# GeoJSON-style schemas for issue #1218: allOf override of nested array items with oneOf
857+
FeatureBase:
858+
type: object
859+
required: [type, geometry]
860+
properties:
861+
id:
862+
type: string
863+
description: Feature identifier
864+
type:
865+
type: string
866+
enum: [Feature]
867+
geometry:
868+
type: object
869+
description: GeoJSON geometry
870+
871+
PointFeature:
872+
allOf:
873+
- $ref: "#/components/schemas/FeatureBase"
874+
- type: object
875+
properties:
876+
properties:
877+
type: object
878+
properties:
879+
label:
880+
type: string
881+
description: Point label
882+
883+
PolygonFeature:
884+
allOf:
885+
- $ref: "#/components/schemas/FeatureBase"
886+
- type: object
887+
properties:
888+
properties:
889+
type: object
890+
properties:
891+
area:
892+
type: number
893+
description: Polygon area
894+
895+
FeatureCollectionBase:
896+
type: object
897+
required: [type, features]
898+
properties:
899+
type:
900+
type: string
901+
enum: [FeatureCollection]
902+
features:
903+
type: array
904+
items:
905+
$ref: "#/components/schemas/FeatureBase"
906+
907+
CustomFeatureCollection:
908+
allOf:
909+
- $ref: "#/components/schemas/FeatureCollectionBase"
910+
- type: object
911+
properties:
912+
features:
913+
items:
914+
oneOf:
915+
- $ref: "#/components/schemas/PointFeature"
916+
- $ref: "#/components/schemas/PolygonFeature"

0 commit comments

Comments
 (0)