- Notifications
You must be signed in to change notification settings - Fork704
"anyOf" should match the best possible option rather than a 100% exac…#1674
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:master
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
germanbisurgi commentedSep 17, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Old code
New PR code
Conclusion
@zeze0556 It looks to me that what you want is already in the old version |
For the following schema definition: {"type":"object","properties":{"foo":{"anyOf":[{"$ref":"#/definitions/A"},{"$ref":"#/definitions/B"}]}},"definitions":{"A":{"type":"object","properties":{"type":{"enum":["A"],"type":"string"},"referenced":{"$ref":"#/definitions/ReferencedObject"}},"required":["type"]},"B":{"type":"object","properties":{"type":{"enum":["B"],"type":"string"},"referenced":{"properties":{"foo":{"type":"string"},"bar":{"type":"string"}},"type":"object"},"addon":{//<== new addon with default"type":"string","default":"addon"}},"required":["type","addon"//<== make it required]},"ReferencedObject":{"properties":{"foo":{"type":"string"},"bar":{"type":"string"}},"type":"object"}}} For the definition of legacy data: {"foo": {"type":"B","referenced": {"foo":"","bar":"" } }}Versions >= 2.6.0 getValue() will return: {"foo": {"type":"A","referenced": {"foo":"","bar":"" } }}Versions < 2.6.0 getValue() will return: {"foo": {"type":"B","referenced": {"foo":"","bar":"" },"addon":"addon" }}This patch will not break the legacy data and will update it to the new data structure. This is relatively friendly for automatic data updates. |
I think there should be an editor option to enable this feature. |
I tested in my local copybut idid not seea difference with the provided schema. |
If the version is >= 2.6.0, it will automatically match "#/definitions/A". |
json-editor is at version 2.15.2 at the moment. |
…t match.