mattpolzin / JSONAPI

Swift Codable JSON:API framework
MIT License
75 stars 19 forks source link

Enhance error reporting of relationships. #84

Closed mlomeli closed 4 years ago

mlomeli commented 4 years ago

Currently if you fail to include an object due to a bad spec, you'll see errors like this.

For example an Include error is described as this

Include 4 failed to parse 

`Could not have been Include Type 1 because:
found JSON:API type "person" but expected "dog"`

`Could not have been Include Type 2 because:
found JSON:API type "person" but expected "pet"`

`Could not have been Include Type 3 because:
found JSON:API type "paragraph" but expected "media"`

Could not have been Include Type 4 because:
'nickname' attribute is not nullable but null was found.

And a primary error as this

Primary Resource 1 failed to parse because 'name' attribute is not nullable but null was found.

I found out that the specific Include error is detailed in DocumentDecodingError is detailed in the idx but not really shown in the description.

I wonder if it's a better way to print only:

Include Type 4 failed because: 'nickname' attribute is not nullable but null was found.

But maybe that's because I don't know if there are other use cases.

mlomeli commented 4 years ago

I wrote code as suggestion let me upload it.

mlomeli commented 4 years ago

Thanks for the fix :) https://github.com/mattpolzin/JSONAPI/pull/86

mattpolzin commented 4 years ago

Available in https://github.com/mattpolzin/JSONAPI/releases/tag/5.0.0-rc.1