Skip to content
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

Proposal: Multiple $ref within single object using Object.assign() #158

Closed
erikfox opened this issue Nov 22, 2016 · 6 comments
Closed

Proposal: Multiple $ref within single object using Object.assign() #158

erikfox opened this issue Nov 22, 2016 · 6 comments

Comments

@erikfox
Copy link

erikfox commented Nov 22, 2016

It would be very useful to be able to merge references within an object:

// JSON
{
  combinedObj: {
    $ref: [ 
      '#first/reference', 
      '#second/reference' 
    ]
  }
}
# YAML
combinedObj:
  $ref:
    - '#first/reference'
    - '#second/reference'

This would use Object.assign(), which also provides a convention in the case of objects with the same properties:

Merging objects with same properties

var o1 = { a: 1, b: 1, c: 1 };
var o2 = { b: 2, c: 2 };
var o3 = { c: 3 };

var obj = Object.assign({}, o1, o2, o3);
console.log(obj); // { a: 1, b: 2, c: 3 }

The properties are overwritten by other objects that have the same properties later in the parameters order.

@danitome24
Copy link

I'm interested too!

@handrews
Copy link
Contributor

See #151 and #119 for combinations when additionalProperties: false, #98 (for a limited form of merging with annotation keywords) and #15 (arbitrary merging/patching, which has a lot of opposition and so is unlikely to be accepted).

@handrews
Copy link
Contributor

BTW, JSON is not JavaScript, and JSON Schema implementations are written in many languages, so JSON Schema features should not be described in terms of JavaScript/ECMAScript features like Object.assign(). Media types for patching (as referenced in #15 and #98) are a more appropriate reference point.

@epoberezkin
Copy link
Member

@handrews I think the consensus is moving towards keeping merging functionality outside of the spec? In any case I'd close it as essentially a duplicate of other similar ideas...

@handrews
Copy link
Contributor

@epoberezkin I think you are right about the outside-of-the-spec approach, at least for non-schema-aware general JSON merging (#15 and to a lesser degree #98). And despite coming up with #119 I'm not actually a huge fan of it! Anyway, this issue should be closed as a duplicate unless @erikfox or other commenters think we're missing something in those other issues.

@handrews
Copy link
Contributor

@erikfox it's been over a month since we suggested closing this in favor of other pre-existing issues, so I'm taking your lack of response as being OK with closing it.

Please feel free to re-open if you think I'm missing something- just include a comment about what still needs to be addressed. But mostly I think this is a dup of #15 with an alternate syntax.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants