iaincollins / structured-data-testing-tool

A library and command line tool to help inspect and test for Structured Data.
https://www.npmjs.com/package/structured-data-testing-tool
ISC License
64 stars 14 forks source link

Support referencing schemas using @id #21

Open iaincollins opened 4 years ago

iaincollins commented 4 years ago

Summary of proposed feature Allow @id to be used to reference one schema from another schema on the same page.

Purpose of proposed feature This format exists to publishers to avoid repeating the same information.

It is valid syntax used by some publishers (although it is not especially common).

For a more detailed explanation, see: https://webmasters.stackexchange.com/questions/98569/what-is-the-use-of-id-in-json-ld-syntax

Detail of the proposed feature

e.g. markup for a news article might look like:

{
  "@context": "http://schema.org",
  "@type": "NewsArticle",
  "publisher": {
    "@id": "https://www.nytimes.com/#publisher"
 }

And it might reference an organisation object on a page which looks like like this:

{
  "@context": "http://schema.org",
  "@type": "NewsMediaOrganization",
  "@id": "https://www.nytimes.com/#publisher",
  "name": "The New York Times",
  "logo": {
    "@context": "http://schema.org",
    "@type": "ImageObject",
    "url": "https://static01.nyt.com/images/misc/NYT_logo_rss_250x40.png",
    "height": 40,
    "width": 250
  },
}

For a real world, example, see: https://www.nytimes.com/2020/04/14/us/coronavirus-updates-usa.html

Potential problems

This could be done by either making the test logic more sophisticated or (perhaps more easily?) by 'unflattening' the data structures after parsing the page, which would mean the test logic doesn't need to change, and that could be better as it would be much simpler logic and avoid special case handling for this feature in an already complicated section of code.

Describe any alternatives you've considered

None

Additional context

None