Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main/resources/jsv-messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
40 changes: 40 additions & 0 deletions src/main/resources/jsv-messages_de_DE.properties
Original file line number Diff line number Diff line change
@@ -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}
73 changes: 38 additions & 35 deletions src/test/java/com/networknt/schema/Issue471Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<ValidationMessage> errors = validate();
Map<String, String> 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<String, String> 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<ValidationMessage> errors = validate();
Map<String, String> 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<String, String> 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<String, String> 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<ValidationMessage> validate() throws Exception {
String schemaPath = "/schema/issue471-2019-09.json";
String dataPath = "/data/issue471.json";
InputStream schemaInputStream = Issue471Test.class.getResourceAsStream(schemaPath);
private Map<String, String> 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<ValidationMessage> validationMessages = schema.validate(node);
return convertValidationMessagesToMap(validationMessages);
}

private Map<String, String> convertValidationMessagesToMap(Set<ValidationMessage> validationMessages) {
return validationMessages.stream().collect(Collectors.toMap(ValidationMessage::getPath, ValidationMessage::getMessage));
}

private Map<String, String> transferErrorMsg(Set<ValidationMessage> validationMessages) {
Map<String, String> 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);
}

}