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

UUID in enum fails validation #679

Closed
JosefWN opened this issue Jan 23, 2025 · 2 comments
Closed

UUID in enum fails validation #679

JosefWN opened this issue Jan 23, 2025 · 2 comments

Comments

@JosefWN
Copy link

JosefWN commented Jan 23, 2025

Schema:

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "source": {
      "oneOf": [{ "const": "parent" }, { "type": "string", "format": "uuid" }]
    }
  }
}

Data:

{
  "source": "parent"
}

Output:

data.json - INVALID. Errors:
1. "parent" is valid under more than one of the schemas listed in the 'oneOf' keyword

I would say there is no ambiguity preventing differentiation between a UUID and "parent"?

Regex:

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "source": {
      "oneOf": [
        { "const": "parent" },
        {
          "type": "string",
          "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$"
        }
      ]
    }
  }
}

Works.

As an aside, finding the issue in the first place was a bit of a struggle, so +1 for this: #649

@Stranger6667
Copy link
Owner

Hi! Thanks for opening this

Indeed, the oneOf validation results are really not intuitive. I'll add a note to the docs until they are not good enough.

The validation fails because format is an annotation, not an assertion (for Draft 2020-12), and you need to enable format validation explicitly. I am going to update the docs on this matter too

@JosefWN
Copy link
Author

JosefWN commented Jan 23, 2025

Thanks for the swift response (and for your work on jsonschema), closing this!

@JosefWN JosefWN closed this as completed Jan 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants