-
Notifications
You must be signed in to change notification settings - Fork 29
Explicit definition of how to recursively merge objects #216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
915d5c0
Explicit definition of how to recursively merge objects
ralfhandl 395b397
Apply suggestion from @mikekistler
ralfhandl bbe5205
Merge branch 'main' into 1.1-merge-explained
ralfhandl 57bf2bb
Merge branch 'main' into 1.1-merge-explained
ralfhandl 091ce79
Apply suggestions from code review
baywet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -122,9 +122,17 @@ The result of the `target` JSONPath expression MUST be zero or more objects or a | |
|
|
||
| To update a primitive property value such as a string, the `target` expression should select the _containing_ object in the target document and `update` should contain an object with the property and its new primitive value. | ||
|
|
||
| Primitive-valued items of an array cannot be replaced or removed individually, only the complete array can be replaced. | ||
| Primitive-valued items of an array cannot be replaced or removed individually, only the complete array can be replaced with a `remove` action followed by an `update` or `copy` action. | ||
|
|
||
| The properties of the `update` object MUST be compatible with the target object referenced by the JSONPath key. When the Overlay document is applied, the properties in the `update` object are recursively merged with the properties in the target object with the same names; new properties are added to the target object. | ||
| The properties of the `update` or `copy` object MUST be compatible with the target object referenced by the JSONPath key. When the Overlay document is applied, the `update` object is merged with the target object by recursively applying these steps: | ||
|
|
||
| - A property that only exists in the target object is left unchanged. | ||
| - A property that only exists in the `update` or `copy` object is inserted into the target object. | ||
| - If a property exists in both `update` or `copy` and target object: | ||
| - A primitive value of the `update` or `copy` property replaces a primitive value of the target property. | ||
| - An array value of the `update` or `copy` property is concatenated with an array value of the target property. | ||
| - An object value of the `update` or `copy` property is recursively merged with an object value of the target property. | ||
| - Other property value combinations are incompatible and result in an error. | ||
|
|
||
| This object MAY be extended with [Specification Extensions](#specification-extensions). | ||
|
|
||
|
|
@@ -244,6 +252,21 @@ paths: | |
| responses: | ||
| 200: | ||
| description: OK | ||
| /items/{id}/subitems: | ||
| get: | ||
| x-oai-traits: ['paged'] | ||
| parameters: | ||
| - name: id | ||
| in: path | ||
| required: true | ||
| responses: | ||
| 200: | ||
| description: OK | ||
| /other: | ||
| get: | ||
| responses: | ||
| 200: | ||
| description: OK | ||
| ``` | ||
|
|
||
| With the above OpenAPI document, the following Overlay document will apply the necessary updates to describe how paging is implemented, where that trait has been applied. | ||
|
|
@@ -254,7 +277,7 @@ info: | |
| title: Apply Traits | ||
| version: 1.0.0 | ||
| actions: | ||
| - target: $.paths.*.get[[email protected].paged] | ||
| - target: $.paths.*.get[?(@.x-oai-traits[?(@ == 'paged')])] | ||
| update: | ||
| parameters: | ||
| - name: top | ||
|
|
@@ -265,6 +288,50 @@ actions: | |
| # ... | ||
| ``` | ||
|
|
||
| resulting in | ||
|
|
||
| ```yaml | ||
| openapi: 3.1.0 | ||
| info: | ||
| title: API with a paged collection | ||
| version: 1.0.0 | ||
| paths: | ||
| /items: | ||
| get: | ||
| x-oai-traits: ["paged"] | ||
| responses: | ||
| 200: | ||
| description: OK | ||
| parameters: | ||
| - name: top | ||
| in: query | ||
| # ... | ||
| - name: skip | ||
| in: query | ||
| # ... | ||
| /items/{id}/subitems: | ||
| get: | ||
| x-oai-traits: ["paged"] | ||
| parameters: | ||
| - name: id | ||
| in: path | ||
| required: true | ||
| - name: top | ||
| in: query | ||
| # ... | ||
| - name: skip | ||
| in: query | ||
| # ... | ||
| responses: | ||
| 200: | ||
| description: OK | ||
| /other: | ||
| get: | ||
| responses: | ||
| 200: | ||
| description: OK | ||
| ``` | ||
|
|
||
| This approach allows inversion of control as to where the Overlay updates apply to the target document itself. | ||
|
|
||
| ### Specification Extensions | ||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
leaving a note to check at a later time whether it's fully compliant with RFC 9535 since both JsonPath.net and https://jsonpath.com/ complain about this one.