Skip to content

[Blueprints] Updating json schema#3236

Draft
fellyph wants to merge 3 commits intotrunkfrom
updating-json-schema
Draft

[Blueprints] Updating json schema#3236
fellyph wants to merge 3 commits intotrunkfrom
updating-json-schema

Conversation

@fellyph
Copy link
Collaborator

@fellyph fellyph commented Feb 3, 2026

This pull request updates the blueprint-schema.json schema in the playground blueprints package to improve type validation. The main change replaces the use of the type array with the more explicit anyOf keyword to specify multiple allowed types for properties, which is the recommended approach in JSON Schema.

Schema validation improvements:

  • Updated the PHPConstants definition to use anyOf for specifying that property values can be strings, booleans, or numbers, instead of using the type array.
  • Updated a schema location (within an array of possible types) to use anyOf for allowing either an object or a string, replacing the previous type array usage.

PR Related to #3178

…n blueprint-schema-validator.js

- Updated schema definitions to replace 'type' arrays with 'anyOf' for better clarity and validation accuracy.
- Enhanced error handling in validation functions to provide more specific error messages for type mismatches.
- Improved overall structure and readability of the validation logic.

This change aims to ensure more robust schema validation and clearer error reporting.
… for Ajv compatibility

- Introduced a new function to recursively transform JSON Schema type arrays into 'anyOf' format, ensuring compatibility with Ajv's strict mode.
- Updated the schema compilation process to utilize the transformed schema, improving validation accuracy and clarity.
- This change aims to enhance the robustness of schema validation in the playground environment.
…improved schema validation

- Modified the schema definitions for PHPConstants and additional properties to utilize 'anyOf' instead of type arrays.
- This change enhances compatibility with Ajv and improves validation accuracy, following recent schema enhancements.
@fellyph
Copy link
Collaborator Author

fellyph commented Feb 3, 2026

@westonruter, I have submitted this PR it solve your issue?

@westonruter
Copy link
Member

@fellyph I tried modifying WordPress/performance as follows to test the new schema:

diff --git a/bin/validate-json.js b/bin/validate-json.js
index 503845ba..1928d098 100755
--- a/bin/validate-json.js
+++ b/bin/validate-json.js
@@ -37,7 +37,7 @@ const schemaCache = new Map();
 function createAjv( AjvConstructor ) {
 	const ajv = new AjvConstructor( {
 		allErrors: true,
-		strict: false, // See <https://github.com/WordPress/wordpress-playground/issues/3178>.
+		strict: true,
 		loadSchema: fetchSchema,
 	} );
 
diff --git a/plugins/performance-lab/.wordpress-org/blueprints/blueprint.json b/plugins/performance-lab/.wordpress-org/blueprints/blueprint.json
index 867cd923..26db6b47 100644
--- a/plugins/performance-lab/.wordpress-org/blueprints/blueprint.json
+++ b/plugins/performance-lab/.wordpress-org/blueprints/blueprint.json
@@ -1,5 +1,5 @@
 {
-	"$schema": "https://playground.wordpress.net/blueprint-schema.json",
+	"$schema": "https://raw.githubusercontent.com/WordPress/wordpress-playground/685b6b80d04e9deb970ece92b04cccdc430cd67a/packages/playground/blueprints/public/blueprint-schema.json",
 	"landingPage": "/wp-admin/admin.php?page=perflab-modules",
 	"plugins": [ "performance-lab" ],
 	"login": true,

I get a different error now:

Error validating JSON: strict mode: unknown keyword: "discriminator"

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

Labels

None yet

2 participants