Commit Graph

161 Commits

Author SHA1 Message Date
Jason McCallister c036316c9d Add tests for mismatching accept headers 2017-10-23 22:41:44 -04:00
Aren Patel a06052dd83
Run gofmt -s to simplifiy. 2017-09-13 12:59:59 -07:00
Aren Patel 8d89a9020f
Fix comment. 2017-09-13 12:56:47 -07:00
Aren Patel 2ce5c379b0
Address go lint comments for the examples. 2017-09-13 12:56:01 -07:00
Aren Patel 5e0c586099
Corrected spelling mistakes. 2017-09-13 12:52:31 -07:00
Aren Patel 3b01bb5fe6
Added go report card. 2017-09-13 12:49:52 -07:00
Aren Patel 3e6ead0f9d
Test against 1.9 2017-09-05 11:11:09 -04:00
Aren Patel c045c87aa1
Ignore Gogland files. 2017-08-01 11:45:13 -07:00
Aren Patel 46d3ced043 Added support for implementing the Linkable and Metable interface on collections (slices) being Marshalled. (#94) 2017-07-07 17:58:51 -07:00
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
Angelos Panagiotopoulos af3dab1a94 Update documentation for responding with proper JSON API headers (#84)
* Update documentation for responding with proper JSONAPI headers

* Fixed examples and commented code for sending proper response headers
2017-04-05 11:19:51 -07:00
Anthony Dodd bce7629682 Use subtests (can only test against go >= 1.7 now). (#63) 2017-02-17 15:11:39 -08:00
Aren Patel 2b01775d0f Merge branch 'feature/meta' 2017-02-16 20:33:20 -08:00
Aren Patel 57008357f7 Feature/meta (#81)
* Added back the Metable implementation for our example models.

* Examples updated to use jsonapi.Links and jsonapi.Meta types rather than the underlying map[string]interface{}

* Commenting the Metable interface and moving the Meta type beside it.

* Use the headerAccept constant defined for the example app.

* Make the Meta field of a Link of type Meta rather than a map[string]inteface{}

* Convert the map[string]interface to a Meta in the test.

* Updated the readme to include a deeply nested, varying typed meta example.

* Moving all testing models to their own file; preparing to write a more complete Meta test.

* Make the Meta test also check for the value of the detail key. Moved more test support models.
2017-02-16 20:31:19 -08: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
Aren Patel 9babeb5aea Merge branch 'master' into feature/meta
* master:
  Added tests for the REST endpoints exposed in our example. Added a script for running the example app. Split the example into multiple files.
  Go 1.8 released today; dropping support for 1.6
  Travis calls script/test
  Added a script/test such that the example app can also have tests and been included in the CI test runs.

# Conflicts:
#	examples/app.go
2017-02-16 19:30:44 -08:00
Aren Patel 6958c3a8be Added tests for the REST endpoints exposed in our example. Added a script for running the example app. Split the example into multiple files. 2017-02-16 19:28:09 -08:00
Aren Patel 4898d2ff2a Go 1.8 released today; dropping support for 1.6 2017-02-16 17:49:49 -08:00
Aren Patel 4ffe86f477 Travis calls script/test 2017-02-16 17:48:23 -08:00
Aren Patel b7ab492362 Added a script/test such that the example app can also have tests and been included in the CI test runs. 2017-02-16 17:47:00 -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
Aren Patel 52f00735e0 Add GoDoc button. 2017-02-13 11:41:01 -08:00
Matt Bostock 40fe9896b3 Prefix example app with $GOPATH env var (#79)
Instead of using `cd` to change to the package directory, prepend the examples commands with `$GOPATH`, which will make the commands easier to follow for anyone unfamiliar with Go. It's easy to miss the 'cd' instruction above.
2017-02-07 18:42:29 -08:00
Aren Patel ec041eb56b Updated README.md
Corrected the example for Links
2017-02-03 19:16:54 -08:00
Aren Patel 7d60f153a2 Added test (serialization, deserialization) for the []string attr feature. 2017-02-03 15:18:58 -08:00
Aren Patel 1d32e9110b Prefer []string{} to []string(nil) 2017-02-03 14:48:06 -08:00
Mirek Petricek 6e6258e1ab Remove accidentaly introduced? noisy println from tests (#75)
* use constants rather than strings in request.go

* Remove accidentaly introduced? noisy println from tests
2017-02-03 14:45:34 -08:00
Marc Abramowitz 71d291e52c README.md: Fix typo in "serializer" (#65) 2017-02-03 12:16:52 -08:00
Sam Woodard 6e86cbdd0d Merge pull request #38 from thedodd/handle-type-errors
Handle type errors during unmarshalNode routine.
2017-01-31 12:35:06 -08:00
Anthony Dodd 1e69609202
Revert use of new error system in `request.go`.
Update tests to account for generic `errors.New` use.
2017-01-31 13:36:56 -06:00
Anthony Dodd 5836d603a3
Handle type errors properly during unmarshal node.
During the `unmarshalNode` routine, various type errors may come up.
Currently they are being swallowed by the error handling mechanism.
Rework that system so that errors are actually exposed and can be
corrected without having to dive into the code.

Handle time.Time & *time.Time type errors.

Add test for unmarshalling ptr with bad type.

Final `attr` type check catch-all & tests.

Implement system for JSON API compatible errors.

This commit creates a series of structs and interfaces for representing
JSON API compatible error objects. It includes a method for emitting a
payload of error objects (according to the JSON API spec). Its algorithm
is based upon a series of interfaces which define incremental levels of
support for errors which are JSON API compatible.

Use new error type for unmarshalling errors.

Update some docs & the privacy of a func.

Don't be prescriptive on `meta`. Use map[string]interface{}.

Add a README section on errors &c.

Do not force inclusion of `title` & `detail` (use omitempty).

Update README & docs on use of pertient errors related types.

Update tests to account for these changes.

If error type is already *ErrorObject, return immediately.

Rm everything except for ErrorsPayload, ErrorObject & MarshalErrors.

Also update README & tests.

Remove a test fixture which is no longer needed.
2017-01-31 13:06:10 -06:00
Keiji Yoshida e126f9ab94 Fix newUUID (#70)
The checking `n` returned by `io.ReadFull()` is removed because `io.ReadFull()` returns n == len(buf) if and only if err == nil according to its document ( https://golang.org/pkg/io/#ReadFull ) and it's enough to check only `err`.
2017-01-30 13:51:41 -08:00
Mirek Petricek d550198212 use constants rather than strings in request.go (#71) 2017-01-30 13:14:01 -08:00
Keiji Yoshida a8d743e645 Remove an unused parameter (#69)
`relationName` parameter of `visitModelNodeRelationships` method is not used and removed.
2017-01-28 19:43:47 -08:00
Aren Patel 3ea9ec4904 Testing and Documentation for UnmarshalManyPayload (#66)
* Added a test for UnmarshalManyPayload

* Document UnmarshalManyPayload in the Readme

* Update the example app to have a UnmarshalManyPayload usage.

* DRY the UnmarshalManyPayload implementation.

* Add a test for grabbing the Links out of a ManyPayload
2017-01-26 15:25:13 -08:00
Lucius Humm 9d919b42a6 Add MarshalManyPayloadWithoutIncluded (#56)
* fix spelling in documentation

* add MarshalManyPayloadWithoutIncluded

does the same as `MarshalOnePayloadWithoutIncluded` but for
MarshalManyPayload

* Refactored MarshalManyPayloadWithoutIncluded to use the MarshalMany func
2017-01-24 14:53:31 -08:00
Aren Patel baa7beb3f7 Update the go versions 2017-01-20 21:36:58 -08:00
Aren Patel 15abc3066a Use constants for status codes, HTTP methods and JSON API media types in comments and readme 2017-01-20 18:06:44 -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 bb88592460 Simplify the MarshalMany implementation. For & range rather than for with int inc; etc. (#59) 2017-01-17 16:04:07 -08:00
Aren Patel 925ebf2136 Added support for string, int(8,16,32,64), uint(8,16,32,64) and each … (#51)
* Added support for string, int(8,16,32,64), uint(8,16,32,64) and each of their ptr types as acceptable to use for the ID field.

* No longer declaring a new idErr var; also eliminate the switch within a switch - if the ID field was a string or *string it will continue. Added a couple extra tests.
2016-09-22 15:02:30 -07:00
Geoff Garside b6c6609ff2 Add support for iso8601 struct tag argument (#47)
* Add support for iso8601 struct tag.

Currently only unix timestamps are supported for serialising time.Time objects. The JSON.API specification doesn't make a specific requirement on time serialisation format, though it does make a recommendation for using ISO8601.

This adds support for an additional struct tag `iso8601` which controls serialisation and deserialisation using the ISO8601 timestamp format.

* Update doc.go with information regarding iso8601 and omitempty tag arguments.
2016-09-22 13:58:07 -07: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
Aren Patel a70d58d3c8 Support pointers as attrs (#40)
* add support to unmarshal attributes to struct field that are ptr types

* Spacing, addressed all the linter warnings, comments to describe errors, cleanup, left a TODO note to resolve the Error messaging.
2016-07-22 18:34:38 -07:00
Aren Patel dd46e31eb5 Updated: build status badge, the go get installation instruction to account for the repo move, readme examples use ID instead of Id (so that they would be linter compliant if copy/pasted). shwoodard/jsonapi => google/jsonapi (#41) 2016-07-22 18:31:33 -07:00
Sam Woodard b4fad2f2e6 Change to force travis to pick up config 2016-07-21 09:00:16 -07:00
Sam Woodard 2eeccd9649 Update License
Process to transfer ownership to google
2016-07-19 13:50:30 -07:00
Aren Patel de4994e265 Feature/omitempty (#35)
* Implemented a failing test demonstrating the intended behaviour of the omitempty annotation.

* Updated the failing test to ensure that unset field without the "omitempty" annotation are not inadvertently omitted.

* Working implementation of the "omitempty" annotation for fields that are of any type.

* Update the readme to include a brief description of how to use the `omitempty` in a attr field.

* Update the json example also using a uint for type variety.
2016-07-16 08:24:21 -07:00