Commit Graph

228 Commits

Author SHA1 Message Date
Marc Abramowitz a3b3bb2cb5 Show type for ErrUnsupportedPtrType
to aid in troubleshooting.

Before:

```
Pointer type in struct is not supported
```

After:

```
jsonapi: Can't unmarshal true (bool) to struct field `Name`, which is a pointer to `string`
```
2018-01-17 13:38:32 -08:00
Marc Abramowitz 16e19ab9f9 Make nested struct pointers work 2018-01-17 13:02:30 -08:00
Marc Abramowitz b28beab7f3 Add TestUnmarshalNestedStructPtr 2018-01-17 13:02:30 -08:00
Marc Abramowitz e3c0871f34 Test more things in TestUnmarshalNestedStruct 2018-01-17 08:12:59 -08:00
Slemgrim 0400041771 fix wrong type for formatting 2017-11-21 19:15:24 +08:00
Slemgrim a6577dfae8 Add more speaking tests
tests should have an expected outcome vs. an actual outcome to make them easier to debug
2017-11-21 19:05:50 +08:00
Slemgrim 7e5c9014d9 Merge remote-tracking branch 'upstream/master' 2017-11-21 18:42:48 +08:00
Sam Woodard e0fc4eed33
Merge pull request #118 from themccallister/patch-1
Add tests for mismatching accept headers
2017-11-08 09:49:09 -08:00
Jason McCallister 081fb8a5c2 Add additional test for method not found 2017-10-23 22:46:32 -04:00
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
Markus Ritberger fc6968dfe7 change nested structs to json annotation instead of json:api. It never made sense to use json:api annotation in nested structs 2017-08-14 20:41:26 +02:00
Markus Ritberger b391a84b75 remove duplicated code 2017-08-14 20:39:14 +02:00
Aren Patel c045c87aa1
Ignore Gogland files. 2017-08-01 11:45:13 -07:00
Slemgrim af21dba1b2 handle nested struct slices 2017-07-15 15:22:03 +02:00
Slemgrim 0c97f0cf8d extract attribute handling into custom method for recursive usage later on 2017-07-11 21:43:12 +02:00
Slemgrim ab915ccbc1 unify type handler 2017-07-10 22:50:43 +02:00
Slemgrim f0b268e046 Merge remote-tracking branch 'upstream/master' 2017-07-10 22:16:45 +02:00
Slemgrim ec077ed283 Merge branch 'master' of https://github.com/Slemgrim/jsonapi 2017-07-10 22:12:10 +02:00
Slemgrim e13a19922d extract type handling 2017-07-10 22:09:01 +02: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