Skip to content
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

Could not load remote context (http://schema.org/): %Jason.DecodeError... #9

Closed
cheerfulstoic opened this issue Dec 29, 2022 · 5 comments

Comments

@cheerfulstoic
Copy link
Contributor

Hey!

I tried this with a few examples from articles I found online, but I was able to reproduce it with a simple example from the JSON-LD playground, so I'm going to provide that here. Here's what I tried:

"""
{
  "@context": "http://schema.org/",
  "@type": "Person",
  "name": "Jane Doe",
  "jobTitle": "Professor",
  "telephone": "(425) 123-4567",
  "url": "http://www.janedoe.com"
}
"""
|> Jason.decode!()
|> JSON.LD.expand()

I notice that in this example the @context is a string, whereas from your README it's an object. Should I be doing some other operation? I'm pretty new to JSON+LD.... 😅

@cheerfulstoic
Copy link
Contributor Author

I've been looking into this a bit and I found this SE answer:

https://webmasters.stackexchange.com/questions/123409/how-can-http-schema-org-be-used-in-json-lds-context-even-though-its-not-a

It seems like http://schema.org/ used to use HTTP redirection / content negotiation, but it now uses the Link header in the response. So maybe JSON.LD.DocumentLoader.Default.http_get/1 should be updated to reflect that. Maybe also a non-unit test so that the test suite actually tries making the HTTP request to verify?

I can give all of that a go in a bit.

@cheerfulstoic
Copy link
Contributor Author

What I would do, to be clear, is refactor to allow for both redirecting and the Link header, because there might be more that schema.org out there.

Honestly, if those are the only two options, then it might just make sense to mock the HTTP requests for the sake of the tests. Hopefully there isn't a third standard that starts being used 😅

@gkellogg
Copy link

This behavior is, in fact, called for by the API LoadDocumentCallback.

If the retrieved resource's Content-Type is not application/json nor any media type with a +json suffix as defined in [RFC6839], and the response has an HTTP Link Header [RFC8288] using the alternate link relation with type application/ld+json, set url to the associated href relative to the previous url and restart the algorithm from step 2.

If the retrieved resource's Content-Type is application/json or any media type with a +json suffix as defined in [RFC6839] except application/ld+json, and the response has an HTTP Link Header [RFC8288] using the http://www.w3.org/ns/json-ld#context link relation, set contextUrl to the associated href.

If multiple HTTP Link Headers using the http://www.w3.org/ns/json-ld#context link relation are found, the promise is rejected with a JsonLdError whose code is set to multiple context link headers and processing is terminated.

@marcelotto
Copy link
Member

@cheerfulstoic Your fix was just released with v0.3.7. Again, sorry, things have taken so long. I've had a bit of a whirlwind recently.

@cheerfulstoic
Copy link
Contributor Author

No worries, happy that it was helpful! 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants