Of the following tests, the first passes, and the remaining 2 do not. They look valid to me, but appear to indicate the validator does not handle properties that are arrays of objects properly.
1) test array ref test 3 (CEP.JSONSchemaTest)
apps/cep/test/json_schema_test.exs:53
** (MatchError) no match of right hand side value: {:error, [{"Schema does not allow additional properties.", "#/tests/0/uid"}, {"Required property uid was not present.", "#/tests/0"}]}
stacktrace:
apps/cep/test/json_schema_test.exs:76: (test)
test array ref test 4 (0.8ms)
2) test array ref test 4 (CEP.JSONSchemaTest)
apps/cep/test/json_schema_test.exs:79
** (MatchError) no match of right hand side value: {:error, [{"Schema does not allow additional properties.", "#/tests/0/uid"}, {"Required property uid was not present.", "#/tests/0"}]}
stacktrace:
apps/cep/test/json_schema_test.exs:99: (test)
Of the following tests, the first passes, and the remaining 2 do not. They look valid to me, but appear to indicate the validator does not handle properties that are arrays of objects properly.
test "array ref test 2" do schema = %{ "type" => "array", "items" => %{"$ref" => "#/definitions/item"}, "definitions" => %{ "item" => %{ "type" => "object", "properties" => %{ "uid" => %{"type" => "string"} }, "required" => ["uid"], "additionalProperties" => false } } } |> ExJsonSchema.Schema.resolve json = [%{uid: "test", junk: 1}] {:error, [{msg, var}]} = ExJsonSchema.Validator.validate(schema, string_keys(json)) assert Regex.run(~r/junk/,var) != nil assert Regex.run(~r/not allow additional/,msg) != nil end
test "array ref test 3" do schema = %{ "type" => "object", "properties" => %{ "tests" => %{ "type" => "array", "items" => %{"$ref" => "#/definitions/item"} }, }, "definitions" => %{ "item" => %{ "type" => "object", "properties" => %{ "uid" => %{ "type" => "string" } }, "required" => ["uid"], "additionalProperties" => false } } } |> ExJsonSchema.Schema.resolve json = %{tests: [%{uid: "test"}]} :ok = ExJsonSchema.Validator.validate(schema, string_keys(json)) end
test "array nesting test 4" do schema = %{ "type" => "object", "properties" => %{ "tests" => %{ "type" => "array", "items" => %{ "type" => "object", "properties" => %{ "uid" => %{ "type" => "string" } }, "required" => ["uid"], "additionalProperties" => false } }, }, } |> ExJsonSchema.Schema.resolve json = %{tests: [%{uid: "test"}]} :ok = ExJsonSchema.Validator.validate(schema, string_keys(json)) end
Test output:
test array ref test 2 (0.7ms)
test array ref test 3 (5.9ms)
1) test array ref test 3 (CEP.JSONSchemaTest) apps/cep/test/json_schema_test.exs:53 ** (MatchError) no match of right hand side value: {:error, [{"Schema does not allow additional properties.", "#/tests/0/uid"}, {"Required property uid was not present.", "#/tests/0"}]} stacktrace: apps/cep/test/json_schema_test.exs:76: (test)
test array ref test 4 (0.8ms)
2) test array ref test 4 (CEP.JSONSchemaTest) apps/cep/test/json_schema_test.exs:79 ** (MatchError) no match of right hand side value: {:error, [{"Schema does not allow additional properties.", "#/tests/0/uid"}, {"Required property uid was not present.", "#/tests/0"}]} stacktrace: apps/cep/test/json_schema_test.exs:99: (test)