woocommerce/packages/php/remote-specs-validation
Leif Singer 8ee74ede0e
Update Woo.com references to WooCommerce.com (#46259)
* replace capitalized Woo.com with WooCommerce.com

* replace http URLs

* replace https URLs

* replace developer.woo.com

* add missing version in `@since` tag

* unslash the HTTP_REFERER

* WordPress.Security.ValidatedSanitizedInput.InputNotSanitized

* add changelog file

* add more changelog files

* address linter errors

* address more linter errors

* fix test

* more linter errors
2024-04-09 09:50:15 +01:00
..
bin Add JSON schema files for remote spec validation (#44484) 2024-02-16 13:31:21 -08:00
bundles Add range operator in Remote Inbox Notification (#45201) 2024-02-29 13:02:38 -08:00
changelog Update Woo.com references to WooCommerce.com (#46259) 2024-04-09 09:50:15 +01:00
schemas Add range operator in Remote Inbox Notification (#45201) 2024-02-29 13:02:38 -08:00
src Allow JSON schema string (#45151) 2024-02-27 00:34:41 -08:00
tests Update Woo.com references to WooCommerce.com (#46259) 2024-04-09 09:50:15 +01:00
README.md Remote Specs: Update endpoints to 2.0 (#45298) 2024-03-12 15:53:59 +13:00
changelog.md Remote Specs Testing package: Add new package (#44419) 2024-02-08 12:46:26 +13:00
composer.json Allow JSON schema string (#45151) 2024-02-27 00:34:41 -08:00
composer.lock Add JSON schema files for remote spec validation (#44484) 2024-02-16 13:31:21 -08:00
package.json pin simple-git in syncpack (#44902) 2024-02-29 13:30:24 -04:00
phpunit.xml Add JSON schema files for remote spec validation (#44484) 2024-02-16 13:31:21 -08:00

README.md

Remote Specification Validation

Installation

composer require woocommerce/remote-specs-validation

Available Schemas

Filename Endpoint Bundle
remote-inbox-notification.json https://woocommerce.com/wp-json/wccom/inbox-notifications/2.0/notifications.json remote-inbox-notification
payment-gateway-suggestions.json https://woocommerce.com/wp-json/wccom/payment-gateway-suggestions/2.0/suggestions.json payment-gateway-suggestions
obw-free-extensions.json https://woocommerce.com/wp-json/wccom/obw-free-extensions/4.0/extensions.json obw-free-extensions
wc-pay-promotions.json https://woocommerce.com/wp-json/wccom/payment-gateway-suggestions/2.0/payment-method/promotions.json wc-pay-promotions
shipping-partner-suggestions.json https://woocommerce.com/wp-json/wccom/shipping-partner-suggestions/2.0/suggestions.json shipping-partner-suggestions

Working with Schema

If it's your first time working with JSON Schema, we highly recommend reading https://json-schema.org/learn/getting-started-step-by-step first.

  1. Open a schema file from schemas directory.
  2. Make changes.
  3. Run ./bin/build schemas/:name-of-schema-file
  4. Bundled schema file will be saved in bundles directory.

Validation Examples

use Automattic\WooCommerce\Tests\RemoteSpecsValidation\RemoteSpecValidator;
$validator = RemoteSpecValidator::create_from_bundle( 'remote-inbox-notification' );

$spec = json_decode( file_get_contents(":your-remote-inbox-noficiation-json") );

$result = $validator->validate( $spec );

if ( !$result->is_valid() ) {
	var_dump( $result->get_errors() );
} else {
	var_dump('everyting looks good!');
}