Current section

23 Versions

Jump to

Compare versions

4 files changed
+15 additions
-10 deletions
  @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
4 4 The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5 5 and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6 6
7 + ## [0.23.1](https://github.com/township-agency/ex_teal/compare/v0.23.0...v0.23.1) (2023-07-10)
8 +
9 +
10 + ### Bug Fixes
11 +
12 + * Serializer should consider errors where the key is an array ([#205](https://github.com/township-agency/ex_teal/issues/205)) ([59953fc](https://github.com/township-agency/ex_teal/commit/59953fc6927a2f9bfce1e23f1207c6c87a5b5a37))
13 +
7 14 ## [0.23.0](https://github.com/township-agency/ex_teal/compare/v0.22.2...v0.23.0) (2023-07-07)
  @@ -207,4 +207,4 @@
207 207 {<<"optional">>,false},
208 208 {<<"repository">>,<<"hexpm">>},
209 209 {<<"requirement">>,<<"~> 1.0">>}]]}.
210 - {<<"version">>,<<"0.23.0">>}.
210 + {<<"version">>,<<"0.23.1">>}.
  @@ -12,17 +12,15 @@ defmodule ExTeal.Api.ErrorSerializer do
12 12 See `Ecto.Changeset.traverse_errors/2`
13 13 """
14 14 def translate_errors(%Changeset{} = changeset) do
15 - Changeset.traverse_errors(changeset, &parse_changeset_error/1)
16 - end
17 -
18 - defp parse_changeset_error({msg, opts}) do
19 - Enum.reduce(opts, msg, fn {key, value}, acc ->
20 - String.replace(acc, "%{#{key}}", to_string(value))
15 + Changeset.traverse_errors(changeset, fn {message, opts} ->
16 + Regex.replace(~r"%{(\w+)}", message, fn _, key ->
17 + opts
18 + |> Keyword.get(String.to_existing_atom(key), key)
19 + |> to_string()
20 + end)
21 21 end)
22 22 end
23 23
24 - defp parse_changeset_error(msg), do: msg
25 -
26 24 def render(%Changeset{} = changeset) do
27 25 # When encoded, the changeset returns its errors
28 26 # as a JSON object. So we just pass it forward.
  @@ -6,7 +6,7 @@ defmodule ExTeal.MixProject do
6 6 def project do
7 7 [
8 8 app: :ex_teal,
9 - version: "0.23.0",
9 + version: "0.23.1",
10 10 elixir: "~> 1.12",
11 11 start_permanent: Mix.env() == :prod,
12 12 build_embedded: Mix.env() == :prod,