-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Update JSON Schemas to Draft 7 #63583
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @DivyanshVinayak23. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Size Change: 0 B Total Size: 1.75 MB ℹ️ View Unchanged
|
6825d36
to
63edffd
Compare
ea61881
to
2ac04ea
Compare
1fab073
to
2ac04ea
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I understand it, this looks like its working as expected and the code looks good. I'd appreciate a review from someone with more knowledge of this area though.
I added a test for each of the 10 places that I manually refactored to use @scruffian is that helpful? |
fb81b62
to
7f1a9f1
Compare
7f1a9f1
to
5fce792
Compare
@@ -45,4 +49,13 @@ describe( 'theme.json schema', () => { | |||
|
|||
expect( result ).toBe( true ); | |||
} ); | |||
|
|||
test.each( invalidFiles )( 'invalidates schema for `%s`', ( filepath ) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would appreciate it if you could tell me why it is necessary to validate invalid theme.json
files.
Isn't it enough to simply check whether theme.json
files in the Gutenberg project are valid via the validates schema for %s
test? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would appreciate it if you could tell me why it is necessary to validate invalid
theme.json
files.Isn't it enough to simply check whether
theme.json
files in the Gutenberg project are valid via thevalidates schema for %s
test? 🤔
Good question! Testing should have a good purpose, and I don't think it always does.
In software development this kind of testing is called negative testing. It's covering failure paths to make sure that they still fail in a way that you would expect.
The theme.json schema is used by many developers, not just core. We want to ensure that invalid properties are flagged for those theme developers as they are developing their themes.
In my personal philosophy of testing, I see tests as a communication tool much like short self-contained correct "compileable" examples (SSCCEs). It can help people who are less familiar with a change understand specifically what has been changed.
The theme.json schema is a complicated schema with a lot of anyOf
/allOf
logic and $ref
s. In this update, I manually changed the way that we invalidate some of those properties by using propertyNames
instead of additionalProperties
, and it isn't immediately obvious where each of those changes affects validation in theme.json. It actually took me a while to trace through all the references in the schema to generate those test files.
As a bonus, tests like this can reduce the burden of manual testing by reviewers when there are a lot of cases to test. Instead of going through each case, if the test can be written simply enough, it's often easier to check the validity of a single test than many manual cases.
I've written the test cases so that they should pass for the old schemas and the new schemas. If one of the tests passed with the old schemas and failed with the new schemas, we would know that I messed something up in my refactor since these properties should be invalid in both cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Thank you for the detailed explanation. I think the schemas are updated perfectly correctly in this PR 🚀
@DivyanshVinayak23 mind sharing your WordPress.org username so I can ensure its included in the 6.7 credits listing? |
What?
Updates all JSON Schemas to use the Draft 7 metaschema.
Why?
Fixes #62462
Additionally, updating to using
propertyNames
uncovered some places where theadditionalProperties
hack wasn't updated properly. Those were fixed in #63582, and this change should ensure that it doesn't happen again in these places.How?
ajv-cli
for initial automated migration to handleexclusiveMinimum
andconst
usage.propertyNames
where appropriate.Testing Instructions
Ensure that validation is still working for all schemas.
Testing Instructions for Keyboard
N/A
Screenshots or screencast
N/A