adobe / adobe/structured-data-validator

Feature Request: Add validators for LocalBusiness, Article, Event, FAQPage, and other common types, and child schema validation

Open
#56 0 comments 2 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
15
Forks
3
PR merge metrics
No merged PRs in 30d

Description

## Summary

The library currently returns zero validation errors for several commonly-used schema.org types that Google Rich Results actively supports, including `LocalBusiness`, `Article`, `Event`, `FAQPage`, `HowTo`, `WebSite`, and `WebPage`.

## Reproduction

```javascript
const testData = {
jsonld: {
LocalBusiness: [{
'@type': 'LocalBusiness'
// Missing required fields: name, address, etc.
}]
},
microdata: {},
rdfa: {},
errors: []
};

const issues = await validator.validate(testData);
console.log(issues.length); // 0 — No errors reported
```

## Expected Behavior

The validator should report missing required fields per [Google's structured data guidelines](https://developers.google.com/search/docs/appearance/structured-data).

For example, `LocalBusiness` should validate:

**Required:**
- `name`
- `address` (PostalAddress object)

**Recommended:**
- `telephone`
- `openingHoursSpecification`
- `geo` (GeoCoordinates)
- `image`
- `priceRange`

## Schema Types Affected

| Type | Google Rich Results Page |
|------|--------------------------|
| LocalBusiness | [docs](https://developers.google.com/search/docs/appearance/structured-data/local-business) |
| Article | [docs](https://developers.google.com/search/docs/appearance/structured-data/article) |
| Event | [docs](https://developers.google.com/search/docs/appearance/structured-data/event) |
| FAQPage | [docs](https://developers.google.com/search/docs/appearance/structured-data/faqpage) |
| HowTo | [docs](https://developers.google.com/search/docs/appearance/structured-data/how-to) |
| WebSite | [docs](https://developers.google.com/search/docs/appearance/structured-data/sitelinks-searchbox) |
| WebPage | Part of various structured data types |

## Impact

Users may believe their structured data is valid when critical fields are missing, leading to:
- Failed rich result eligibility in Google Search
- Poor SEO outcomes
- Confusion when Google Search Console reports errors that this validator missed

## Proposed Solution

Add validator classes for the missing types following the existing pattern. Example:

```javascript
// src/types/LocalBusiness.js
import BaseValidator from './base.js';

export default class LocalBusinessValidator extends BaseValidator {
getConditions() {
return [
this.required('name'),
this.required('address', 'object'),
this.recommended('telephone'),
this.recommended('openingHoursSpecification', 'array'),
this.recommended('geo', 'object'),
this.recommended('image', 'url'),
this.recommended('priceRange'),
].map((c) => c.bind(this));
}
}
```

Then register in `src/Validator.js`:

```javascript
this.registeredHandlers = {
// ... existing handlers
LocalBusiness: [() => import('./types/LocalBusiness.js')],
};
```

### Problem: Subtypes are not validated

Currently, if a schema uses a subtype like `Restaurant`, `NewsArticle`, or `MusicEvent`, the validator returns **zero errors** even when required fields are missing.

**Example:**
const data = {
jsonld: {
Restaurant: [{
'@type': 'Restaurant'
// Missing name, address - but no errors reported!
}]
},
microdata: {},
rdfa: {},
errors: []
};

const issues = await validator.validate(data);
console.log(issues.length); // 0 — No validation!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.