question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Adding `merge` construct

See original GitHub issue

Propose 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:closed
  • Created 7 years ago
  • Reactions:6
  • Comments:13 (11 by maintainers)

github_iconTop GitHub Comments

2reactions
dolmencommented, Dec 12, 2018

My openapi-preprocessor tool provides a $merge keyword with a strong implementation, but also a $inline keyword.

0reactions
handrewscommented, Feb 24, 2020

I’m going to be daring and go ahead and close this for two reasons:

  1. It’s well-established at this point that with the full adoption of JSON Schema in OAS 3.1, we don’t want to diverge from it by adding $merge into the Schema Object.
  2. Outside of the Schema Object, this is best discussed in the context of the various overlay proposals, which are tracked elsewhere: #1442 #1722 #1843 (#1442 in particular duplicates much of this issue’s discussion).
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found