From 00d01cfd9c74307840a114da6ff606179bde4011 Mon Sep 17 00:00:00 2001 From: Zack Michener Date: Sat, 24 Feb 2024 07:16:42 -0800 Subject: [PATCH] Transform relationship keys with shallow field transformation options (#314) (#315) * Transform relationship keys with shallow field transformation options * bump patch version * Add line item for other bug fix --------- Co-authored-by: Mathew Polzin --- CHANGELOG.md | 6 ++++++ lib/jsonapi/utils/string.ex | 4 ++++ mix.exs | 2 +- test/jsonapi/serializer_test.exs | 3 +++ 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 61f66a52..37470999 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,12 @@ ## NEXT ... +## 1.7.1 (2024-02-23) +* Fix bug where underscore/dasherize misses single characters by @protestContest in https://github.com/beam-community/jsonapi/pull/316 +* Transform relationship keys with shallow field transformation options (#314) by @protestContest in https://github.com/beam-community/jsonapi/pull/315 + +**Full Changelog**: https://github.com/beam-community/jsonapi/compare/1.7.0...1.7.1 + ## 1.7.0 (2024-02-15) ## What's Changed diff --git a/lib/jsonapi/utils/string.ex b/lib/jsonapi/utils/string.ex index e01af9ad..6877d9c4 100644 --- a/lib/jsonapi/utils/string.ex +++ b/lib/jsonapi/utils/string.ex @@ -267,6 +267,10 @@ defmodule JSONAPI.Utils.String do end) end + def expand_root_keys(key, fun) when is_binary(key) or is_atom(key) do + fun.(key) + end + def expand_root_keys(value, _fun), do: expand_fields(value, &to_string/1) defp maybe_expand_fields(values, fun) when is_list(values) do diff --git a/mix.exs b/mix.exs index 8a4535c8..ffcc5c5d 100644 --- a/mix.exs +++ b/mix.exs @@ -4,7 +4,7 @@ defmodule JSONAPI.Mixfile do def project do [ app: :jsonapi, - version: "1.7.0", + version: "1.7.1", package: package(), compilers: compilers(Mix.env()), description: description(), diff --git a/test/jsonapi/serializer_test.exs b/test/jsonapi/serializer_test.exs index 65543c3f..14cb113c 100644 --- a/test/jsonapi/serializer_test.exs +++ b/test/jsonapi/serializer_test.exs @@ -667,12 +667,15 @@ defmodule JSONAPI.SerializerTest do encoded = Serializer.serialize(PostView, data, nil) attributes = encoded[:data][:attributes] + relationships = encoded[:data][:relationships] included = encoded[:included] assert attributes["full-description"] == data[:full_description] assert attributes["body"]["data_attr"] == "foo" assert attributes["inserted-at"] == data[:inserted_at] + assert Map.has_key?(relationships, "best-comments") + author = Enum.find(included, &(&1[:type] == "user" && &1[:id] == "2")) assert author != nil assert author[:attributes]["last-name"] == "bonds"