Blank numeric text integration configuration field not validated on save
Describe the bug
- Integration configuration text field with numeric string format not validated on save
- This has come up multiple times where users have left the field blank and then it errors at runtime
To Reproduce
Steps to reproduce the behavior:
- Add the
automation-anywhere/control-roomintegration - Provide an invalid configuration (invalid because Folder ID regex is
\d+)
Expected behavior
Discussion
- Is Formik not validating the field? Or does the schema-to-yup field consider it as being valid because it's an optional field? The documentation for Yup required seems to indicate required corresponds with null/undefined: https://github.com/jquense/yup?tab=readme-ov-file#schemarequiredmessage-string--function-schema
- Best fix might be to run the JSON Schema validator check on save as a backstop for inconsistency between Yup Schema generation and JSON Schema?
Related Code
- https://github.com/pixiebrix/pixiebrix-extension/blob/837ea111eead6afd0adec5c76cf8b628e220a5fb/contrib/integrations/automation-anywhere.yaml#L31-L31
After doing some research, the problem appears to be that an empty string for a non-required field is still considered valid by yup. @cf-worker's validator also seems to deliver the same result.
I tried adding a minLength to the schema for the relevant field, but it still passes even though I've confirmed the minLength is being converted to yup. Again, I believe this is because empty strings are allowed when the field isn't required.
What is the exact error/problem from having an empty string for folderId? Would stripping empty strings from the formData (either deleting the keys or setting the values to null) resolve the problem?
cc @twschiller
https://github.com/cf-worker's validator also seems to deliver the same result.
Noting from our call that it seems like a code reload issue, and that cf-worker was catching it
Noting from our call that it seems like a code reload issue, and that cf-worker was catching it
Yes, looks like I had an issue with hot reloading not triggering for some reason. I'll look into converting the validation result so that the appropriate error is displayed.
Reopened due to bug when saving some configurations:
@grahamlangford see this file for examples of validating JSON Schemas: https://github.com/pixiebrix/pixiebrix-extension/blob/4668ee9455d97634a9512663bf0c80c04c7a91ef/src/validators/schemaValidator.ts#L244-L244