Skip to content

Add validation for invalid schema.org types #59

@gsriram24

Description

@gsriram24

Description

Current Behavior

When a structured data object uses a @type that is not a valid schema.org type (e.g., "@type": "BananaPhone"), the validator silently skips it without returning any error or warning.

Currently:

  1. If the type has no registered handler in validator.js, it logs a debug warning and returns an empty array
  2. The schemaOrg.js global handler only validates properties, not the type itself
  3. Users receive no feedback that their type is invalid

Expected Behavior

The validator should return a warning when a @type is not a valid schema.org type, helping users catch typos or made-up types early.

Proposed Implementation

  1. Modify schemaOrg.js to check if the type exists in the loaded schema.org specification before validating properties:

    const schema = await this.#loadSchema();
    const typeId = this.#stripSchema(this.type);
    
    if (!schema[typeId]) {
      issues.push({
        issueMessage: `Type "${typeId}" is not a valid schema.org type`,
        severity: 'WARNING',
        path: this.path,
        errorType: 'schemaOrg',
        fieldName: '@type',
      });
      return issues;
    }
  2. Modify validator.js to ensure the schemaOrg handler runs even for types without a registered handler (so completely unknown types are also validated)

Acceptance Criteria

  • Validator returns a warning for types not found in schema.org specification
  • Warning includes the invalid type name and path
  • Valid schema.org types (even without specific handlers) do not trigger warnings
  • Add test cases for invalid type validation

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions