Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

"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

Open
zeze0556 wants to merge1 commit intojson-editor:master
base:master
Choose a base branch
Loading
fromzeze0556:master

Conversation

@zeze0556
Copy link

…t match.

QA
Is bugfix?✔️
New feature?
Is backward-compatible?✔️
Tests pass?✔️❌
Fixed issuescomma-separated list of tickets # fixed by the PR, if any
Updated README/docs?
Added CHANGELOG entry?

@germanbisurgi
Copy link
Collaborator

germanbisurgi commentedSep 17, 2025
edited
Loading

Old code

  • Checksall validators.
  • Picks thefirst one that validates, but can switch later if a better match is found.
  • Bug: sometimes throws away the "best fit" when a validator fails.

New PR code

  • Stops checking as soon as it finds thefirst validator that passes.
  • Fixes the bug (no longer discards best fit on failure).
  • But now itwon’t find a better match later — only the first valid one counts.

Conclusion

  • ✅ If you want“first valid wins”, the PR is fine (but the title is misleading).
  • ⚠️ If you want“best match”, the PR breaks that and should be adjusted.

@zeze0556 It looks to me that what you want is already in the old version

@zeze0556
Copy link
Author

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.

@schmunk42
Copy link
Collaborator

I think there should be an editor option to enable this feature.

@germanbisurgi
Copy link
Collaborator

I tested in my local copybut idid not seea difference with the provided schema.
Could you list your steps list to reproduce your case, please?

@zeze0556
Copy link
Author

var editor = JSONEditor(dom,{      schema: schema, //use comment schema      startval: {          "foo": {            "type": "B",            "referenced": {              "foo": "",              "bar": ""            }          }},      keep_oneof_values:false    });console.log('value=', editor.getValue());

If the version is >= 2.6.0, it will automatically match "#/definitions/A".
If the version is < 2.6.0, it will match the correct schema: "#/definitions/B".
In this case, the correct match should be "#/definitions/B".

@germanbisurgi
Copy link
Collaborator

json-editor is at version 2.15.2 at the moment.
Using the changes in the Pull Request does not change the json output in my local copy 😕

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@germanbisurgigermanbisurgiAwaiting requested review from germanbisurgi

At least 1 approving review is required to merge this pull request.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@zeze0556@germanbisurgi@schmunk42

[8]ページ先頭

©2009-2025 Movatter.jp