Skip to content

Conversation

joshuatf
Copy link
Contributor

@joshuatf joshuatf commented Aug 14, 2024

Changes proposed in this Pull Request:

This PR is a POC around creating our own library for validation using JSON Schema. This package was created as an alternative to using an existing library because:

  • The existing libraries (AJV) are larger in size and it's likely this library will be used on the frontend of the site (111kb vs < 10kb)
  • The $data pointer property is needed for comparison between two properties
  • Higher level of extensibility within the validation itself
Screenshot 2024-08-14 at 11 16 31 AM

How to test the changes in this Pull Request:

Since this is a POC, it's not important that this is fully functional, but this can act as a general guide for the person who takes over validation. Here are some questions to think about:

  1. Do the general concepts and exposed functions look reasonable in the README?
  2. Is the code organized and easy to understand? Does it scale well with the addition of new keywords and property types?
  3. Could this package be moved upstream to Gutenberg?
  4. Outside of the additional types and keywords needed, is there additional functionality we should consider introducing?

Some of the validation in this PR is demoed in the new product editor. You can test this by:

  1. Enabling the new product editing experience under admin.php?page=wc-settings&tab=advanced&section=features
  2. Navigating to Products -> Add new
  3. Type in the name field, see errors in the console if name is <5 characters in length
  4. Note the external_url error in the console if not yet inserted
  5. Add a space to the SKU field, note the error in the console

Changelog entry

  • Automatically create a changelog entry from the details below.
  • This Pull Request does not require a changelog entry. (Comment required below)
Changelog Entry Details

Significance

  • Patch
  • Minor
  • Major

Type

  • Fix - Fixes an existing bug
  • Add - Adds functionality
  • Update - Update existing functionality
  • Dev - Development related task
  • Tweak - A minor adjustment to the codebase
  • Performance - Address performance issues
  • Enhancement - Improvement to existing functionality

Message

Changelog Entry Comment

Comment

@joshuatf joshuatf self-assigned this Aug 14, 2024
@github-actions github-actions bot added the focus: monorepo infrastructure Issues and PRs related to monorepo tooling. label Aug 14, 2024
Copy link
Contributor

Hi @youknowriad, @louwie17, @gigitux,

Apart from reviewing the code changes, please make sure to review the testing instructions and verify that relevant tests (E2E, Unit, Integration, etc.) have been added or updated as needed.

You can follow this guide to find out what good testing instructions should look like:
https://github.com/woocommerce/woocommerce/wiki/Writing-high-quality-testing-instructions

@github-actions github-actions bot added the plugin: woocommerce Issues related to the WooCommerce Core plugin. label Aug 14, 2024
@ajlende
Copy link

ajlende commented Aug 14, 2024

Which version of JSON Schema are you targeting?

@joshuatf
Copy link
Contributor Author

Hey @ajlende 👋 Sorry for the late reply.

This is a POC PR and we'll likely try to move this package upstream, but will likely target draft 07 or draft 2019-09. The latter introduces a few new concepts which might be useful (dependentRequired comes to mind), but will come at a performance cost to this package.

Also worth noting that this won't follow the exact spec given we'll need $data pointers to compare properties.

Happy to hear any thoughts you have around draft used or otherwise!

@joshuatf
Copy link
Contributor Author

This validation package was being worked on by @senadir though may be on hold given other current priorities. Closing this PR.

@joshuatf joshuatf closed this Apr 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
focus: monorepo infrastructure Issues and PRs related to monorepo tooling. plugin: woocommerce Issues related to the WooCommerce Core plugin.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants