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

Update JSON schemas to use draft-07 #62462

Closed
ajlende opened this issue Jun 11, 2024 · 4 comments · Fixed by #63583
Closed

Update JSON schemas to use draft-07 #62462

ajlende opened this issue Jun 11, 2024 · 4 comments · Fixed by #63583
Labels
Good First Issue An issue that's suitable for someone looking to contribute for the first time [Type] Code Quality Issues or PRs that relate to code quality [Type] Enhancement A suggestion for improvement.

Comments

@ajlende
Copy link
Contributor

ajlende commented Jun 11, 2024

We've been following the SchemaStore best practices for the development of our JSON schemas. They recommend a schema version based on what is widely supported in editors and IDEs. Previously this was draft-04, so all of our schemas currently use that version. However the new recommendation is draft-07 which comes with some quality of life improvements that can improve the readability and maintainability of our JSON schemas. Namely:

  1. The $comment keyword to explain reasoning behind schema decisions inline.
  2. The propertyNames keyword to improve merging of two or more object subschemas while limiting additionalProperties.

Additionally, SchemaStore has an unofficial "strict mode" draft-07 meta schema https://json.schemastore.org/metaschema-draft-07-unofficial-strict.json that requires type, title, and description properties which we should be using and provides links to understanding-json-schema for each hint/check to help new JSON Schema contributors.

  • There are some breaking changes from draft-04 to draft-06. You can migrate schemas from draft-04 to draft-07 using ajv-cli.
  • The pattern of *PropertiesComplete can be updated to use propertyNames instead of lists of empty objects.
  • The enum properties with single values can be updated to const where it would make sense to use const.
@ajlende ajlende added [Type] Code Quality Issues or PRs that relate to code quality Good First Issue An issue that's suitable for someone looking to contribute for the first time labels Jun 11, 2024
@DivyanshVinayak23
Copy link

Hi, can I work on this?

@ajlende
Copy link
Contributor Author

ajlende commented Jun 11, 2024

Hi, can I work on this?

@DivyanshVinayak23 Absolutely!

Check out the contributing guidelines, specifically the developer section, for general information on how to contribute code.

The #core-editor channel on Make WordPress Slack (registration required) is also a good place to ask questions if you have any.

@jordesign jordesign added the [Type] Enhancement A suggestion for improvement. label Jun 14, 2024
@scruffian
Copy link
Contributor

I noticed we use the ajv-draft-04 npm package, and I can't find an alternative for draft-07...

@ajlende
Copy link
Contributor Author

ajlende commented Jun 24, 2024

I noticed we use the ajv-draft-04 npm package, and I can't find an alternative for draft-07...

The draft-07 validator is in the main ajv package. Because there were breaking changes, they made the draft-04 validator its own package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Good First Issue An issue that's suitable for someone looking to contribute for the first time [Type] Code Quality Issues or PRs that relate to code quality [Type] Enhancement A suggestion for improvement.
4 participants