wp-env: Update JSON Schema with missing properties and add README docs#76115
wp-env: Update JSON Schema with missing properties and add README docs#76115kraftbj wants to merge 4 commits intoWordPress:trunkfrom
Conversation
Add a JSON Schema file that enables editor autocomplete and validation for .wp-env.json configuration files. Users can opt in by adding a $schema key pointing to the published schema URL. The schema covers all root-level and per-environment options, including the recently added autoPort option, and rejects unknown keys to catch typos early.
|
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 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. |
| To enable editor autocomplete and validation, add a `$schema` key: | ||
|
|
||
| ```json | ||
| { | ||
| "$schema": "https://schemas.wordpress.org/wp-env.schema.json", | ||
| "plugins": [ "." ] | ||
| } | ||
| ``` | ||
|
|
There was a problem hiding this comment.
I think this is a good to have regardless of whether we have a new schema doc or keep on using https://schemas.wp.org/trunk/wp-env.json 👍🏻
Remove the duplicate schema and test added in packages/env/lib/config/ and instead update the existing schemas/json/wp-env.json with the missing properties: autoPort, mysqlPort, phpVersion pattern validation, port range constraints, config/mappings typing, phpmyadminPort null support, and afterReset/afterCleanup lifecycle scripts. Also fix the $schema URL in the wp-env README to use schemas.wp.org (consistent with other schemas), add wp-env.json to schemas/README.md, and document the schemas directory in AGENTS.md.
ramonjd
left a comment
There was a problem hiding this comment.
Thanks for updating the schema with the new props 🙇🏻
Looking pretty good. Just had a couple of questions around validation.
schemas/json/wp-env.json
Outdated
| { | ||
| "type": "string" | ||
| "type": "string", | ||
| "pattern": "^[0-9]+\\.[0-9]+$" |
There was a problem hiding this comment.
Also wondering if this should match the runtime validator regex in checkVersion
This is a bit stricter, allowing x.x, but not x.x.x for example.
I'm looking at version_compare for examples.
What do you think?
There was a problem hiding this comment.
Thanks for the thorough review! All three items addressed:
- Added
allowUnionTypes: trueto the test AJV options - Updated port
minimumto0to match the runtimecheckPortvalidator — you're right it's a non-issue in practice but might as well match - Updated
phpVersionpattern to^[0-9]+(?:\.[0-9]+)*$to match the runtimecheckVersionregex, accepting "X", "X.X", and "X.X.X" formats
- Match runtime phpVersion validator pattern: accept "X", "X.X", and "X.X.X" formats instead of only "X.X" - Match runtime port validator: allow port 0 (minimum: 0) to align with checkPort in validate-config.js - Add allowUnionTypes to AJV options in schema test to support union type arrays in config additionalProperties
What?
Update the existing
schemas/json/wp-env.jsonschema with missing properties and improve documentation for schema usage.Why?
The existing wp-env JSON Schema was missing several configuration options that have been added to wp-env over time (
autoPort,mysqlPort, lifecycle scriptsafterReset/afterCleanup). It also lacked validation constraints (port ranges, phpVersion pattern, config/mappings value types). Meanwhile, the wp-env README and schemas README had no mention of the schema, making it hard to discover.How?
schemas/json/wp-env.jsonwith missing properties:autoPort(root-only),mysqlPort(shared),afterResetandafterCleanuplifecycle scripts.phpVersionpattern (^[0-9]+\.[0-9]+$),configvalue types (string/number/boolean),mappingsvalue types (string),phpmyadminPortnull support.$schemausage note topackages/env/README.mdpointing toschemas.wp.org/trunk/wp-env.json.wp-env.jsontoschemas/README.mddescription and usage examples.schemas/json/directory inAGENTS.md.Testing Instructions
.wp-env.jsonfile in any project."$schema": "https://schemas.wp.org/trunk/wp-env.json"(or use a relative path toschemas/json/wp-env.json).core,plugins,port,autoPort,mysqlPort, etc.).autoPortandtestsPortshow warnings when placed inside anenvoverride.Testing Instructions for Keyboard
N/A — no UI changes.