0

I'm wanting to replicate the following XSD in json schema:

  <xs:element maxOccurs="unbounded" name="Variable" minOccurs="0">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="VariableName" type="xs:string" />
        <xs:choice maxOccurs="1">
          <xs:sequence>
            <xs:element name="VariableValue" type="xs:string" />
          </xs:sequence>
          <xs:sequence>
            <xs:element name="ValueMask" type="xs:string" minOccurs="0" maxOccurs="1" />
            <xs:element name="Prefix" type="xs:string" minOccurs="0" maxOccurs="1" />
            <xs:element name="RangeStart" type="xs:int" />
            <xs:element name="RangeEnd" type="xs:int" />
            <xs:element name="Suffix" type="xs:string" minOccurs="0" maxOccurs="1" />
          </xs:sequence>
        </xs:choice>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

this XSD has the following requirements:

  • All Variable nodes will have the VariableName element
  • Some Variable nodes will have a VariableValue element
  • Variable Nodes that have the VariableValue element cannot have the ValueMask, Prefix, RangeStart, RangeEnd, and Suffix elements
  • Some Variable nodes will have the RangeStart and RangeEnd elements
  • Varaible Nodes that have the RangeStart and RangeEnd elements may also have the ValueMask, Prefix, and/or Suffix elements.
  • Variable Nodex that have the RangeStart and RangeEnd elements cannot have the VariableValue element.

I've seen a similar question on here, but it has the "additionalProperties": false attribute on it that would prevent the optional use of ValueMask, Prefix, and/or Suffix when opting for option 2.

Does anybody know how to implement these requirements in JSON schema?

Here is the current JSON I am working with: (Please excuse the comments, I know they aren't valid JSON)

{
  "type": "object",
  "properties": {
    "variableName": {
      "type": "string"
    },

    //this
    "variableValue": {
      "type": "string"
    },

    //or that
    "valueMask": {
      "type": "string"
    },
    "prefix": {
      "type": "string"
    },
    "rangeStart": {
      "type": "integer"
    },
    "rangeEnd": {
      "type": "integer"
    },
    "suffix": {
      "type": "string"
    }
  }
}
Oxymoron
  • 1,380
  • 2
  • 19
  • 47
  • I've dont additional research and found this quesiton: https://stackoverflow.com/questions/50881764/mutually-exclusive-combinations-of-properties However it violates the DRY principal. If this ends up being the case then I will open an issue on the github issue tracker. – Oxymoron Jul 26 '18 at 00:13
  • All the techniques you need to solve this can be found here https://stackoverflow.com/questions/38717933/jsonschema-attribute-conditionally-required – Jason Desrosiers Jul 26 '18 at 00:42

0 Answers0