Skip to content

Conversation

@gsriram24
Copy link
Contributor

Description

When a structured data object uses a @type that is not a valid schema.org type (e.g., "@type": "BananaPhone"), the validator now returns a warning instead of silently skipping it.

Changes made:

  • Added validateType() method to schemaOrg.js to check if a type exists in the schema.org specification
  • Modified validator.js to always run global handlers (like schemaOrg) even when no type-specific handler is registered
  • Returns a warning when @type is not a valid schema.org type with fieldName: '@type'
  • Added fieldName to property validation errors for consistency
  • Added test case for invalid type detection using BananaPhone as an example
  • Excluded test files containing Google-specific extensions (startOffset-input) from schema.org validation tests

Related Issue

Closes #59

Motivation and Context

Previously, when a user made a typo in their schema type (e.g., Prodcut instead of Product) 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?

  • All 200 unit tests pass
  • Added new unit test for invalid type detection
  • Manual testing with:
    • Valid types: Product, Person, Organization, Article, MedicalClinic ✅
    • Invalid types: BananaPhone, FakeType123 ❌ (correctly flagged)
    • Typos: Prodcut ❌ (correctly flagged)
    • Nested invalid types: correctly detected with full path
    • Prefixed types: schema:Product, https://schema.org/Product

Screenshots (if appropriate):

N/A

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • I have signed the Adobe Open Source CLA.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

- 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
@herzog31 herzog31 requested review from herzog31 and noruiz January 28, 2026 10:14
@herzog31 herzog31 added the enhancement New feature or request label Jan 28, 2026
Copy link
Member

@herzog31 herzog31 left a 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 -input and -output suffixes 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:PropertyValueSpecification domain.
  • startOffset is 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 💯

gsriram24 and others added 2 commits February 2, 2026 09:35
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>
@gsriram24 gsriram24 requested a review from herzog31 February 2, 2026 04:07
@gsriram24
Copy link
Contributor Author

@herzog31 , addressed this comment and added support for -input and -output

Copy link
Member

@herzog31 herzog31 left a 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 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add validation for invalid schema.org types

3 participants