go-fed / activity

ActivityStreams & ActivityPub in golang, oh my!
BSD 3-Clause "New" or "Revised" License
702 stars 111 forks source link

Propagate default alias to properties #119

Closed cjslep closed 4 years ago

cjslep commented 4 years ago

As discussed in https://github.com/go-fed/activity/pull/118 and the associated links and threads, properties are not being serialized properly when voabularies in the context have a default JSON-LD alias.

Note that this won't be handled by Mastodon (and SocialHome?) right now, so may need to file issues against those projects.

cjslep commented 4 years ago

I've identified root cause: the generated Serialization function half-asses a solution. Firstly, property names never have the chance to be aliased. Secondly, the type name is being properly aliased... but then overwritten by the actual type property. The type property, since it is a JSON-LD special property, will need a bit of extra processing to preserve other type names that may be manually aliased, and preserve its own type name with the correct alias (eliminating a dupe or non-aliased dupe).

The solution I have in mind will still require people wanting to add multiple types, to handle that aliasing correctly on their own. Solving that will be very difficult, there isn't any immediate uses cases, and I don't want to spin on it.

cjslep commented 4 years ago

I got the stuff to generate and serialize with proper aliasing:

{
  "@context": [
    "https://www.w3.org/ns/activitystreams",
    {
      "widsv": "https://w3id.org/security/v1"
    }
  ],
  "type": "Person",
  "widsv:publicKey": {
    "type": "widsv:PublicKey",
    "widsv:publicKeyPem": "test PEM value"
  }
}

Will push the code shortly.

cjslep commented 4 years ago

Here is the fix in astool: b5a6786f9edfb57f58275a20daf7b1f97ad00488

Here is the new generated code: e084b904b19552d8a165f5c79b2d295afd1fc8a1