feat: add fieldName property to validation error objects#57
Merged
herzog31 merged 4 commits intoadobe:mainfrom Feb 2, 2026
Merged
feat: add fieldName property to validation error objects#57herzog31 merged 4 commits intoadobe:mainfrom
herzog31 merged 4 commits intoadobe:mainfrom
Conversation
- Add fieldName to required(), recommended(), or() in base.js - Add fieldName to custom validators (BreadcrumbList, DefinedRegion, MerchantReturnPolicy, Product, ProductMerchant, Rating, schemaOrg) - Add tests for fieldName in base.test.js Fixes adobe#55
noruiz
reviewed
Jan 28, 2026
herzog31
reviewed
Jan 29, 2026
Member
herzog31
left a comment
There was a problem hiding this comment.
Thanks for your contribution 💯
Could you please also ensure that the changes related to fieldName made to
BreadcrumbList.jsDefinedRegion.jsMerchantReturnPolicy.jsProduct.jsProductMerchant.jsRating.jsschemaOrg.js
are also covered by unit tests? Extending existing tests is fine.
Replace fieldName (singular) with fieldNames (array) for consistency. All validation errors now return fieldNames as an array, eliminating redundancy and providing a cleaner API. - Single field errors: fieldNames: ['price'] - Multi-field errors: fieldNames: ['aggregateRating', 'offers', 'review'] Access primary field with error.fieldNames[0] or iterate over all fields. Co-authored-by: Cursor <cursoragent@cursor.com>
Add fieldNames coverage to unit tests for: - BreadcrumbList.test.js - DefinedRegion.test.js - MerchantReturnPolicy.test.js - Product.test.js - ProductMerchant.test.js - Rating.test.js - schemaOrg.test.js This ensures the fieldNames property is verified in each validator's test file, not just in base.test.js. Co-authored-by: Cursor <cursoragent@cursor.com>
Contributor
Author
|
@herzog31, updated the test files to assert for |
herzog31
approved these changes
Feb 2, 2026
Member
|
Thanks a lot @gsriram24 for the contribution. |
10 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR adds a
fieldNamesproperty to validation error objects, enabling consumers to programmatically identify which field caused a validation error without parsing theissueMessagestring.Changes:
Core (
src/types/base.js):required()— returnsfieldNames: [name]for missing/invalid type errorsrecommended()— returnsfieldNames: [name]for missing/invalid type warningsor()— returnsfieldNames(all fields) for compound conditionsCustom validators:
BreadcrumbList.js—fieldNamesfor item count and URL validation errorsDefinedRegion.js—fieldNamesfor addressRegion/postalCode conflictMerchantReturnPolicy.js—fieldNamesfor country/link validationProduct.js—fieldNamesfor rating/review/offers and notes count errorsProductMerchant.js—fieldNamesfor GTIN validationRating.js—fieldNamesfor out-of-range rating errorsschemaOrg.js—fieldNamesfor unsupported property errorsTests:
base.test.jswith 10 new tests coveringfieldNamesbehaviorRelated Issue
Fixes #55
Motivation and Context
Currently, the field name is embedded in the
issueMessagestring:Consumers must use regex to extract the field name, which is fragile and breaks if message wording changes. This PR adds a dedicated
fieldNameproperty for direct programmatic access, enabling use cases like:How Has This Been Tested?
base.test.jscovering:required()returningfieldNamesfor missing attributesrequired()returningfieldNamesfor invalid typerecommended()returningfieldNamesfor missing/invalid attributesor()returningfieldNamesfor compound conditionsfieldNames(e.g.,offers.price)npm run unit-test # 211 passingScreenshots (if appropriate):
N/A
Types of changes
Checklist: