-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JsonApi::Deserialization YARD docs are misleading #2384
Comments
it says about the you may take a look at an example how it can be used: active_model_serializers/lib/active_model_serializers/adapter/json_api/deserialization.rb Lines 67 to 69 in 873cf4a
|
because active_model_serializers/lib/active_model_serializers/adapter/json_api/deserialization.rb Line 18 in 873cf4a
and in the latter case, its converted to a hash with string-keys, as can be seen in: active_model_serializers/lib/active_model_serializers/adapter/json_api/deserialization.rb Line 86 in 873cf4a
|
to be honest, I have found one gotcha though: it should be active_model_serializers/lib/active_model_serializers/adapter/json_api/deserialization.rb Lines 27 to 56 in 873cf4a
may be because the spec was like that during the time when this example was written :) |
Hey @wasifhossain thanks for pointing that out to me >_< I guess I should have pointed to this example instead - this would be a symbol-keyed hash, no?
|
according to the spec, a valid JSON API document keys should be stringified, as shown in this typical example https://jsonapi.org/format/#document-compound-documents {
"data": [{
"type": "articles",
"id": "1",
"attributes": {
"title": "JSON:API paints my bikeshed!"
},
"links": {
"self": "http://example.com/articles/1"
},
"relationships": {
"author": {
"links": {
"self": "http://example.com/articles/1/relationships/author",
"related": "http://example.com/articles/1/author"
},
"data": { "type": "people", "id": "9" }
},
"comments": {
"links": {
"self": "http://example.com/articles/1/relationships/comments",
"related": "http://example.com/articles/1/comments"
},
"data": [
{ "type": "comments", "id": "5" },
{ "type": "comments", "id": "12" }
]
}
}
}],
"included": [{
"type": "people",
"id": "9",
"attributes": {
"first-name": "Dan",
"last-name": "Gebhardt",
"twitter": "dgeb"
},
"links": {
"self": "http://example.com/people/9"
}
}, {
"type": "comments",
"id": "5",
"attributes": {
"body": "First!"
},
"relationships": {
"author": {
"data": { "type": "people", "id": "2" }
}
},
"links": {
"self": "http://example.com/comments/5"
}
}, {
"type": "comments",
"id": "12",
"attributes": {
"body": "I like XML better"
},
"relationships": {
"author": {
"data": { "type": "people", "id": "9" }
}
},
"links": {
"self": "http://example.com/comments/12"
}
}]
} |
@wasifhossain I get that - since we're documenting in Ruby though, should we not expect that users will read this as Ruby? Happy to close this either way... |
I will push a PR with a working example for this api (#2384 (comment)) thanks for pointing it out 👍 |
I'd be happy to make a PR if you don't have time, just wanted to be sure that I had the correct interpretation! |
sure thing. please go ahead with this. I will have a look later. thanks! |
Expected behavior vs actual behavior
In the YARD docs the example suggests that using a symbol-keyed hash will work:
active_model_serializers/lib/active_model_serializers/adapter/json_api/deserialization.rb
Lines 27 to 56 in 873cf4a
(Edited)
But in the code, it will actually check via string-keys:
https://github.com/rails-api/active_model_serializers/blob/v0.10.10/lib/active_model_serializers/adapter/json_api/deserialization.rb#L118
The text was updated successfully, but these errors were encountered: