Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions test/overlay-previous-overlay/input.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
type: object
properties:
parent:
type: object
properties:
one:
type: object
properties:
child: {}
two:
type: object
properties:
child: {}
three:
type: object
properties:
child: {}
2 changes: 2 additions & 0 deletions test/overlay-previous-overlay/options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
output: output.yaml
overlayFile: overlay.yaml
77 changes: 77 additions & 0 deletions test/overlay-previous-overlay/output.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
type: object
properties:
parent:
type: object
properties:
one:
type: object
properties:
child:
oneOf:
- type: object
properties:
type:
const: a
a:
type: object
oneOf:
- type: object
properties:
type:
const: c
c:
type: object
- type: object
properties:
type:
const: b
b:
type: object
two:
type: object
properties:
child:
oneOf:
- type: object
properties:
type:
const: a
a:
type: object
oneOf:
- type: object
properties:
type:
const: c
c:
type: object
- type: object
properties:
type:
const: b
b:
type: object
three:
type: object
properties:
child:
oneOf:
- type: object
properties:
type:
const: a
a:
type: object
oneOf:
- type: object
properties:
type:
const: c
c:
type: object
- type: object
properties:
type:
const: b
b:
type: object
32 changes: 32 additions & 0 deletions test/overlay-previous-overlay/overlay.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
actions:

# apply an overlay to add an object from this overlay into the original OpenAPI schema
# this should be applied as a copy to each target, not a reference
- target: $..child
update:
oneOf:
- type: object
properties:
type:
const: a
a:
type: object
- type: object
properties:
type:
const: b
b:
type: object

# apply a further overlay to the above overlaid object
# as the above overlaid object should be a copy, we shouldn't keep
# adding the overlay multiple times to the same referenced object
- target: $..child.oneOf[0].properties.a
update:
oneOf:
- type: object
properties:
type:
const: c
c:
type: object
4 changes: 3 additions & 1 deletion utils/overlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ async function openapiOverlay(oaObj, options) {
// Handle update actions
targets.forEach(node => {
if (node.parent && node.key !== undefined) {
node.parent[node.key] = deepMerge(node.value, update);
// make a copy of the update object any further updates aren't applied
// multiple times to the same object
node.parent[node.key] = deepMerge(node.value, structuredClone(update));
}
});
}
Expand Down