diff --git a/src/main/resources/jsv-messages.properties b/src/main/resources/jsv-messages.properties index dab978c4c..69262d22d 100644 --- a/src/main/resources/jsv-messages.properties +++ b/src/main/resources/jsv-messages.properties @@ -32,8 +32,8 @@ unionType = {0}: {1} found, but {2} is required uniqueItems = {0}: the items in the array must be unique uuid = {0}: {1} is an invalid {2} id = {0}: {1} is an invalid segment for URI {2} -exclusiveMaximum = {0}: must have a exclusive maximum value of {1} -exclusiveMinimum = {0}: must have a exclusive minimum value of {1} +exclusiveMaximum = {0}: must have an exclusive maximum value of {1} +exclusiveMinimum = {0}: must have an exclusive minimum value of {1} false = Boolean schema false is not valid const = {0}: must be a constant value {1} contains = {0}: does not contain an element that passes these validations: {1} diff --git a/src/main/resources/jsv-messages_de_DE.properties b/src/main/resources/jsv-messages_de_DE.properties new file mode 100644 index 000000000..3e7cc20f7 --- /dev/null +++ b/src/main/resources/jsv-messages_de_DE.properties @@ -0,0 +1,40 @@ +additionalProperties = {0}.{1} ist nicht im Schema definiert und das Schema verbietet 'additionalProperties' +allOf = {0} muss gültig für alle Schemata {1} sein +anyOf = {0} muss gültig für mindestens ein Schema {1} sein +crossEdits = {0}: Ein Fehler mit 'cross edits' ist aufgetreten +dependencies = {0} hat einen Fehler mit Abhängigkeiten {1} +dependentRequired = {0} fehlt eine Eigenschaft, welche 'dependentRequired' {1} ist +dependentSchemas = {0}: Ein Fehler mit 'dependentSchemas' {1} ist aufgetreten +edits = {0}: Ein Fehler mit 'edits' ist aufgetreten +enum = {0}: Ein Wert in der Aufzählung {1} fehlt +format = {0} muss dem Format {1} entsprechen {2} +items = {0}[{1}]: kein Validator an diesem Index gefunden +maximum = {0} darf den Wert {1} nicht überschreiten +maxItems = {0}: Es dürfen höchstens {1} Elemente in diesem Array sein +maxLength = {0} darf höchstens {1} Zeichen lang sein +maxProperties = {0} darf höchstens {1} Eigenschaften haben +minimum = {0} muss mindestens den Wert {1} haben +minItems = {0} es müssen mindestens {1} Elemente in diesem Array sein +minLength = {0} muss mindestens {1} Zeichen lang sein +minProperties = {0} muss mindestens {1} Eigenschaften haben +multipleOf = {0} muss ein Vielfaches von {1} sein +notAllowed = {0}.{1} ist nicht erlaubt und darf folglich nicht auftreten +not = {0} soll nicht gültig sein für das Schema {1} +oneOf = {0} darf nur für ein einziges Schema {1} gültig sein +patternProperties = {0} stimmt nicht überein mit dem Format definiert in 'pattern properties' +pattern = {0} stimmt nicht mit dem regulären Ausdruck {1} überein +properties = {0}: Ein Fehler mit 'properties' ist aufgetreten +readOnly = {0} ist ein schreibgeschütztes Feld und kann nicht verändert werden +$ref = {0}: Ein Fehler mit 'refs' ist aufgetreten +required = {0}.{1} ist ein Pflichtfeld aber fehlt +type = {0}: {1} wurde gefunden aber {2} erwartet +unionType = {0}: {1} wurde gefunden aber {2} wird verlangt +uniqueItems = {0} die Elemente des Arrays müssen einmalig sein +uuid = {0}: {1} ist ein ungültiges {2} +id = {0}: {1} ist ein ungültiges Segment für die URI {2} +exclusiveMaximum = {0} muss größer sein als {1} +exclusiveMinimum = {0} muss kleiner sein als {1} +false = Boolean schema false is not valid +const = {0} muss den konstanten Wert {1} annehmen +contains = {0} beinhaltet kein Element, das diese Validierung besteht: {1} +propertyNames = Eigenschaftsname {0} ist ungültig für die Validierung: {1} diff --git a/src/test/java/com/networknt/schema/Issue471Test.java b/src/test/java/com/networknt/schema/Issue471Test.java index 04a4303e1..5e264e313 100644 --- a/src/test/java/com/networknt/schema/Issue471Test.java +++ b/src/test/java/com/networknt/schema/Issue471Test.java @@ -11,60 +11,63 @@ import java.util.Locale; import java.util.Map; import java.util.Set; +import java.util.stream.Collectors; public class Issue471Test { + private final String DATA_PATH = "/data/issue471.json"; + private final String SCHEMA_PATH = "/schema/issue471-2019-09.json"; - private JsonSchema getJsonSchemaFromStreamContentV201909(InputStream schemaContent) { - JsonSchemaFactory factory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V201909); - return factory.getSchema(schemaContent); - } - - private JsonNode getJsonNodeFromStreamContent(InputStream content) throws Exception { - ObjectMapper mapper = new ObjectMapper(); - return mapper.readTree(content); - } - - // Only one test method is allowed at a time + // Only one test method is allowed at a time as the ResourceBundle is statically initialized @Test @Disabled public void shouldFailV201909_with_enUS() throws Exception { Locale.setDefault(Locale.US); - Set errors = validate(); - Map errorMsgMap = transferErrorMsg(errors); - Assertions.assertTrue(errorMsgMap.containsKey("$.title"), "error message must contains key: $.title"); - Assertions.assertTrue(errorMsgMap.containsKey("$.pictures"), "error message must contains key: $.pictures"); - Assertions.assertEquals("$.title: may only be 10 characters long", errorMsgMap.get("$.title")); - Assertions.assertEquals("$.pictures: there must be a maximum of 2 items in the array", errorMsgMap.get("$.pictures")); + Map errorsMap = validate(); + Assertions.assertEquals("$.title: may only be 10 characters long", errorsMap.get("$.title")); + Assertions.assertEquals("$.pictures: there must be a maximum of 2 items in the array", errorsMap.get("$.pictures")); } @Test @Disabled public void shouldFailV201909_with_zhCN() throws Exception { Locale.setDefault(Locale.CHINA); - Set errors = validate(); - Map errorMsgMap = transferErrorMsg(errors); - Assertions.assertTrue(errorMsgMap.containsKey("$.title"), "error message must contains key: $.title"); - Assertions.assertTrue(errorMsgMap.containsKey("$.pictures"), "error message must contains key: $.pictures"); - Assertions.assertEquals("$.title:å¯èƒ½åªæœ‰ 10 个字符长", errorMsgMap.get("$.title")); - Assertions.assertEquals("$.pictures:数组中最多必须有 2 个项目", errorMsgMap.get("$.pictures")); + Map errorsMap = validate(); + Assertions.assertEquals("$.title:å¯èƒ½åªæœ‰ 10 个字符长", errorsMap.get("$.title")); + Assertions.assertEquals("$.pictures:数组中最多必须有 2 个项目", errorsMap.get("$.pictures")); + } + + @Test + @Disabled + public void shouldFailV201909_with_deDE() throws Exception { + Locale.setDefault(Locale.GERMANY); + Map errorsMap = validate(); + Assertions.assertEquals("$.title darf höchstens 10 Zeichen lang sein", errorsMap.get("$.title")); + Assertions.assertEquals("$.pictures: Es dürfen höchstens 2 Elemente in diesem Array sein", errorsMap.get("$.pictures")); } - private Set validate() throws Exception { - String schemaPath = "/schema/issue471-2019-09.json"; - String dataPath = "/data/issue471.json"; - InputStream schemaInputStream = Issue471Test.class.getResourceAsStream(schemaPath); + private Map validate() throws Exception { + InputStream schemaInputStream = Issue471Test.class.getResourceAsStream(SCHEMA_PATH); JsonSchema schema = getJsonSchemaFromStreamContentV201909(schemaInputStream); - InputStream dataInputStream = Issue471Test.class.getResourceAsStream(dataPath); + InputStream dataInputStream = Issue471Test.class.getResourceAsStream(DATA_PATH); JsonNode node = getJsonNodeFromStreamContent(dataInputStream); - return schema.validate(node); + + Set validationMessages = schema.validate(node); + return convertValidationMessagesToMap(validationMessages); + } + + private Map convertValidationMessagesToMap(Set validationMessages) { + return validationMessages.stream().collect(Collectors.toMap(ValidationMessage::getPath, ValidationMessage::getMessage)); } - private Map transferErrorMsg(Set validationMessages) { - Map pathToMessage = new HashMap<>(); - validationMessages.forEach(msg -> { - pathToMessage.put(msg.getPath(), msg.getMessage()); - }); - return pathToMessage; + private JsonSchema getJsonSchemaFromStreamContentV201909(InputStream schemaContent) { + JsonSchemaFactory factory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V201909); + return factory.getSchema(schemaContent); } + + private JsonNode getJsonNodeFromStreamContent(InputStream content) throws Exception { + ObjectMapper mapper = new ObjectMapper(); + return mapper.readTree(content); + } + }