-
Notifications
You must be signed in to change notification settings - Fork 39
JSON Schemas: Add framework and Post Type schema #221
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
Conversation
schemas/post-type.schema.json
Outdated
| }, | ||
| "description": "The post type key passed to register_post_type() (e.g. 'book', 'product'). Max 20 characters, lowercase letters/numbers/underscores/dashes only, cannot be WordPress reserved terms." | ||
| }, | ||
| "ID": { |
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 exported a json post type and could not see any ID, I guess it will be internal.
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.
It is internal, but upon a more detailed check, I've noticed it's actually always ignored in favor of the key property, so:
- When importing a new Post Type, the ID is not used and is assigned upon DB insertion.
- When importing an existing Post Type, the ID is overwritten with the actual ID.
All in all, it's only metadata that represents the Post Type, but since it's never used during import or export, let's remove it.
Good catch!
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.
It's a long PR, I couldn't find anything weird or out of a default export.
I guess we may find some issues in a future when is used, but we need that testing / feedback.
What
Part of #162.
Adds JSON schema validation infrastructure for post type definitions. This not only improves the creation of new Post Types via JSON files, but also makes integrating the Abilities API easier.
Why
SCF supports exporting and importing its entities through JSON files, but the lack of schemas makes it difficult to create them from scratch; even LLMs have trouble creating a basic, working JSON file for post types, as seen in the included fixture of a wrong format.
Having these schemas will help create new post types from scratch by:
How
SCF_JSON_Schema_Validatorthat accepts different format (JSON files, strings, or PHP objects) and serves as a base for post type schemas and future ones.1. The import and schema accept both strings and boolean values. The same goes with single/multiple post types, the import accepts both.Testing Instructions
composer test:php tests/php/PostTypeSchemaTest.php --verbose- all post type schema validation tests should pass3.1 Create a post type
3.2 Go to SCF -> Tools, export the post type
3.3 Put it in
tests/php/fixtures/schemas/post-types/valid3.4 Run again the test via
composer test:php tests/php/PostTypeSchemaTest.php --verbose, it should pass.