Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Since 1.3.0: Validation fails on keyword 'uuid' #939

Closed
rainer-wei opened this issue Jan 29, 2024 · 1 comment · Fixed by #942
Closed

Since 1.3.0: Validation fails on keyword 'uuid' #939

rainer-wei opened this issue Jan 29, 2024 · 1 comment · Fixed by #942

Comments

@rainer-wei
Copy link

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.

@justin-tay
Copy link
Contributor

This will be fixed in the next version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants