diff --git a/lib/exonerate/context.ex b/lib/exonerate/context.ex index 8469b3d..3fa7e5b 100644 --- a/lib/exonerate/context.ex +++ b/lib/exonerate/context.ex @@ -175,6 +175,7 @@ defmodule Exonerate.Context do {filters, accessories} = types + |> List.wrap() |> MapSet.new() |> MapSet.intersection(filtered_types) |> Enum.map(fn type -> diff --git a/lib/exonerate/degeneracy.ex b/lib/exonerate/degeneracy.ex index 4a7334b..26bd3d2 100644 --- a/lib/exonerate/degeneracy.ex +++ b/lib/exonerate/degeneracy.ex @@ -275,7 +275,8 @@ defmodule Exonerate.Degeneracy do def class(false), do: :error def class(context = %{"type" => t}) do - if Enum.sort(t) == @all_types do + types = List.wrap(t) + if Enum.sort(types) == @all_types do context |> Map.delete("type") |> class() diff --git a/mix.exs b/mix.exs index 86b4b25..af11954 100644 --- a/mix.exs +++ b/mix.exs @@ -4,7 +4,7 @@ defmodule Exonerate.MixProject do def project do [ app: :exonerate, - version: "1.1.2", + version: "1.1.3", elixir: "~> 1.14", start_permanent: Mix.env() == :prod, deps: deps(), diff --git a/test/regression/general_test.exs b/test/regression/general_test.exs index 0565656..ade6a90 100644 --- a/test/regression/general_test.exs +++ b/test/regression/general_test.exs @@ -1,4 +1,4 @@ -defmodule ExonerateTest.RegressionTest do +defmodule ExonerateTest.Regression.GeneralTest do use ExUnit.Case, async: true require Exonerate diff --git a/test/regression/string_type_test.exs b/test/regression/string_type_test.exs new file mode 100644 index 0000000..1151574 --- /dev/null +++ b/test/regression/string_type_test.exs @@ -0,0 +1,31 @@ +defmodule ExonerateTest.Regression.NestedStringTypeTest do + use ExUnit.Case, async: true + require Exonerate + + # contributed by @ahacking (issue #78). This is due to + # degeneracy testing across jumps in the schema not respecting + # type being a single string instead of an array. + + Exonerate.function_from_string(:def, :validate_api, ~S""" + { + "$schema": "http://json-schema.org/draft-04/schema#", + "title": "JSON validation failure", + "type": "object", + "id": "https://example.com/fail.json", + "definitions": { + "versionType": { + "type": "string", + "enum": [ "1.0", "1.1", "2.0" ] + } + }, + "properties": { + "version": { "$ref": "#/definitions/versionType" } + }, + "required": [ "version" ] + } + """) + + test "regression passes" do + assert :ok = validate_api(%{"version" => "1.1"} ) + end +end