From b078413f1bff0bfef249c8630d9b9ac7684568a4 Mon Sep 17 00:00:00 2001 From: Marius Orcsik Date: Tue, 12 Sep 2017 19:21:23 +0200 Subject: [PATCH] Remove omitempty from jsonld marshalling options, as it apparently doesn't take it into account --- activitypub/activity.go | 18 +++++----- activitypub/actors.go | 28 ++++++++-------- activitypub/collections.go | 30 ++++++++--------- activitypub/object.go | 68 +++++++++++++++++++------------------- 4 files changed, 72 insertions(+), 72 deletions(-) diff --git a/activitypub/activity.go b/activitypub/activity.go index 5d5feee..7c86c4b 100644 --- a/activitypub/activity.go +++ b/activitypub/activity.go @@ -75,7 +75,7 @@ type Activity struct { // For instance, in the activity "John added a movie to his wishlist", // the object of the activity is the movie added. // When used within a Relationship describes the entity to which the subject is related. - Object ObjectOrLink `jsonld:"object,omitempty"` + Object ObjectOrLink `jsonld:"object"` } // Indicates that the actor accepts the object. The target property can be used in certain circumstances to indicate @@ -193,12 +193,12 @@ type Question struct { *IntransitiveActivity // Identifies an exclusive option for a Question. Use of oneOf implies that the Question // can have only a single answer. To indicate that a Question can have multiple answers, use anyOf. - OneOf ObjectOrLink `jsonld:"oneOf,omitempty"` + OneOf ObjectOrLink `jsonld:"oneOf"` // Identifies an inclusive option for a Question. Use of anyOf implies that the Question can have multiple answers. // To indicate that a Question can have only one answer, use oneOf. - AnyOf ObjectOrLink `jsonld:"anyOf,omitempty"` + AnyOf ObjectOrLink `jsonld:"anyOf"` // Indicates that a question has been closed, and answers are no longer accepted. - Closed bool `jsonld:"closed,omitempty"` + Closed bool `jsonld:"closed"` } // Instances of IntransitiveActivity are a subtype of Activity representing intransitive actions. @@ -207,22 +207,22 @@ type IntransitiveActivity struct { *BaseObject // Describes one or more entities that either performed or are expected to perform the activity. // Any single activity can have multiple actors. The actor may be specified using an indirect Link. - Actor Actor `jsonld:"actor,omitempty"` + Actor Actor `jsonld:"actor"` // Describes the indirect object, or target, of the activity. // The precise meaning of the target is largely dependent on the type of action being described // but will often be the object of the English preposition "to". // For instance, in the activity "John added a movie to his wishlist", // the target of the activity is John's wishlist. An activity can have more than one target. - Target ObjectOrLink `jsonld:"actor,omitempty"` + Target ObjectOrLink `jsonld:"actor"` // Describes the result of the activity. For instance, if a particular action results in the creation // of a new resource, the result property can be used to describe that new resource. - Result ObjectOrLink `jsonld:"actor,omitempty"` + Result ObjectOrLink `jsonld:"actor"` // Describes an indirect object of the activity from which the activity is directed. // The precise meaning of the origin is the object of the English preposition "from". // For instance, in the activity "John moved an item to List B from List A", the origin of the activity is "List A". - Origin ObjectOrLink `jsonld:"origin,omitempty"` + Origin ObjectOrLink `jsonld:"origin"` // Identifies one or more objects used (or to be used) in the completion of an Activity. - Instrument ObjectOrLink `jsonld:"instrument,omitempty"` + Instrument ObjectOrLink `jsonld:"instrument"` Source Source } diff --git a/activitypub/actors.go b/activitypub/actors.go index b51ecb6..0f904b3 100644 --- a/activitypub/actors.go +++ b/activitypub/actors.go @@ -19,25 +19,25 @@ var validActorTypes = [...]string{ type Endpoints struct { // Upload endpoint URI for this user for binary data. - UploadMedia ObjectOrLink `jsonld:"uploadMedia,omitempty"` + UploadMedia ObjectOrLink `jsonld:"uploadMedia"` // Endpoint URI so this actor's clients may access remote ActivityStreams objects which require authentication // to access. To use this endpoint, the client posts an x-www-form-urlencoded id parameter with the value being // the id of the requested ActivityStreams object. - OauthAuthorizationEndpoint ObjectOrLink `jsonld:"oauthAuthorizationEndpoint,omitempty"` + OauthAuthorizationEndpoint ObjectOrLink `jsonld:"oauthAuthorizationEndpoint"` // If OAuth 2.0 bearer tokens [RFC6749] [RFC6750] are being used for authenticating client to server interactions, // this endpoint specifies a URI at which a browser-authenticated user may obtain a new authorization grant. - OauthTokenEndpoint ObjectOrLink `jsonld:"oauthTokenEndpoint,omitempty"` + OauthTokenEndpoint ObjectOrLink `jsonld:"oauthTokenEndpoint"` // If OAuth 2.0 bearer tokens [RFC6749] [RFC6750] are being used for authenticating client to server interactions, // this endpoint specifies a URI at which a client may acquire an access token. - ProvideClientKey ObjectOrLink `jsonld:"provideClientKey,omitempty"` + ProvideClientKey ObjectOrLink `jsonld:"provideClientKey"` // If Linked Data Signatures and HTTP Signatures are being used for authentication and authorization, // this endpoint specifies a URI at which browser-authenticated users may authorize a client's public // key for client to server interactions. - SignClientKey ObjectOrLink `jsonld:"signClientKey,omitempty"` + SignClientKey ObjectOrLink `jsonld:"signClientKey"` // If Linked Data Signatures and HTTP Signatures are being used for authentication and authorization, // this endpoint specifies a URI at which a client key may be signed by the actor's key for a time window to // act on behalf of the actor in interacting with foreign servers. - SharedInbox ObjectOrLink `jsonld:"sharedInbox,omitempty"` + SharedInbox ObjectOrLink `jsonld:"sharedInbox"` } // Actor types are Object types that are capable of performing activities. @@ -45,28 +45,28 @@ type Actor struct { *BaseObject // A reference to an [ActivityStreams] OrderedCollection comprised of all the messages received by the actor; // see 5.2 Inbox. - Inbox InboxStream `jsonld:"inbox,omitempty"` + Inbox InboxStream `jsonld:"inbox"` // An [ActivityStreams] OrderedCollection comprised of all the messages produced by the actor; // see 5.1 Outbox. - Outbox OutboxStream `jsonld:"outbox,omitempty"` + Outbox OutboxStream `jsonld:"outbox"` // A link to an [ActivityStreams] collection of the actors that this actor is following; // see 5.4 Following Collection - Following FollowingCollection `jsonld:"following,omitempty"` + Following FollowingCollection `jsonld:"following"` // A link to an [ActivityStreams] collection of the actors that follow this actor; // see 5.3 Followers Collection. - Followers FollowersCollection `jsonld:"followers,omitempty"` + Followers FollowersCollection `jsonld:"followers"` // A link to an [ActivityStreams] collection of the actors that follow this actor; // see 5.3 Followers Collection. - Liked LikedCollection `jsonld:"liked,omitempty"` + Liked LikedCollection `jsonld:"liked"` // A short username which may be used to refer to the actor, with no uniqueness guarantees. - PreferredUsername NaturalLanguageValue `jsonld:"preferredUsername,omitempty"` + PreferredUsername NaturalLanguageValue `jsonld:"preferredUsername"` // A json object which maps additional (typically server/domain-wide) endpoints which may be useful either // for this actor or someone referencing this actor. // This mapping may be nested inside the actor document as the value or may be a link // to a JSON-LD document with these properties. - Endpoints Endpoints `jsonld:"endpoints,omitempty"` + Endpoints Endpoints `jsonld:"endpoints"` // A list of supplementary Collections which may be of interest. - Streams []Collection `jsonld:"streams,omitempty"` + Streams []Collection `jsonld:"streams"` } // Describes a software application. diff --git a/activitypub/collections.go b/activitypub/collections.go index 8b2b206..0c3b951 100644 --- a/activitypub/collections.go +++ b/activitypub/collections.go @@ -4,18 +4,18 @@ type Collection struct { *BaseObject // A non-negative integer specifying the total number of objects contained by the logical view of the collection. // This number might not reflect the actual number of items serialized within the Collection object instance. - TotalItems uint `jsonld:"totalItems,omitempty"` + TotalItems uint `jsonld:"totalItems"` // Identifies the items contained in a collection. The items might be ordered or unordered. - Items ItemCollection `jsonld:"items,omitempty"` + Items ItemCollection `jsonld:"items"` } type OrderedCollection struct { *BaseObject // A non-negative integer specifying the total number of objects contained by the logical view of the collection. // This number might not reflect the actual number of items serialized within the Collection object instance. - TotalItems uint `jsonld:"totalItems,omitempty"` + TotalItems uint `jsonld:"totalItems"` // Identifies the items contained in a collection. The items might be ordered or unordered. - Items ItemCollection `jsonld:"items,omitempty"` + Items ItemCollection `jsonld:"items"` } type Page ObjectOrLink @@ -23,31 +23,31 @@ type Page ObjectOrLink type CollectionPage struct { PartOf *Collection // In a paged Collection, indicates the page that contains the most recently updated member items. - Current Page `jsonld:"current,omitempty"` + Current Page `jsonld:"current"` // In a paged Collection, indicates the furthest preceeding page of items in the collection. - First Page `jsonld:"first,omitempty"` + First Page `jsonld:"first"` // In a paged Collection, indicates the furthest proceeding page of the collection. - Last Page `jsonld:"last,omitempty"` + Last Page `jsonld:"last"` // In a paged Collection, indicates the next page of items. - Next Page `jsonld:"next,omitempty"` + Next Page `jsonld:"next"` // In a paged Collection, identifies the previous page of items. - Prev Page `jsonld:"prev,omitempty"` + Prev Page `jsonld:"prev"` } type OrderedCollectionPage struct { PartOf *OrderedCollection // In a paged Collection, indicates the page that contains the most recently updated member items. - Current Page `jsonld:"current,omitempty"` + Current Page `jsonld:"current"` // In a paged Collection, indicates the furthest preceeding page of items in the collection. - First Page `jsonld:"first,omitempty"` + First Page `jsonld:"first"` // In a paged Collection, indicates the furthest proceeding page of the collection. - Last Page `jsonld:"last,omitempty"` + Last Page `jsonld:"last"` // In a paged Collection, indicates the next page of items. - Next Page `jsonld:"next,omitempty"` + Next Page `jsonld:"next"` // In a paged Collection, identifies the previous page of items. - Prev Page `jsonld:"prev,omitempty"` + Prev Page `jsonld:"prev"` // A non-negative integer value identifying the relative position within the logical view of a strictly ordered collection. - StartIndex uint `jsonld:"startIndex,omitempty"` + StartIndex uint `jsonld:"startIndex"` } diff --git a/activitypub/object.go b/activitypub/object.go index 933db33..015b08b 100644 --- a/activitypub/object.go +++ b/activitypub/object.go @@ -66,86 +66,86 @@ type NaturalLanguageValue map[LangRef]string // including other Core types such as Activity, IntransitiveActivity, Collection and OrderedCollection. type BaseObject struct { // Provides the globally unique identifier for an Object or Link. - Id ObjectId `jsonld:"id,omitempty"` + Id ObjectId `jsonld:"id"` // Identifies the Object or Link type. Multiple values may be specified. - Type string `jsonld:"type,omitempty"` + Type string `jsonld:"type"` // A simple, human-readable, plain-text name for the object. // HTML markup MUST NOT be included. The name MAY be expressed using multiple language-tagged values. - Name NaturalLanguageValue `jsonld:"name,omitempty"` + Name NaturalLanguageValue `jsonld:"name"` } type Object struct { *BaseObject // Identifies a resource attached or related to an object that potentially requires special handling. // The intent is to provide a model that is at least semantically similar to attachments in email. - Attachment ObjectOrLink `jsonld:"attachment,omitempty"` + Attachment ObjectOrLink `jsonld:"attachment"` // Identifies one or more entities to which this object is attributed. The attributed entities might not be Actors. // For instance, an object might be attributed to the completion of another activity. - AttributedTo ObjectOrLink `jsonld:"attributedTo,omitempty"` + AttributedTo ObjectOrLink `jsonld:"attributedTo"` // Identifies one or more entities that represent the total population of entities // for which the object can considered to be relevant. - Audience ObjectOrLink `jsonld:"audience,omitempty"` + Audience ObjectOrLink `jsonld:"audience"` // The content or textual representation of the Object encoded as a JSON string. // By default, the value of content is HTML. // The mediaType property can be used in the object to indicate a different content type. // (The content MAY be expressed using multiple language-tagged values.) - Content NaturalLanguageValue `jsonld:"content,omitempty"` + Content NaturalLanguageValue `jsonld:"content"` // Identifies the context within which the object exists or an activity was performed. // The notion of "context" used is intentionally vague. // The intended function is to serve as a means of grouping objects and activities that share a // common originating context or purpose. An example could be all activities relating to a common project or event. - Context ObjectOrLink `jsonld:"context,omitempty"` + Context ObjectOrLink `jsonld:"context"` // The date and time describing the actual or expected ending time of the object. // When used with an Activity object, for instance, the endTime property specifies the moment // the activity concluded or is expected to conclude. - EndTime time.Time `jsonld:"endTime,omitempty"` + EndTime time.Time `jsonld:"endTime"` // Identifies the entity (e.g. an application) that generated the object. - Generator ObjectOrLink `jsonld:"generator,omitempty"` + Generator ObjectOrLink `jsonld:"generator"` // Indicates an entity that describes an icon for this object. // The image should have an aspect ratio of one (horizontal) to one (vertical) // and should be suitable for presentation at a small size. - Icon ImageOrLink `jsonld:"icon,omitempty"` + Icon ImageOrLink `jsonld:"icon"` // Indicates an entity that describes an image for this object. // Unlike the icon property, there are no aspect ratio or display size limitations assumed. - Image ImageOrLink `jsonld:"image,omitempty"` + Image ImageOrLink `jsonld:"image"` // Indicates one or more entities for which this object is considered a response. - InReplyTo ObjectOrLink `jsonld:"inReplyTo,omitempty"` + InReplyTo ObjectOrLink `jsonld:"inReplyTo"` // Indicates one or more physical or logical locations associated with the object. - Location ObjectOrLink `jsonld:"location,omitempty"` + Location ObjectOrLink `jsonld:"location"` // Identifies an entity that provides a preview of this object. - Preview ObjectOrLink `jsonld:"preview,omitempty"` + Preview ObjectOrLink `jsonld:"preview"` // The date and time at which the object was published - Published time.Time `jsonld:"published,omitempty"` + Published time.Time `jsonld:"published"` // Identifies a Collection containing objects considered to be responses to this object. - Replies Collection `jsonld:"replies,omitempty"` + Replies Collection `jsonld:"replies"` // The date and time describing the actual or expected starting time of the object. // When used with an Activity object, for instance, the startTime property specifies // the moment the activity began or is scheduled to begin. - StartTime time.Time `jsonld:"startTime,omitempty"` + StartTime time.Time `jsonld:"startTime"` // A natural language summarization of the object encoded as HTML. // *Multiple language tagged summaries may be provided.) - Summary NaturalLanguageValue `jsonld:"summary,omitempty"` + Summary NaturalLanguageValue `jsonld:"summary"` // One or more "tags" that have been associated with an objects. A tag can be any kind of Object. // The key difference between attachment and tag is that the former implies association by inclusion, // while the latter implies associated by reference. - Tag ObjectOrLink `jsonld:"tag,omitempty"` + Tag ObjectOrLink `jsonld:"tag"` // The date and time at which the object was updated - Updated time.Time `jsonld:"updated,omitempty"` + Updated time.Time `jsonld:"updated"` // Identifies one or more links to representations of the object - Url LinkOrUri `jsonld:"url,omitempty"` + Url LinkOrUri `jsonld:"url"` // Identifies an entity considered to be part of the public primary audience of an Object - To ObjectOrLink `jsonld:"to,omitempty"` + To ObjectOrLink `jsonld:"to"` // Identifies an Object that is part of the private primary audience of this Object. - Bto ObjectOrLink `jsonld:"bto,omitempty"` + Bto ObjectOrLink `jsonld:"bto"` // Identifies an Object that is part of the public secondary audience of this Object. - Cc ObjectOrLink `jsonld:"cc,omitempty"` + Cc ObjectOrLink `jsonld:"cc"` // Identifies one or more Objects that are part of the private secondary audience of this Object. - Bcc ObjectOrLink `jsonld:"bcc,omitempty"` + Bcc ObjectOrLink `jsonld:"bcc"` // When the object describes a time-bound resource, such as an audio or video, a meeting, etc, // the duration property indicates the object's approximate duration. // The value must be expressed as an xsd:duration as defined by [ xmlschema11-2], // section 3.3.6 (e.g. a period of 5 seconds is represented as "PT5S"). - Duration time.Duration `jsonld:"duration,omitempty"` + Duration time.Duration `jsonld:"duration"` } // A Link is an indirect, qualified reference to a resource identified by a URL. @@ -160,22 +160,22 @@ type Link struct { // [RFC5988](https://tools.ietf.org/html/rfc5988) "link relation" definitions. // In the [HTML5], any string not containing the "space" U+0020, "tab" (U+0009), "LF" (U+000A), // "FF" (U+000C), "CR" (U+000D) or "," (U+002C) characters can be used as a valid link relation. - Rel *Link `jsonld:"rel,omitempty"` + Rel *Link `jsonld:"rel"` // When used on a Link, identifies the MIME media type of the referenced resource. // When used on an Object, identifies the MIME media type of the value of the content property. // If not specified, the content property is assumed to contain text/html content. - MediaType MimeType `jsonld:"mediaType,omitempty"` + MediaType MimeType `jsonld:"mediaType"` // On a Link, specifies a hint as to the rendering height in device-independent pixels of the linked resource. - Height uint `jsonld:"height,omitempty"` + Height uint `jsonld:"height"` // On a Link, specifies a hint as to the rendering width in device-independent pixels of the linked resource. - Width uint `jsonld:"width,omitempty"` + Width uint `jsonld:"width"` // Identifies an entity that provides a preview of this object. - Preview ObjectOrLink `jsonld:"preview,omitempty"` + Preview ObjectOrLink `jsonld:"preview"` // The target resource pointed to by a Link. - Href URI `jsonld:"href,omitempty"` + Href URI `jsonld:"href"` // Hints as to the language used by the target resource. // Value must be a [BCP47](https://tools.ietf.org/html/bcp47) Language-Tag. - HrefLang LangRef `jsonld:"hrefLang,omitempty"` + HrefLang LangRef `jsonld:"hrefLang"` } type ContentType string