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

validation error reported onOf object incorrectly #382

Closed
ClementMindflow opened this issue Mar 27, 2023 · 3 comments
Closed

validation error reported onOf object incorrectly #382

ClementMindflow opened this issue Mar 27, 2023 · 3 comments

Comments

@ClementMindflow
Copy link

ClementMindflow commented Mar 27, 2023

Hello !

When validating a schema containing a onOf where two of the items are similar, an error is reported even if the value match the expected format.

For example, validating the value { type: "json", value: "{\n \n}" } against this schema:

{
  title: "Test Schema",
  oneOf: [
    {
      $ref: "#/definitions/schema-A"
    },
    {
      $ref: "#/definitions/schema-B"
    }
  ],
  definitions: {
    "schema-A": {
      type: "object",
      required: ["type", "value"],
      properties: {
        type: {
          type: "string",
          default: "json"
        },
        value: {
          title: "JSON content",
          type: "string",
          default: "{\n \n}"
        }
      }
    },
    "schema-B": {
      type: "object",
      required: ["type", "value"],
      properties: {
        type: {
          type: "string",
          default: "text"
        },
        value: {
          title: "Text content",
          type: "string"
        }
      }
    }
  }
}

report the following error: is not exactly one from <#/definitions/schema-A>,<#/definitions/schema-B>

See this codepen for a reproduction scenario.

@ClementMindflow ClementMindflow changed the title validation error reported on off object incorrectly validation error reported onOff object incorrectly Mar 27, 2023
@semicullen
Copy link

I assume you mean oneOf, not onOff.

@ninthclowd
Copy link

I'm having the same issue. Getting:
{
"property": "instance",
"message": "is not exactly one from "TYPE A","TYPE B""
}
when the schema is defined as "oneOf": [...]

@ClementMindflow ClementMindflow changed the title validation error reported onOff object incorrectly validation error reported onOf object incorrectly Apr 25, 2024
@ClementMindflow
Copy link
Author

I came back here after a while...
The issue did not came from the validation lib but from a misunderstanding about how oneOf were supposed to work.
The spec say that the value should match one and exactly one schema in the list.
And that care should be taken when crafting schemas inside a oneOf so they are not "structurally equivalent".
Which is not the case here.

Closing this ticket.

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

3 participants