jonasschmidt / ex_json_schema

An Elixir JSON Schema validator
MIT License
366 stars 98 forks source link

Map.take deprecation #45

Closed rsilvestre closed 5 years ago

rsilvestre commented 5 years ago

Hi,

Erlang/OTP 22 [erts-10.4.3] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [hipe] [dtrace]

Interactive Elixir (1.9.0) - press Ctrl+C to exit (type h() ENTER for help)

With elixir 1.9 comes lot of deprecations.

One of them is : warning: Map.take/2 with an Enumerable of keys that is not a list is deprecated. Use a list of keys instead.

The consequence is the follow : in ex_json_schema/lib/ex_json_schema/validator/properties.ex line 73: Map.take(properties, unvalidated)

unvalidated is a MapSet that is now deprecated

one solution could be to do : Map.take(properties, MapSet.to_list(unvalidated))

Other thing, in ex_json_schema/lib/ex_json_schema/validator.ex line 182, 189, 197, 204: Map.size is deprecated It should to be replaced by map_size (Kernel.map_size)

The consequence of this deprecation. My log is filled with bunch of warning

I tried do clone the project, fix the issue, but when I try to test it, I have :

Finished in 1.0 seconds
484 tests, 6 failures

Sorry, i don't have more time do spend on this issue.

git diff :

diff --git a/lib/ex_json_schema/validator.ex b/lib/ex_json_schema/validator.ex
index 870d91b..017b310 100644
--- a/lib/ex_json_schema/validator.ex
+++ b/lib/ex_json_schema/validator.ex
@@ -179,14 +179,14 @@ defmodule ExJsonSchema.Validator do
   end

   defp validate_aspect(_, _, {"minProperties", min_properties}, data) when is_map(data) do
-    case Map.size(data) >= min_properties do
+    case map_size(data) >= min_properties do
       true ->
         []

       false ->
         [
           %Error{
-            error: %Error.MinProperties{expected: min_properties, actual: Map.size(data)},
+            error: %Error.MinProperties{expected: min_properties, actual: map_size(data)},
             path: ""
           }
         ]
@@ -194,14 +194,14 @@ defmodule ExJsonSchema.Validator do
   end

   defp validate_aspect(_, _, {"maxProperties", max_properties}, data) when is_map(data) do
-    case Map.size(data) <= max_properties do
+    case map_size(data) <= max_properties do
       true ->
         []

       false ->
         [
           %Error{
-            error: %Error.MaxProperties{expected: max_properties, actual: Map.size(data)},
+            error: %Error.MaxProperties{expected: max_properties, actual: map_size(data)},
             path: ""
           }
         ]
diff --git a/lib/ex_json_schema/validator/properties.ex b/lib/ex_json_schema/validator/properties.ex
index b5882de..033ca2d 100644
--- a/lib/ex_json_schema/validator/properties.ex
+++ b/lib/ex_json_schema/validator/properties.ex
@@ -70,7 +70,7 @@ defmodule ExJsonSchema.Validator.Properties do

   defp unvalidated_properties(properties, validated_properties) do
     unvalidated = MapSet.difference(keys_as_set(properties), keys_as_set(validated_properties))
-    Map.take(properties, unvalidated)
+    Map.take(properties, MapSet.to_list(unvalidated))
   end

   defp keys_as_set(properties) do
diff --git a/test/JSON-Schema-Test-Suite b/test/JSON-Schema-Test-Suite
index 1bd999a..9cbad89 160000
--- a/test/JSON-Schema-Test-Suite
+++ b/test/JSON-Schema-Test-Suite
@@ -1 +1 @@
-Subproject commit 1bd999ac16bd8d3fdb5c44ef13a0759aefb4ab73
+Subproject commit 9cbad896454d42fb591ffb4ed3b452a5c12ec63a
woylie commented 5 years ago

This was addressed in #43

rsilvestre commented 5 years ago

If it was addressed 9 days ago, why it's still there ?