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 theVariableName
element - Some
Variable
nodes will have aVariableValue
element Variable
Nodes that have theVariableValue
element cannot have theValueMask
,Prefix
,RangeStart
,RangeEnd
, andSuffix
elements- Some
Variable
nodes will have theRangeStart
andRangeEnd
elements Varaible
Nodes that have theRangeStart
andRangeEnd
elements may also have theValueMask
,Prefix
, and/orSuffix
elements.Variable
Nodex that have theRangeStart
andRangeEnd
elements cannot have theVariableValue
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"
}
}
}