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

Feature Request: provide ref-like path for allOf/oneOf matches if validation fails. #298

Closed
adamaig-verve opened this issue Jan 22, 2016 · 1 comment

Comments

@adamaig-verve
Copy link

While wanting to determine programmatically why allOf and oneOf constraints are failing, I'm really wishing that the sub-schema paths that are matched could be returned. For example, given the schema below, and this input:

{
  "action_1":"call",
  "value_1":"111-2233",
  "action_2":"visit",
  "value_2":"123"
}

an error message like this would be useful: "Data does not match any schemas from /allOf/1/oneOf" (derived from http://jsonvalidate.com/)

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "required": ["action_1", "action_2"],
  "properties": {
    "action_1": {
      "enum": ["call", "visit"]
    },
    "value_1": {
      "type": "string"
    },
    "action_2": {
      "enum": ["call", "visit"]
    },
    "value_2": {
      "type": "string"
    }
  },
  "allOf": [{
    "type": "object",
    "oneOf": [{
      "type": "object",
      "properties": {
        "action_1": {
          "enum": ["call"]
        },
        "value_1": {
          "pattern": "^[0-9]{3}-[0-9]{4}$"
        }
      }
    }, {
      "type": "object",
      "properties": {
        "action_1": {
          "enum": ["visit"]
        },
        "value_1": {
          "pattern": "^http"
        }
      }
    }]
  }, {
    "type": "object",
    "oneOf": [{
      "type": "object",
      "properties": {
        "action_2": {
          "enum": ["call"]
        },
        "value_2": {
          "pattern": "^[0-9]{3}-[0-9]{4}$"
        }
      }
    }, {
      "type": "object",
      "properties": {
        "action_2": {
          "enum": ["visit"]
        },
        "value_2": {
          "pattern": "^http"
        }
      }
    }]
  }]
}

Currently the message returned is: "The property '#/' of type Hash did not match all of the required schemas in schema ..." Having the more specific validation failure path would allow clients to determine a closer neighborhood of failure in order to provide better feedback to users.

@adamaig-verve
Copy link
Author

I realized this morning that this is already accessible via the object errors. Closing.

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

1 participant