mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-23 14:29:31 +00:00
pretty clear now that the ONLY difference
rendering a `user` with `include: 'posts.comments'`
is that the included post's user relationship
in jsonapirb is `meta: { included: false }`
and AMS is `data: { id: 1, type: users}`
which I guess is to avoid the user's
post's comment from looking up the user?
similarly, the included comment's post relationship
for jsonapi-rb is `meta: { included: false}`
and AMS is `data: { id: 2, type: posts }`
took a bit of jq and diff to figure this out
43 lines
1.3 KiB
Bash
43 lines
1.3 KiB
Bash
#!/usr/bin/env bash
|
|
|
|
set -o pipefail
|
|
|
|
DEBUG="${DEBUG:-false}"
|
|
|
|
if ! command -v jq &>/dev/null; then
|
|
npm install -g jq
|
|
fi
|
|
|
|
get_for_file() {
|
|
local path
|
|
path="$1"
|
|
result="$(cat ${path})"
|
|
echo "$result"
|
|
}
|
|
|
|
compare_files() {
|
|
local actual
|
|
local expected
|
|
local pattern
|
|
actual="$1"
|
|
expected="$2"
|
|
pattern="$3"
|
|
|
|
if [ "$DEBUG" = "true" ]; then get_for_file "${expected}" >&2; fi
|
|
diff --side-by-side \
|
|
<(jq "${pattern}" -S <(get_for_file "${expected}")) \
|
|
<(jq "${pattern}" -S <(get_for_file "${actual}"))
|
|
}
|
|
echo
|
|
|
|
echo "-------------------------------------data"
|
|
compare_files support/json_document-ams.json support/json_document-jsonapi_rb.json ".data"
|
|
echo "-------------------------------------included posts"
|
|
compare_files support/json_document-ams.json support/json_document-jsonapi_rb.json ".included | .[] | select(.type == \"posts\")"
|
|
echo "-------------------------------------included comments"
|
|
compare_files support/json_document-ams.json support/json_document-jsonapi_rb.json ".included | .[] | select(.type == \"comments\")"
|
|
echo "-------------------------------------included types: ams"
|
|
jq '.included | .[] | .type' -S < support/json_document-ams.json | sort -u
|
|
echo "-------------------------------------included types: jsonapi_rb"
|
|
jq '.included | .[] | .type' -S < support/json_document-jsonapi_rb.json | sort -u
|