Repository: networknt/json-schema-validator (java)

Issue:
when I set type:["string",null],this custom errorMessage is invalid
oneOf:errorMessage is valid,but type:["string",null] errorMessage is invalid
{
  "type": "object",
  "properties": {
    "keyword": {
      "oneOf": [
        { "type": "string" },
        { "type": "null" }
      ],
      "errorMessage": {
        "oneOf": "keyword必须为字符串"
      },
      "title": "关键字"
    },
    "keyword1": {
      "type": ["string","null"],
      "errorMessage": {
        "type": "关键字1必须为字符串"
      },
      "title": "关键字"
    }


  }}

Pull request description:
Fix custom error message for union type
Closes #1137 

Patch:
diff --git a/src/main/java/com/networknt/schema/UnionTypeValidator.java b/src/main/java/com/networknt/schema/UnionTypeValidator.java
index c6292ef..3dd0e32 100644
--- a/src/main/java/com/networknt/schema/UnionTypeValidator.java
+++ b/src/main/java/com/networknt/schema/UnionTypeValidator.java
@@ -35,7 +35,7 @@ public class UnionTypeValidator extends BaseJsonValidator implements JsonValidat
     private final String error;
 
     public UnionTypeValidator(SchemaLocation schemaLocation, JsonNodePath evaluationPath, JsonNode schemaNode, JsonSchema parentSchema, ValidationContext validationContext) {
-        super(schemaLocation, evaluationPath, schemaNode, parentSchema, ValidatorTypeCode.UNION_TYPE, validationContext);
+        super(schemaLocation, evaluationPath, schemaNode, parentSchema, ValidatorTypeCode.TYPE, validationContext);
         StringBuilder errorBuilder = new StringBuilder();
 
         String sep = "";


Test patch:
diff --git a/src/test/java/com/networknt/schema/ValidationMessageHandlerTest.java b/src/test/java/com/networknt/schema/ValidationMessageHandlerTest.java
index a0b9c3c..4ff9a8e 100644
--- a/src/test/java/com/networknt/schema/ValidationMessageHandlerTest.java
+++ b/src/test/java/com/networknt/schema/ValidationMessageHandlerTest.java
@@ -61,4 +61,32 @@ class ValidationMessageHandlerTest {
         assertEquals("should not have properties other than foo", messages.get(1).getMessage());
     }
 
+    @Test
+    void errorMessageUnionType() {
+        String schemaData = "{\r\n"
+                + "  \"type\": \"object\",\r\n"
+                + "  \"properties\": {\r\n"
+                + "    \"keyword1\": {\r\n"
+                + "      \"type\": [\r\n"
+                + "        \"string\",\r\n"
+                + "        \"null\"\r\n"
+                + "      ],\r\n"
+                + "      \"errorMessage\": {\r\n"
+                + "        \"type\": \"关键字1必须为字符串\"\r\n"
+                + "      },\r\n"
+                + "      \"title\": \"关键字\"\r\n"
+                + "    }\r\n"
+                + "  }\r\n"
+                + "}";
+        String inputData = "{\r\n"
+                + "  \"keyword1\": 2\r\n"
+                + "}";
+        JsonSchema schema = JsonSchemaFactory.getInstance(VersionFlag.V202012).getSchema(schemaData,
+                SchemaValidatorsConfig.builder().errorMessageKeyword("errorMessage").build());
+        List<ValidationMessage> messages = schema.validate(inputData, InputFormat.JSON).stream().collect(Collectors.toList());
+        assertFalse(messages.isEmpty());
+        assertEquals("/keyword1", messages.get(0).getInstanceLocation().toString());
+        assertEquals("关键字1必须为字符串", messages.get(0).getMessage());
+    }
+
 }