-
Notifications
You must be signed in to change notification settings - Fork 11
fix(input_schema): show all valid editors in error when invalid editor is used on array property #596
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
…rray property When an invalid editor value (e.g., "fileUpload" instead of "fileupload") was used on an array field, the error message only showed a single editor from the first oneOf branch instead of all valid options. Now the error lists all valid array editors when the value is completely outside the allowed set. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Verifies that invalid editor values on nested (sub-schema) array properties show all valid editors, not just a subset from a oneOf branch. Co-Authored-By: Claude Opus 4.6 <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Improves human-readable AJV validation errors for input_schema by ensuring invalid editor values on array fields report the complete set of valid editors (instead of a misleading subset from a oneOf/anyOf branch), and updates/adds regression tests for this behavior.
Changes:
- Add logic to select a more relevant AJV error and enhance enum errors from
oneOf/anyOfbranches to show top-level allowed values when the provided value is outside the allowed set. - Update existing array-editor validation tests to expect the full allowed editor list.
- Add new tests covering invalid editor values on array properties (including nested/sub-schema arrays).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
packages/input_schema/src/input_schema.ts |
Adds selectBestError and enhances enum error reporting to prefer full allowed editor lists when appropriate. |
test/input_schema.test.ts |
Updates expected error messages and adds coverage for invalid array editor values (top-level and nested). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| function selectBestError(errors: ErrorObject[]): ErrorObject { | ||
| const branchPattern = /\/(oneOf|anyOf)\/\d+\//; | ||
| const nonBranchErrors = errors.filter( | ||
| (e) => !branchPattern.test(e.schemaPath) && e.keyword !== 'oneOf' && e.keyword !== 'anyOf', | ||
| ); | ||
| return nonBranchErrors[0] ?? errors[0]; | ||
| } | ||
|
|
||
| /** | ||
| * Validates a given object against the schema and throws a human-readable error. | ||
| */ | ||
| const validateAgainstSchemaOrThrow = (validator: Ajv, obj: Record<string, unknown>, inputSchema: Schema, rootName: string) => { | ||
| if (validator.validate(inputSchema, obj)) return; | ||
|
|
||
| const errorMessage = parseAjvError(validator.errors![0], rootName)?.message; | ||
| let bestError = selectBestError(validator.errors!); | ||
|
|
||
| /* | ||
| When the best AJV error comes from a oneOf/anyOf branch (showing only a subset of valid values), | ||
| and the schema has a broader top-level enum for the same property, and the input value is not in | ||
| that enum at all, the error is enhanced to show all valid values instead of just the branch subset. | ||
| */ | ||
| const branchPattern = /\/(oneOf|anyOf)\/\d+\//; | ||
| if (bestError.keyword === 'enum' && branchPattern.test(bestError.schemaPath)) { |
Copilot
AI
Feb 12, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
branchPattern is declared both in selectBestError and again in validateAgainstSchemaOrThrow. Consider extracting it to a single module-level constant (or reusing the one from selectBestError) to avoid future divergence if the pattern needs to change.
When an invalid editor value (e.g., "fileUpload" instead of "fileupload") was used on an array field, the error message only showed a single editor from the first oneOf branch instead of all valid options. Now the error lists all valid array editors when the value is completely outside the allowed set.
Reported here: https://apify.slack.com/archives/C0L33UM7Z/p1770826695378579