Adding `merge` construct
See original GitHub issuePropose that we introduce a construct from JSON Schema draft-5, but not exactly per the draft-5 proposal.
Background
The allOf
construct requires that all members be proper JSON Schemas. For JSON-Schema draft-5,
a $merge
operator was proposed. The behavioral differences between the two include:
- merge members do not need to be valid schemas
- the
$merge
operator allows for subtraction of values - the
$merge
operator has operational order, which allows for a defined behavior when keys clash and have different values - the
$merge
operator is pre-processed, constructing a (valid) schema before validation is actually performed
The JSON schema draft has a different syntax than proposed. Why? It’s too verbose, and supports a source
and with
syntax (i.e. merge two objects). We need to merge multiple objects, and the source
, with
is more wordy than we need.
Examples
Similar to allOf
, but with partial schemas:
definitions:
Dog:
$merge:
- $ref: '#/definitions/Animal'
- description: a dog
Animal:
type: object
properties:
numberOfFeet:
type: integer
format: int32
result:
definitions:
Dog:
properties:
numberOfFeet:
type: integer
format: int32
description: a dog
In addition, since we can use $merge
without full schemas, I propose a fragments
section where non-validated schemas can be used.
parameters:
- $merge:
- $ref: '#/fragments/skip'
- in: query
description: the total records to skip
minimum: null
fragments:
skip:
# this is a partial schema! It's not a proper parameter
name: skip
type: integer
format: int32
minimum: 0
The effective result:
parameters:
- in: query
description: the total records to skip
name: skip
type: integer
format: int32
# note the minimum is removed by the `null`!!!
Modeling a common pattern
components:
definitions:
PaginatedResult:
type: object
properties:
totalRecords:
type: integer
format: int32
cursorId:
type: string
UserPaginatedResult:
$merge:
- $ref: '#/components/definitions/PaginatedResult'
- properties:
data:
type: array
items:
$ref: '#/components/definitions/User'
User:
properties:
name:
type: string
Effective result:
components:
definitions:
UserPaginatedResult:
type: object
properties:
totalRecords:
type: integer
format: int32
cursorId:
type: string
# note `data` is merged, not replacing `properties`!!!
data:
type: array
items:
$ref: '#/components/definitions/User'
Issue Analytics
- State:
- Created 7 years ago
- Reactions:6
- Comments:13 (11 by maintainers)
Top Results From Across the Web
How to merge 2 projects (Tutorial from SQUALE). - Construct 3
Copy the 2 projects content (Be careful to only copy the different effects! Only one of each type.) <object-folder>. Add all different objects ......
Read more >Insert mail merge fields - Microsoft Support
Add individual merge fields · Click or tap where you want the merge field. · Choose the down-arrow under Insert Merge Field, and...
Read more >Preparing a Document with Merge Fields - Laserfiche Cloud
Adding Table Merge Fields ... When you create a field merge table in Word, you need to define the region in a table...
Read more >Merge features into one feature—ArcGIS Pro | Documentation
On the Edit tab, in the Features group, click Modify · Expand Construct and click Merge · Click the New Feature tab. ·...
Read more >How do I create a merge field in Microsoft Word?
... a merge field may need to be created to map Raiser's Edge fields to the document when editing an existing letter or...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
My openapi-preprocessor tool provides a
$merge
keyword with a strong implementation, but also a$inline
keyword.I’m going to be daring and go ahead and close this for two reasons:
$merge
into the Schema Object.