Skip to content

Commit

Permalink
Merge branch 'trunk' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
szepeviktor authored Jul 14, 2024
2 parents 2fbaaf4 + e21ba17 commit 59763a6
Show file tree
Hide file tree
Showing 186 changed files with 2,641 additions and 11,029 deletions.
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = tab
indent_size = 4

[*.yml]
indent_style = space
Expand Down
1 change: 0 additions & 1 deletion .github/FUNDING.yml

This file was deleted.

2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,3 @@

/composer.lock
/package-lock.json
/tests/.env
/tests/hyper-schema/index.js
18 changes: 14 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ There is no fully automatic process to create these schemas. A schema for a PHP

npm install

3. If you want to run the tests locally, check the MySQL database credentials in the `tests/.env` file and amend them as necessary.

## Creating a REST API response schema

The WordPress REST API response doesn't fully adhere to the JSON schema spec, so we need to tweak its output in order to generate a valid schema and to increase its specificity.
Expand All @@ -47,7 +45,7 @@ The WordPress REST API response doesn't fully adhere to the JSON schema spec, so
- Start by copying an existing file such as `post.php` which is for `/wp/v2/posts`
- The command should perform one or more REST API requests to the endpoint and pass the responses to the `save_rest_array()` function which saves them as JSON during the tests
* Run `composer run test` to validate and test the schemas.
* Run `npm run build-wp-types` and check the output of `packages/wp-types/index.ts`.
* Check the output of `packages/wp-types/index.ts`.
* Add documentation for the schema in both `readme.md` and `packages/wp-types/readme.md`.

## Creating a PHP object schema
Expand All @@ -71,9 +69,21 @@ The schema for a PHP object is created using the docblocks from its class proper
- Start by copying an existing file such as `error.php`
- The file should pass an array of one or more objects of this type to the `save_object_array()` function which saves it as JSON during the tests
* Run `composer run test` to validate and test the schemas.
* Run `npm run build-wp-types` and check the output of `packages/wp-types/index.ts`.
* Check the output of `packages/wp-types/index.ts`.
* Add documentation for the schema in both `readme.md` and `packages/wp-types/readme.md`.

## Updating schemas for a new WordPress release

* composer require --dev roots/wordpress-full=dev-main
* composer update
* composer test

Address any test failures by updating the corresponding schema files.

Address any newly added REST API routes by adding them to both readme files and adding a schema if necessary or documenting them as "Todo".

For release, update the WordPress version number in composer.json and the readme files.

## Releasing a new version

* npm install
Expand Down
32 changes: 25 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,56 @@
"homepage": "https://johnblackbourn.com/"
}
],
"repositories": [
{
"type": "composer",
"url": "https://wpackagist.org",
"only": [
"wpackagist-plugin/*",
"wpackagist-theme/*"
]
}
],
"require": {
"php": "^7 || ^8"
},
"require-dev": {
"ext-sqlite3": "*",
"ext-pdo_sqlite": "*",
"ergebnis/json-printer": "^3.5",
"johnbillion/args": "1.7.0",
"roots/wordpress-core-installer": "^1.0.0",
"roots/wordpress-full": "~6.2.0",
"vlucas/phpdotenv": "^5",
"roots/wordpress-full": "6.6-RC3",
"wp-cli/core-command": "^2",
"wp-cli/db-command": "^2",
"wp-cli/language-command": "^2"
"wp-cli/language-command": "^2",
"wpackagist-plugin/sqlite-database-integration": "^2.1"
},
"config": {
"allow-plugins": {
"composer/installers": true,
"roots/wordpress-core-installer": true
},
"preferred-install": "dist",
"sort-packages": true
},
"extra": {
"installer-paths": {
"tests/wordpress/wp-content/plugins/{$name}/": [
"wpackagist-plugin/sqlite-database-integration"
]
},
"wordpress-install-dir": "tests/wordpress"
},
"scripts": {
"post-update-cmd": [
"@php -r \"! file_exists( 'tests/.env' ) && copy( 'tests/.env.dist', 'tests/.env' );\""
],
"test": [
"@php -r \"file_exists( 'tests/wordpress/wp-content/db.php' ) || copy( 'tests/wordpress/wp-content/plugins/sqlite-database-integration/db.copy', 'tests/wordpress/wp-content/db.php' );\"",

"npm run validate",
"npm run build-wp-types",
"npm run test-wp-types",

"wp db reset --yes",
"rm -f tests/wordpress/wp-content/database/.ht.sqlite",
"wp core multisite-install --url=example.org --title=Example --admin_user=admin [email protected] --skip-email",
"wp language core install de_DE it_IT ar he_IL",

Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wp-json-schemas",
"version": "3.62.1",
"version": "3.66.0",
"description": "JSON schemas for WordPress PHP objects and REST API responses",
"main": "schema.json",
"files": [
Expand Down Expand Up @@ -28,8 +28,7 @@
"scripts": {
"version": "cd packages/wp-types && npm version $(node -p -e \"require('../../package.json').version\") && git add .",
"build-wp-types": "json2ts -i schema.json -o packages/wp-types/index.ts --style.trailingComma=all --style.useTabs && cat packages/wp-types/append.ts >> packages/wp-types/index.ts",
"build-hyper-schema-types": "json2ts -i tests/hyper-schema/hyper-schema.json -o tests/hyper-schema/index.ts --style.trailingComma=all --style.useTabs",
"test-wp-types": "tsc packages/wp-types/tests/test.ts --noEmit --strict",
"validate": "ajv compile --strict --strict-schema=false -c ajv-formats -m tests/hyper-schema/hyper-schema.json -s schema.json -r \"schemas/**/*.json\""
"validate": "ajv compile --strict --strict-schema=false -c ajv-formats -m tests/external-schemas/hyper-schema.json -s schema.json -r \"schemas/**/*.json\""
}
}
7 changes: 5 additions & 2 deletions packages/wp-types/append.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
type ValueOf<T> = T[keyof T]

/**
* An enveloped REST API response.
* An enveloped REST API response (with `?_envelope`).
*
* @template T A REST API response type.
*/
Expand All @@ -18,5 +18,8 @@ export interface WP_REST_API_Envelope<T extends ValueOf<WP["REST_API"]>> {
/**
* The HTTP headers
*/
headers: object;
headers: {
[k: string]: string|number;
};
[k: string]: unknown;
}
Loading

0 comments on commit 59763a6

Please sign in to comment.