Skip to content

Commit 81b9986

Browse files
committed
Fix enum
1 parent f9dbc78 commit 81b9986

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

src/main/java/com/networknt/schema/utils/JsonNodeTypes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public static boolean equalsToSchemaType(JsonNode node, JsonType schemaType, Sch
4949

5050
// Skip the type validation when the schema is an enum object schema. Since the current type
5151
// of node itself can be used for type validation.
52-
if (isEnumObjectSchema(parentSchema)) {
52+
if (isEnumObjectSchema(parentSchema) && !config.isStrict("type", Boolean.TRUE)) {
5353
return true;
5454
}
5555
if (config != null && config.isTypeLoose()) {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ private DynamicNode buildContainer(SpecificationVersion defaultVersion, TestCase
183183
@SuppressWarnings("deprecation") boolean typeLoose = testSpec.isTypeLoose();
184184

185185
SchemaRegistryConfig.Builder configBuilder = SchemaRegistryConfig.builder();
186+
configBuilder.strict("type", false);
186187
configBuilder.typeLoose(typeLoose);
187188
configBuilder.regularExpressionFactory(
188189
TestSpec.RegexKind.JDK == testSpec.getRegex() ? JDKRegularExpressionFactory.getInstance()

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import com.fasterxml.jackson.databind.JsonNode;
44
import com.fasterxml.jackson.databind.ObjectMapper;
5-
import org.junit.jupiter.api.Assertions;
5+
import static org.junit.jupiter.api.Assertions.assertEquals;
66
import org.junit.jupiter.api.Test;
77

88
import java.io.InputStream;
@@ -29,7 +29,11 @@ void expectObjectNotIntegerV7() throws Exception {
2929
InputStream dataInputStream = getClass().getResourceAsStream(dataPath);
3030
JsonNode node = getJsonNodeFromStreamContent(dataInputStream);
3131
List<Error> errors = schema.validate(node);
32-
Assertions.assertEquals(0, errors.size());
32+
assertEquals(1, errors.size());
33+
assertEquals("type", errors.get(0).getKeyword());
34+
assertEquals("/bar", errors.get(0).getInstanceLocation().toString());
35+
assertEquals("/properties/bar/$ref/type", errors.get(0).getEvaluationPath().toString());
36+
assertEquals("https://example.com/address.schema.json#/properties/foo/type", errors.get(0).getSchemaLocation().toString());
3337
}
3438

3539
}

0 commit comments

Comments
 (0)