Skip to content

Commit 9fcfc4b

Browse files
darrelmillerMikeRalphson
authored andcommitted
Updated Overlay proposal (OAI#2300)
* Updated Overlay proposal * fixed examples * Update proposals/004_Overlays.md Co-authored-by: Mike Ralphson <[email protected]> Co-authored-by: Mike Ralphson <[email protected]>
1 parent 1bef4ca commit 9fcfc4b

File tree

3 files changed

+94
-13
lines changed

3 files changed

+94
-13
lines changed

proposals/004_Overlays.md

+14-13
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
|---- | ---------------- | ---------- |
1616
| 24th December 2019 | Darrel Miller | Initial draft |
1717
| 2nd January 2019 | Darrel Miller | Update to wording around removing items from arrays. Added section on backward compatibility. Clarified process around applying a set of updates. Started to add supported scenarios.|
18+
| 29th July 2020 | Darrel Miller | Updated to be explicit about update operations |
1819

1920
## Introduction
2021

2122
In recent months we have been discussing various use cases for overlays and various solutions. The following proposal takes a somewhat more radical approach to the problem. It is a more ambitious proposal than the others we have seen before but the additional complexity does allow for supporting many of the scenarios that have been discussed to date.
2223

23-
2424
#### <a name="overlayDocument"></a>Overlay Document
2525

2626
An overlay document contains a list of [Update Objects](#overlayUpdates) that are to be applied to the target document. Each [Update Object](#updateObject) has a `target` property and a `value` property. The `target` property is a [JMESPath](http://jmespath.org/specification.html) query that identifies what part of the target document is to be updated and the `value` property contains an object with the properties to be overlaid.
@@ -63,10 +63,11 @@ This object represents one or more changes to be applied to the target document
6363
Field Name | Type | Description
6464
---|:---:|---
6565
<a name="updateTarget"></a>target | `string` | A JMESPath expression referencing the target objects in the target document.
66-
<a name="updateValue"></a>value | [Any](#valueObject) | An object with the properties and values to be updated in the target document. Property has no impact if `remove` property is `true`.
66+
<a name="updateAdd"></a>add | [Any](#addObject) | An object to be added as a child of the object(s) referenced by the target. Property has no impact if `remove` property is `true`.
67+
<a name="updateMerge"></a>merge | [Any](#mergeObject) | An object with the properties and values to be merged with the object(s) referenced by the target. Property has no impact if `remove` property is `true`.
6768
<a name="updateRemove"></a>remove | `boolean` | A boolean value that indicates that the target object is to be removed from the the map or array it is contained in. The default value is false.
6869

69-
The properties of the `Value Object` MUST be compatible with the target object referenced by the JMESPath key. When the Overlay document is applied, the properties in the `Value Object` replace properties in the target object with the same name and new properties are appended to the target object.
70+
The properties of the merge object MUST be compatible with the target object referenced by the JMESPath key. When the Overlay document is applied, the properties in the merge object replace properties in the target object with the same name and new properties are appended to the target object.
7071

7172
##### Structured Overlays Example
7273

@@ -79,7 +80,7 @@ info:
7980
version: 1.0.0
8081
updates:
8182
- target: "@"
82-
value:
83+
merge:
8384
info:
8485
x-overlay-applied: structured-overlay
8586
paths:
@@ -103,17 +104,17 @@ Alternatively, where only a small number of updates need to be applied to a larg
103104
```yaml
104105
overlay: 1.0.0
105106
info:
106-
title: Structured Overlay
107+
title: Targeted Overlays
107108
version: 1.0.0
108109
updates:
109110
- target: paths."/foo".get
110-
value:
111+
merge:
111112
description: This is the new description
112113
- target: paths."/bar".get
113-
value:
114+
merge:
114115
description: This is the updated description
115116
- target: paths."/bar"
116-
value:
117+
merge:
117118
post:
118119
description: This is an updated description of a child object
119120
x-safe: false
@@ -130,10 +131,10 @@ info:
130131
version: 1.0.0
131132
updates:
132133
- target: paths.*.get
133-
value:
134+
merge:
134135
x-safe: true
135136
- target: paths.*.get.parameters[?name=='filter' && in=='query']
136-
value:
137+
merge:
137138
schema:
138139
$ref: "/components/schemas/filterSchema"
139140
```
@@ -148,8 +149,8 @@ info:
148149
title: Add an array element
149150
version: 1.0.0
150151
updates:
151-
- target: paths.*.get.parameters[length(@)]
152-
value:
152+
- target: paths.*.get.parameters
153+
add:
153154
name: newParam
154155
in: query
155156
```
@@ -160,7 +161,7 @@ info:
160161
title: Remove a array element
161162
version: 1.0.0
162163
updates:
163-
- target: $.paths[*].get.parameters[? name == 'dummy']
164+
- target: paths[*].get.parameters[? name == 'dummy']
164165
remove: true
165166
```
166167

proposals/Overlays/Changes.yml

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Create update methods (add,replace,merge,delete)? Is merge necessary?
2+
# Multiple additions or updates to the same target is more efficient with merge
3+
4+
# Different than JSON Patch because is works in JSON and YAML
5+
# Has info object and spec version
6+
# values
7+
8+
overlay: 1.0.0
9+
info:
10+
title: An example of an overlay that captures changes to an API
11+
version: 1.0.0
12+
updates:
13+
# Add a property to a schema
14+
- target: components.schemas."todo".properties
15+
merge:
16+
createdBy:
17+
type: string
18+
# Add constraints to a schema
19+
- target: components.schemas."todo"
20+
merge:
21+
additionalProperties: false
22+
- target: components.schemas."todo"
23+
merge:
24+
type: ["object","null"]
25+
#Change a schema
26+
- target: components.schemas."todo"
27+
replace:
28+
type: integer
29+
# Add multiple constraints to a schema using merge
30+
- target: components.schemas."todo"
31+
merge:
32+
additionalProperties: false
33+
type: ["object","null"]
34+
# Add multiple constraints to a schema using merge
35+
- target: components.schemas."todo"
36+
merge:
37+
additionalProperties: false
38+
type: ["object","null"]
39+
properties:
40+
someprop:
41+
type: string
42+
# Add an operation
43+
- target: paths."/foo"
44+
add:
45+
delete:
46+
description: delete a foo
47+
responses:
48+
200:
49+
description: ok
50+
# Add a path
51+
- target: paths
52+
add:
53+
"/items":
54+
get:
55+
responses:
56+
200:
57+
description: ok
58+
# Add an optional query parameter
59+
- target: paths."/bar".parameters
60+
add:
61+
name: skip
62+
in: query
63+
type: string
64+
# Mark an operation as deprecated
65+
66+
# Change the value of a JSON schema constraint
67+
# Update the version of the API
68+
# Change the license of an API
69+
# Add support for a new request media type
70+
# Add support for a new response media type

proposals/Overlays/MergePatch.yml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
overlay: 1.0.0
2+
info:
3+
title: An example of an overlay that performs a Merge Patch
4+
version: 1.0.0
5+
updates:
6+
- target: "@"
7+
merge:
8+
openapi: 3.0.3
9+
paths: {}
10+

0 commit comments

Comments
 (0)