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

invalid use of oneOf #23

Open
epugh opened this issue Aug 23, 2024 · 1 comment
Open

invalid use of oneOf #23

epugh opened this issue Aug 23, 2024 · 1 comment
Assignees

Comments

@epugh
Copy link
Member

epugh commented Aug 23, 2024

From the JSONSchema community Slack -->

One thing I noticed is invalid use of oneOf on this line. https://github.com/o19s/ubi/blob/main/schema%2F1.0.0%2Fquery.response.schema.json#L11
JSON Schema validation does not evaluate the format keyword to distinguish strings. The format keyword is referred to as an annotation and is only informational.
You might try something like this.

{
  "query_id": { 
    "type": "string",
    "oneOf":[
      { "pattern": "pattern for <uuid>"},
      {"not":{ "pattern": "pattern for <uuid>", "maxLength": 100}}
    ]
  }
}
@epugh epugh self-assigned this Aug 29, 2024
@russcam
Copy link

russcam commented Dec 13, 2024

A question I have is if the oneOf provides value. In the linked schema

"oneOf": [
        {
          "type": "string",
          "format": "uuid",
          "examples": ["00112233-4455-6677-8899-aabbccddeeff"]
        },
        {
          "type": "string",
          "maxLength": 100,
          "examples": ["1234-user-5678"]
        }
      ]

The bottom schema is sufficient to cover both, and a consumer of a query response JSON wouldn't know if the "query_id" is a UUID without inspecting it (or trying to parse it).

Is there some value that having the distinction provides?

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