-
Notifications
You must be signed in to change notification settings - Fork 330
Closed
Description
The following code example fails with 1.3.0:
import com.networknt.schema.InputFormat;
import com.networknt.schema.JsonSchemaFactory;
import com.networknt.schema.SpecVersion;
import org.junit.jupiter.api.Assertions;
import java.util.UUID;
public class JsonSchemaValidatorTest {
public static void main(String[] args) {
var schemaString = """
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"additionalProperties": false,
"required": [
"someUuid"
],
"properties": {
"someUuid": {
"$ref": "#/definitions/uuid"
}
},
"definitions": {
"uuid": {
"type": "string",
"pattern": "^[0-9a-f]{8}(\\\\-[0-9a-f]{4}){3}\\\\-[0-9a-f]{12}$",
"minLength": 36,
"maxLength": 36
}
}
}
""";
var factory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V7);
var jsonSchema = factory.getSchema(schemaString);
var json = "{\"someUuid\": \"" + UUID.randomUUID() + "\"}";
var validationMessages = jsonSchema.validate(json, InputFormat.JSON);
Assertions.assertTrue(validationMessages.isEmpty());
}
}
Caused by: java.lang.UnsupportedOperationException: No suitable validator for uuid
at com.networknt.schema.ValidatorTypeCode.newValidator(ValidatorTypeCode.java:161)
at com.networknt.schema.JsonMetaSchema.newValidator(JsonMetaSchema.java:323)
... 25 more
Renaming the definition reference to something like uuid-string
can be used as workaround.
Metadata
Metadata
Assignees
Labels
No labels