Commit Graph

16 Commits

Author SHA1 Message Date
Aren Patel cf83b97b3d Public Marshal API Simplification (#90)
* Used to have 6 functions: MarshalOnePayload, MarshalOnePayloadWithoutIncluded, MarshalOne, MarshalManyPayload, MarshalManyPayloadWithoutIncluded, MarshalMany - now there are only 3: MarshalPayload, MarshalPayloadWithoutIncluded, Marshal. This simplifies the public API; will be easier to explain and document while still providing the existing support for struct ptrs (&Blog{}) and slices of struct ptrs ([]*Blog{}).

* Correcting all code occurrences leftover.

* Updating README to reflect Marshal API changes.

* Omit the mention of One vs Many
2017-06-28 17:30:09 -07:00
Stratos Neiros ebb7923313 Add omitempty to Node.ID (#89)
This commit adds omitempty to the field ID of type Node. This is needed
when constructing an entity client-side and sending it to the server for
creation. Without omitempty, the constructed entity will contain an
empty "id": "", which is not sensible to transmit.

This change addresses #83.
2017-05-23 20:17:04 -07:00
Aren Patel 0a2decba43 Make the Meta test also check for the value of the detail key. Moving all testing models to their own file. Updated the readme to include a deeply nested, varying typed meta example. Convert the map[string]interface to a Meta in the tests. Make the Meta field of a Link of type Meta rather than a map[string]inteface{}. Use the headerAccept constant defined for the example app. Commenting the new Metable interface and moving the Meta type beside it. Example app updated to use jsonapi.Links and jsonapi.Meta types rather than the underlying map[string]interface{}. 2017-02-16 20:28:09 -08:00
Samantha Belkin 776433d17d Add support for 'meta' (#72)
* add Meta field in node structs and Metable/RelationshipMetable interfaces

* update response marshalling to add Meta

* update tests for presence of Meta

* add Metable and RelationshipMetable interfaces to example

* update README to include Meta details
2017-02-16 17:40:50 -08:00
Kyle Truscott 46a5b96356 Add support for 'links' via optional interfaces (#57)
* Implement `links` via optional interfaces

* Updating example app to include links

* Update readme with links information

* Exclude a slice relationship only if the slice is empty AND there are no defined links

* Remove `Link` in favor of vanilla `map[string]interface{}`. More flexible for different allowed links spec implementations.

* Update app.go with correct Links methods

* Use LinksObject and LinkObject types along with type assertion to provide errors when marshaling an invalid links JSON API object.

* Renamed LinksObject Links and LinkObject Link

* Added back the relationship link post merge.

* Renamed the JSON* Linkable functions JSONAPI* such that when a library user implements the interface it is clear the functions are used for JSON API as opposed to JSON

* Example cleanup.

* Refactor the example to use constants from jsonapi and http.
2017-01-20 17:55:59 -08:00
Aren Patel 2cb19b89ed Skimata's null relationships + fixes (#62)
* Add support to nullify relationship; http://jsonapi.org/format/#document-resource-object-linkage

* Fixed: [null] is not valid as an empty relationship.

* add support for 'omitempty' on relationships; default behavior of marshalling empty/nil relations (i.e. w/o 'omitempty' tag) marshals with null data relation

* cleanup whitespace

* Added go 1.7 to test versions; fixed the marshaling of empty relations to return an empty array rather than a null/nil. Added a more robust test case for the marshaling of non omitted relations.

* Cleanup.

* Added a comment to UnmarshalMany

* Document the ‘omitempty’ annotation on a relation.

* Add common JSON API values as exported jsonapi pkg constants.
2017-01-20 16:13:04 -08:00
Aren Patel a1fa2c84a0 Feature/marshal many interface (#42)
* add support for direct use of slice of struct pointers for MarshalMany

* Added a test to ensure that whether MarshalManyPayload is called with a []interface{} or []*Struct it will produce the same desired result.

* Added a test to show how the new error type may be returned.

* Ensure the outside accessible Errs have comments.

* Page char width cleanup. Addressed warnings about duplicated "client-id" definition; using the const.
2016-09-12 22:12:42 -07:00
Luke Young 57819f3b34 Follow Golang naming specifications 2016-07-05 20:32:15 -05:00
Sam Woodard 10e0987b5d start supporting client ids 2015-09-10 15:55:51 -07:00
Sam Woodard adefc0a600 no longer used 2015-07-12 13:15:02 -07:00
Sam Woodard 0becfab81d remove 'JsonApi' everywhere, since we're already in a pkg 2015-07-10 09:07:12 -07:00
Sam Woodard 8de6c952ef test request relationships, nested relationships 2015-07-08 09:35:20 -07:00
Sam Woodard 81bf23f93f support marshalling a list of models 2015-07-07 09:52:38 -07:00
Sam Woodard 0525400acb fix relationships--add data--to comply w spec 2015-07-06 17:04:26 -07:00
Sam Woodard 68210ff3ec rename struct, add test for relationships 2015-07-06 11:57:20 -07:00
Sam Woodard f8d5fbba3d rename files, only initialize included if there are relationships 2015-07-06 09:24:35 -07:00