Skip to content

Commit 64f6367

Browse files
committed
fixes #203 String for Number should fail with the default SchemaValidatorsConfig
1 parent 5788bba commit 64f6367

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

src/main/java/com/networknt/schema/SchemaValidatorsConfig.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,5 @@ public void setHandleNullableField(boolean handleNullableField) {
8888
}
8989

9090
public SchemaValidatorsConfig() {
91-
loadDefaultConfig();
92-
}
93-
94-
private void loadDefaultConfig() {
95-
this.typeLoose = true;
96-
this.uriMappings = new HashMap<String, String>();
9791
}
9892
}

src/test/java/com/networknt/schema/MaximumValidatorTest.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,10 @@ public void negativeDoubleOverflowTest() throws IOException {
185185
String maximum = aTestCycle[0];
186186
String value = aTestCycle[1];
187187
String schema = format(NUMBER, maximum);
188-
188+
SchemaValidatorsConfig config = new SchemaValidatorsConfig();
189+
config.setTypeLoose(true);
189190
// Schema and document parsed with just double
190-
JsonSchema v = factory.getSchema(mapper.readTree(schema));
191+
JsonSchema v = factory.getSchema(mapper.readTree(schema), config);
191192
JsonNode doc = mapper.readTree(value);
192193
Set<ValidationMessage> messages = v.validate(doc);
193194
assertTrue(format("Maximum %s and value %s are interpreted as Infinity, thus no schema violation should be reported", maximum, value), messages.isEmpty());
@@ -204,7 +205,7 @@ public void negativeDoubleOverflowTest() throws IOException {
204205

205206

206207
// schema and document parsed with BigDecimal
207-
v = factory.getSchema(bigDecimalMapper.readTree(schema));
208+
v = factory.getSchema(bigDecimalMapper.readTree(schema), config);
208209
Set<ValidationMessage> messages3 = v.validate(doc);
209210
//when the schema and value are both using BigDecimal, the value should be parsed in same mechanism.
210211
if(maximum.toLowerCase().equals(value.toLowerCase()) || Double.valueOf(maximum).equals(Double.POSITIVE_INFINITY)) {
@@ -291,8 +292,10 @@ private static void expectNoMessages(String[][] values, String schemaTemplate, O
291292
String maximum = aTestCycle[0];
292293
String value = aTestCycle[1];
293294
String schema = format(schemaTemplate, maximum);
295+
SchemaValidatorsConfig config = new SchemaValidatorsConfig();
296+
config.setTypeLoose(true);
294297

295-
JsonSchema v = factory.getSchema(mapper.readTree(schema));
298+
JsonSchema v = factory.getSchema(mapper.readTree(schema), config);
296299
JsonNode doc = mapper.readTree(value);
297300

298301
Set<ValidationMessage> messages = v.validate(doc);

src/test/java/com/networknt/schema/MinimumValidatorTest.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,11 @@ public void negativeDoubleOverflowTest() throws IOException {
171171
String minimum = aTestCycle[0];
172172
String value = aTestCycle[1];
173173
String schema = format(NUMBER, minimum);
174+
SchemaValidatorsConfig config = new SchemaValidatorsConfig();
175+
config.setTypeLoose(true);
174176

175177
// Schema and document parsed with just double
176-
JsonSchema v = factory.getSchema(mapper.readTree(schema));
178+
JsonSchema v = factory.getSchema(mapper.readTree(schema), config);
177179
JsonNode doc = mapper.readTree(value);
178180
Set<ValidationMessage> messages = v.validate(doc);
179181
assertTrue(format("Minimum %s and value %s are interpreted as Infinity, thus no schema violation should be reported", minimum, value), messages.isEmpty());
@@ -194,7 +196,7 @@ public void negativeDoubleOverflowTest() throws IOException {
194196
}
195197

196198
// schema and document parsed with BigDecimal
197-
v = factory.getSchema(bigDecimalMapper.readTree(schema));
199+
v = factory.getSchema(bigDecimalMapper.readTree(schema), config);
198200
Set<ValidationMessage> messages3 = v.validate(doc);
199201
//when the schema and value are both using BigDecimal, the value should be parsed in same mechanism.
200202
if(minimum.toLowerCase().equals(value.toLowerCase()) || Double.valueOf(minimum).equals(Double.NEGATIVE_INFINITY)) {
@@ -282,8 +284,10 @@ private void expectNoMessages(String[][] values, String integer, ObjectMapper ma
282284
String minimum = aTestCycle[0];
283285
String value = aTestCycle[1];
284286
String schema = format(integer, minimum);
287+
SchemaValidatorsConfig config = new SchemaValidatorsConfig();
288+
config.setTypeLoose(true);
285289

286-
JsonSchema v = factory.getSchema(mapper.readTree(schema));
290+
JsonSchema v = factory.getSchema(mapper.readTree(schema), config);
287291
JsonNode doc = bigIntegerMapper.readTree(value);
288292

289293
Set<ValidationMessage> messages = v.validate(doc);

0 commit comments

Comments
 (0)