Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/conform/schema.ex
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ defmodule Conform.Schema do
schema |> Map.to_list |> Keyword.delete(:__struct__) |> Enum.map(&to_list/1)
end
defp to_list({k, v}) when is_list(v) do
{k, Enum.map(v, &to_list/1)}
{k, Enum.map(Enum.sort(v, &do_sort/2), &to_list/1)}
end
defp to_list(%Conform.Schema.Validator{name: nil, definition: nil, validator: v}), do: v
defp to_list(%Conform.Schema.Validator{name: name, definition: v}), do: {String.to_atom(name), v}
Expand All @@ -345,6 +345,14 @@ defmodule Conform.Schema do
v |> Map.to_list |> Keyword.delete(:__struct__)
end

defp do_sort(m1, m2) do
key(m1) <= key(m2)
end

defp key(%Conform.Schema.Mapping{name: name}), do: name
defp key(%Conform.Schema.Validator{name: name}), do: name
defp key(k), do: k

@doc """
Convert standard configuration to quoted schema format
"""
Expand Down
24 changes: 12 additions & 12 deletions test/integration_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,18 @@ defmodule IntegrationTest do
extends: [],
import: [],
mappings: [
"my_app.rx_pattern": [
commented: false,
datatype: [
list: :binary
],
default: [
~r/[A-Z]+/
],
doc: "Provide documentation for my_app.rx_pattern here.",
hidden: false,
to: "my_app.rx_pattern"
],
"my_app.sublist": [
commented: false,
datatype: [
Expand All @@ -114,18 +126,6 @@ defmodule IntegrationTest do
doc: "Provide documentation for my_app.sublist here.",
hidden: false,
to: "my_app.sublist"
],
"my_app.rx_pattern": [
commented: false,
datatype: [
list: :binary
],
default: [
~r/[A-Z]+/
],
doc: "Provide documentation for my_app.rx_pattern here.",
hidden: false,
to: "my_app.rx_pattern"
]
],
transforms: [],
Expand Down