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

Translate conditional requirements into JSON schema #32

Open
nealkruis opened this issue Feb 17, 2021 · 1 comment
Open

Translate conditional requirements into JSON schema #32

nealkruis opened this issue Feb 17, 2021 · 1 comment
Assignees

Comments

@nealkruis
Copy link
Contributor

Here's a helpful post on the capabilities in JSON schema.

Here are the cases to handle:

Is defined

a:
  Data Type: "Boolean"
  Required: True
b:
  Data Type: "Numeric"  
  Required: "if a"
c:
  Data Type: "Numeric"  
  Required: True

gives

{
  "type": "object",
  "properties": {
    "a": { "type": "boolean" },
    "b": { "type": "number" },
    "c": { "type": "number" }
  },
  "required": ["a", "c"],
  "dependencies": {
    "a": ["b"]
  }
}

Is equal

a:
  Data Type: "Boolean"
  Required: True
b:
  Data Type: "Numeric"  
  Required: "if a=False"
c:
  Data Type: "Numeric"  
  Required: True

gives

{
  "type": "object",
  "properties": {
    "a": { "type": "boolean" },
    "b": { "type": "number" },
    "c": { "type": "number" }
  },
  "required": ["a", "c"],
  "if": {
      "properties": {
        "a": { "const": false} 
      }
  },
  "then": { "required": ["b"] }
}

Is not equal

a:
  Data Type: "Boolean"
  Required: True
b:
  Data Type: "Numeric"  
  Required: "if a!=False"
c:
  Data Type: "Numeric"  
  Required: True

gives

{
  "type": "object",
  "properties": {
    "a": { "type": "boolean" },
    "b": { "type": "number" },
    "c": { "type": "number" }
  },
  "required": ["a", "c"],
  "if": {
      "properties": {
        "a": { "not": {"const": false} }
      }
  },
  "then": { "required": ["b"] }
}

We may be able to find ways to combine these too. But I think covering these cases for now should be fine.

@nealkruis
Copy link
Contributor Author

@tanaya-bigladder I started a branch called conditional-requirements for this change.

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