-
Notifications
You must be signed in to change notification settings - Fork 1
feat: Add validation for invalid schema.org types #60
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: main
Are you sure you want to change the base?
Conversation
- Add validateType() method to schemaOrg.js to check if type exists in schema.org - Modify validator.js to always run global handlers even for unknown types - Return warning when @type is not a valid schema.org type - Add fieldName to validation errors for consistency - Add test case for invalid type detection - Exclude test files with Google-specific extensions from schema.org validation
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.
Regarding startOffset-input, there are multiple aspects here:
- Generally the
-inputand-outputsuffixes are allowed as part of the schema.org spec under https://schema.org/docs/actions.html#part-4. - IIUC this however only applies to specific attributes, e.g. part of the
schema:PropertyValueSpecificationdomain. startOffsetis not part of that.
For consistency I recommend to globally allow -input and -output suffixes for all schema.org properties. I don't want to discourage users from using startOffset-input.
Everything else looks great, thank you 💯
Per the schema.org Actions specification, properties can have -input and -output suffixes to indicate input/output constraints. This change strips these suffixes before validating the base property name. See: https://schema.org/docs/actions.html#part-4 Co-authored-by: Cursor <cursoragent@cursor.com>
|
@herzog31 , addressed this comment and added support for |
herzog31
left a comment
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.
@gsriram24 Could you please update this PR against main and change fieldName to fieldNames (according to #57)? Then PR looks good and is ready to be merged 👍
Description
When a structured data object uses a
@typethat is not a valid schema.org type (e.g.,"@type": "BananaPhone"), the validator now returns a warning instead of silently skipping it.Changes made:
validateType()method toschemaOrg.jsto check if a type exists in the schema.org specificationvalidator.jsto always run global handlers (like schemaOrg) even when no type-specific handler is registered@typeis not a valid schema.org type withfieldName: '@type'fieldNameto property validation errors for consistencyBananaPhoneas an examplestartOffset-input) from schema.org validation testsRelated Issue
Closes #59
Motivation and Context
Previously, when a user made a typo in their schema type (e.g.,
Prodcutinstead ofProduct) or used a completely made-up type, the validator would silently skip validation without any feedback. This made it difficult for users to catch errors in their structured data. With this change, users now receive a clear warning message identifying invalid types.How Has This Been Tested?
schema:Product,https://schema.org/Product✅Screenshots (if appropriate):
N/A
Types of changes
Checklist: