Skip to content

Conversation

@priethor
Copy link
Contributor

@priethor priethor commented Dec 24, 2025

What

Required for #162.

Adds a SCF_Schema_Builder class to handle JSON Schema composition for field type validation.

Why

WordPress internal JSON validation uses V4 and doesn't understand JSON Schema $ref or complex schema composition. Field validation requires type-specific rules while sharing:

  • Base properties common to all 35 field types.
  • Properties shared by all/most fields in the same category that could be defined once and referenced, instead of defined multiple times.

This builder enables strict per-type validation through oneOf composition and extracts the existing $ref resolution.

How

Extracting schema building logic from abilities classes into a dedicated SCF_Schema_Builder class that:

  • Resolves $ref references by inlining definitions for WordPress compatibility
  • Composes field schemas with oneOf variants for each field type

Since WordPress validation doesn't support allOf for the field composition, what we do here for fields at runtime is:

  1. Load the base properties common to all fields
  2. Load each partial field schema that has its specific fields
  3. Resolve any references for reusable properties that are not common to all fields but defined once
  4. Compose a full JSON schema for the field, with all properties.
  5. The validation will accept oneOf each complete field schema.

This PR also adds the most basic field schema, text.schema.json, as the first type-specific schema to validate the composition pipeline.

Testing Instructions

  1. Run vendor/bin/phpunit tests/php/includes/SCFSchemaBuilderTest.php - all 8 tests should pass
  2. Run full test suite vendor/bin/phpunit - all 404 tests should pass
  3. Run composer test:phpstan - no errors

@codecov
Copy link

codecov bot commented Dec 24, 2025

Codecov Report

❌ Patch coverage is 95.14563% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 14.46%. Comparing base (8887e6c) to head (f35baf7).

Files with missing lines Patch % Lines
includes/class-scf-schema-builder.php 94.11% 5 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##              trunk     #301      +/-   ##
============================================
+ Coverage     14.36%   14.46%   +0.09%     
- Complexity     4386     4397      +11     
============================================
  Files           286      287       +1     
  Lines         35270    35320      +50     
============================================
+ Hits           5066     5108      +42     
- Misses        30204    30212       +8     
Flag Coverage Δ
e2e 30.69% <ø> (-0.03%) ⬇️
javascript 2.60% <ø> (ø)
phpunit 10.61% <95.14%> (+0.14%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@priethor priethor force-pushed the add/schema-composer branch from a4954d7 to 4e320f1 Compare December 24, 2025 17:08
@priethor priethor self-assigned this Dec 24, 2025
@priethor priethor added the [Type] Enhancement New feature or request label Dec 24, 2025
@priethor priethor changed the title Add schema composer and move ref resolution there JSON Schemas: Add SCF_Schema_Builder for field schema composition Dec 24, 2025
@priethor priethor force-pushed the add/schema-composer branch from 89d843b to 2cad3db Compare December 24, 2025 18:27
@priethor priethor marked this pull request as ready for review December 24, 2025 18:28
@github-actions
Copy link

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 props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props priethor.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

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

Labels

[Type] Enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants