go-ap / activitypub

ActivityPub vocabulary for Go
MIT License
124 stars 10 forks source link

Should 'context' be '@context'? #11

Closed hacdias closed 1 year ago

hacdias commented 1 year ago

I was considering using this library to encode some ActivityPub data I have on my website. However, I noticed that the Context field gets serialised to context and not @context. Is that on purpose? If so, why? And how could I output it as @context?

ghost commented 1 year ago

I remember running into this issue while working on Gitea federation a few months ago. My solution was to use jsonld.WithContext as you can see here.

hacdias commented 1 year ago

Thanks @Ta180m!

hacdias commented 1 year ago

It would be great to get some feedback from the author though, cc @mariusor. I would like to understand if this is a bug, or on purpose.

ghost commented 1 year ago

Maybe ask about this on the mailing list?

mariusor commented 1 year ago

Hey @hacdias, apologies for the late reply.

So, @ta180m is right on all accounts:

I prefer the mailing list for questions because on github usually nothing happens, and it's more convenient for me to talk over email.

To use the JSON-LD @context, you need to use the mechanism suggested:

body, err := jsonld.WithContext(
    jsonld.IRI(vocab.ActivityBaseURI),
    jsonld.IRI(vocab.SecurityContextURI),
).Marshal(a)

The Context property that you mentioned on the go-ap objects stems from the ActivityStreams vocabulary specification, and has nothing to do with the JSON-LD context, though I can understand the confusion. It should be commented in the source code with the details from the spec itself, which I was hoping that it gives an indication about its purpose.

hacdias commented 1 year ago

@mariusor thanks for the context - no pun intended. I will then close this issue as it is not a bug!