Conversion XSD to JSON Schema not as expected
Posted: Sun Oct 10, 2021 6:43 pm
I have used the Oxygen feature to convert an XSD to a JSON Schema. The result is not as expected. I will try to explain the problem.
The XSD for the VraagAfnemer states that the message should contain a data group VraagAfnemer. (The fact that the message and the data group share the same name might be a bit confusing, but I hope this will not hinder the interpretation of the problem.) Below is the XSD. I have left out some irrelevant lines. The XSD refers to other XSD's. Therefore, the XSD does not tell the whole story.)
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:bd="http://data.justid.nl/riga/document/VraagAfnemer-0" xmlns:ccts="urn:un:unece:uncefact:documentation:standard:CoreComponentsTechnicalSpecification:2" xmlns:eMak="http://data.justid.nl/eMak/dictionary-0" xmlns:ebvh="http://data.justid.nl/common/header-3" xmlns:qdt="urn:un:unece:uncefact:data:standard:QualifiedDataType:11" xmlns:udt="urn:un:unece:uncefact:data:standard:UnqualifiedDataType:11" xmlns:xsd="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://data.justid.nl/riga/document/VraagAfnemer-0" version="0.0">
[…]
<!-- ======================================================================= -->
<!-- Element Declarations -->
<!-- ======================================================================= -->
<!-- Root Element -->
<!-- ======================================================================= -->
<xsd:element name="VraagAfnemer" type="bd:VraagAfnemerType">
[…]
</xsd:element>
<!-- ================================================================== -->
<!-- ===== Type Definition ===== -->
<!-- ================================================================== -->
<xsd:complexType name="VraagAfnemerType">
[…]
<xsd:sequence>
<!-- =================================================================== -->
<!-- ===== Standard Header Elements -->
<!-- =================================================================== -->
<xsd:element ref="ebvh:ID"/>
<xsd:element maxOccurs="1" minOccurs="0" ref="ebvh:ReferentieID"/>
<xsd:element maxOccurs="1" minOccurs="0" ref="ebvh:ConversationID"/>
<xsd:element maxOccurs="unbounded" minOccurs="1" ref="ebvh:VerzendendeInstantie"/>
<xsd:element maxOccurs="unbounded" minOccurs="1" ref="ebvh:OntvangendeInstantie"/>
<xsd:element maxOccurs="1" minOccurs="1" ref="ebvh:Datum"/>
<xsd:element maxOccurs="1" minOccurs="1" ref="ebvh:Tijdstip"/>
<xsd:element maxOccurs="1" minOccurs="0" ref="ebvh:TestIndicator"/>
<xsd:element maxOccurs="1" minOccurs="0" ref="ebvh:SchemaVersieID"/>
<!-- =================================================================== -->
<!-- ===== Business Document Content Elements -->
<!-- =================================================================== -->
<xsd:element name="VraagAfnemer" type="eMak:VraagAfnemerType">
[…]
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
Thus, a valid message should start with the header elements, and then it should have an element VraagAfnemer.
The generated JSON Schema does not seem to force that a valid message should have an element VraagAfnemer. The JSON Schema contains an anyOf-block that seems to provide a lot of liberty. Here is the JSON Schema. Again, irrelevant parts are left out:
{
"$schema": "https://json-schema.org/draft-07/schema#",
"$id": "http://data.justid.nl/common/header-3#",
"definitions": {
"VraagAfnemerType2": {
"type": "object",
"required": [
"IdentificatieVraagAfnemerID",
"UitwisselingsthemaCode",
"VraagmodelCode",
"IdentificatieSubject",
"AfnemerInstantie"
],
"properties": {
"IdentificatieVraagAfnemerID": {"type": "string"},
"UitwisselingsthemaCode": {"type": "string"},
"VraagmodelCode": {"type": "string"},
"IndicatieNegeerCacheIndicator": {"type": "boolean"},
"IdentificatieSubject": {
"type": "array",
"items": {"$ref": "#/definitions/IdentificatieSubjectType"},
"minItems": 1
},
"Verwerkingseenheid": {
"type": "array",
"items": {"$ref": "#/definitions/VerwerkingseenheidType"},
"minItems": 0
},
"AfnemerInstantie": {"$ref": "#/definitions/InstantieType2"}
}
},
"VraagAfnemerType": {
"type": "object",
"required": [
"ID",
"VerzendendeInstantie",
"OntvangendeInstantie",
"Datum",
"Tijdstip",
"VraagAfnemer"
],
"properties": {
"ID": {"type": "string"},
"ReferentieID": {"type": "string"},
"ConversationID": {"type": "string"},
"VerzendendeInstantie": {
"type": "array",
"items": {"$ref": "#/definitions/InstantieType"},
"minItems": 1
},
"OntvangendeInstantie": {
"type": "array",
"items": {"$ref": "#/definitions/InstantieType"},
"minItems": 1
},
"Datum": {
"type": "string",
"format": "date"
},
"Tijdstip": {
"type": "string",
"format": "time"
},
"TestIndicator": {"type": "boolean"},
"SchemaVersieID": {"type": "string"},
"VraagAfnemer": {"$ref": "#/definitions/VraagAfnemerType2"}
}
},
"anyOf": [
{
"type": "object",
"properties": {
"VraagAfnemer": {"$ref": "#/definitions/VraagAfnemerType"}
}
},
{
"type": "object",
"properties": {
"ConversationID": {"type": "string"}
}
},
{
"type": "object",
"properties": {
"OntvangendeInstantie": {"$ref": "#/definitions/InstantieType"}
}
},
{
"type": "object",
"properties": {
"VerzendendeInstantie": {"$ref": "#/definitions/InstantieType"}
}
},
{
"type": "object",
"properties": {
"Datum": {
"type": "string",
"format": "date"
}
}
},
{
"type": "object",
"properties": {
"TestIndicator": {"type": "boolean"}
}
},
{
"type": "object",
"properties": {
"ReferentieID": {"type": "string"}
}
},
{
"type": "object",
"properties": {
"ID": {"type": "string"}
}
},
{
"type": "object",
"properties": {
"SchemaVersieID": {"type": "string"}
}
},
{
"type": "object",
"properties": {
"Tijdstip": {
"type": "string",
"format": "time"
}
}
},
{
"type": "object",
"properties": {
"AgencyIdentificationCode": {"$ref": "#/definitions/AgencyIdentificationCodeContentType"}
}
},
{
"type": "object",
"properties": {
"TINSTANTIE": {"type": "string"}
}
},
{
"type": "object",
"properties": {
"VraagAfnemer": {"$ref": "#/definitions/VraagAfnemerType2"}
}
},
{
"type": "object",
"properties": {
"IdentificatieSubject": {"$ref": "#/definitions/IdentificatieSubjectType"}
}
},
{
"type": "object",
"properties": {
"Verwerkingseenheid": {"$ref": "#/definitions/VerwerkingseenheidType"}
}
},
{
"type": "object",
"properties": {
"Verwerkingscategorie": {"$ref": "#/definitions/VerwerkingscategorieType"}
}
},
{
"type": "object",
"properties": {
"Instantie": {"$ref": "#/definitions/InstantieType2"}
}
}
]
}
(Note that the JSON Schema contains a VraagAfnemerType and a VraagAfnemerType (for the message as a whole) and a VraagAfnemerType2 (for the data group VraagAfnemer.))
Why is this? Why does the JSON Schema not force that a valid message should have a group VraagAfnemer?
I must admit that I am not experienced in using JSON and JSON Schema. Therefore, it might be that I a missing a point somewhere.
I hope anyone can help me out. As long as this problem still exists, the JSON Schema is worthless for us.
The XSD for the VraagAfnemer states that the message should contain a data group VraagAfnemer. (The fact that the message and the data group share the same name might be a bit confusing, but I hope this will not hinder the interpretation of the problem.) Below is the XSD. I have left out some irrelevant lines. The XSD refers to other XSD's. Therefore, the XSD does not tell the whole story.)
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:bd="http://data.justid.nl/riga/document/VraagAfnemer-0" xmlns:ccts="urn:un:unece:uncefact:documentation:standard:CoreComponentsTechnicalSpecification:2" xmlns:eMak="http://data.justid.nl/eMak/dictionary-0" xmlns:ebvh="http://data.justid.nl/common/header-3" xmlns:qdt="urn:un:unece:uncefact:data:standard:QualifiedDataType:11" xmlns:udt="urn:un:unece:uncefact:data:standard:UnqualifiedDataType:11" xmlns:xsd="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://data.justid.nl/riga/document/VraagAfnemer-0" version="0.0">
[…]
<!-- ======================================================================= -->
<!-- Element Declarations -->
<!-- ======================================================================= -->
<!-- Root Element -->
<!-- ======================================================================= -->
<xsd:element name="VraagAfnemer" type="bd:VraagAfnemerType">
[…]
</xsd:element>
<!-- ================================================================== -->
<!-- ===== Type Definition ===== -->
<!-- ================================================================== -->
<xsd:complexType name="VraagAfnemerType">
[…]
<xsd:sequence>
<!-- =================================================================== -->
<!-- ===== Standard Header Elements -->
<!-- =================================================================== -->
<xsd:element ref="ebvh:ID"/>
<xsd:element maxOccurs="1" minOccurs="0" ref="ebvh:ReferentieID"/>
<xsd:element maxOccurs="1" minOccurs="0" ref="ebvh:ConversationID"/>
<xsd:element maxOccurs="unbounded" minOccurs="1" ref="ebvh:VerzendendeInstantie"/>
<xsd:element maxOccurs="unbounded" minOccurs="1" ref="ebvh:OntvangendeInstantie"/>
<xsd:element maxOccurs="1" minOccurs="1" ref="ebvh:Datum"/>
<xsd:element maxOccurs="1" minOccurs="1" ref="ebvh:Tijdstip"/>
<xsd:element maxOccurs="1" minOccurs="0" ref="ebvh:TestIndicator"/>
<xsd:element maxOccurs="1" minOccurs="0" ref="ebvh:SchemaVersieID"/>
<!-- =================================================================== -->
<!-- ===== Business Document Content Elements -->
<!-- =================================================================== -->
<xsd:element name="VraagAfnemer" type="eMak:VraagAfnemerType">
[…]
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
Thus, a valid message should start with the header elements, and then it should have an element VraagAfnemer.
The generated JSON Schema does not seem to force that a valid message should have an element VraagAfnemer. The JSON Schema contains an anyOf-block that seems to provide a lot of liberty. Here is the JSON Schema. Again, irrelevant parts are left out:
{
"$schema": "https://json-schema.org/draft-07/schema#",
"$id": "http://data.justid.nl/common/header-3#",
"definitions": {
"VraagAfnemerType2": {
"type": "object",
"required": [
"IdentificatieVraagAfnemerID",
"UitwisselingsthemaCode",
"VraagmodelCode",
"IdentificatieSubject",
"AfnemerInstantie"
],
"properties": {
"IdentificatieVraagAfnemerID": {"type": "string"},
"UitwisselingsthemaCode": {"type": "string"},
"VraagmodelCode": {"type": "string"},
"IndicatieNegeerCacheIndicator": {"type": "boolean"},
"IdentificatieSubject": {
"type": "array",
"items": {"$ref": "#/definitions/IdentificatieSubjectType"},
"minItems": 1
},
"Verwerkingseenheid": {
"type": "array",
"items": {"$ref": "#/definitions/VerwerkingseenheidType"},
"minItems": 0
},
"AfnemerInstantie": {"$ref": "#/definitions/InstantieType2"}
}
},
"VraagAfnemerType": {
"type": "object",
"required": [
"ID",
"VerzendendeInstantie",
"OntvangendeInstantie",
"Datum",
"Tijdstip",
"VraagAfnemer"
],
"properties": {
"ID": {"type": "string"},
"ReferentieID": {"type": "string"},
"ConversationID": {"type": "string"},
"VerzendendeInstantie": {
"type": "array",
"items": {"$ref": "#/definitions/InstantieType"},
"minItems": 1
},
"OntvangendeInstantie": {
"type": "array",
"items": {"$ref": "#/definitions/InstantieType"},
"minItems": 1
},
"Datum": {
"type": "string",
"format": "date"
},
"Tijdstip": {
"type": "string",
"format": "time"
},
"TestIndicator": {"type": "boolean"},
"SchemaVersieID": {"type": "string"},
"VraagAfnemer": {"$ref": "#/definitions/VraagAfnemerType2"}
}
},
"anyOf": [
{
"type": "object",
"properties": {
"VraagAfnemer": {"$ref": "#/definitions/VraagAfnemerType"}
}
},
{
"type": "object",
"properties": {
"ConversationID": {"type": "string"}
}
},
{
"type": "object",
"properties": {
"OntvangendeInstantie": {"$ref": "#/definitions/InstantieType"}
}
},
{
"type": "object",
"properties": {
"VerzendendeInstantie": {"$ref": "#/definitions/InstantieType"}
}
},
{
"type": "object",
"properties": {
"Datum": {
"type": "string",
"format": "date"
}
}
},
{
"type": "object",
"properties": {
"TestIndicator": {"type": "boolean"}
}
},
{
"type": "object",
"properties": {
"ReferentieID": {"type": "string"}
}
},
{
"type": "object",
"properties": {
"ID": {"type": "string"}
}
},
{
"type": "object",
"properties": {
"SchemaVersieID": {"type": "string"}
}
},
{
"type": "object",
"properties": {
"Tijdstip": {
"type": "string",
"format": "time"
}
}
},
{
"type": "object",
"properties": {
"AgencyIdentificationCode": {"$ref": "#/definitions/AgencyIdentificationCodeContentType"}
}
},
{
"type": "object",
"properties": {
"TINSTANTIE": {"type": "string"}
}
},
{
"type": "object",
"properties": {
"VraagAfnemer": {"$ref": "#/definitions/VraagAfnemerType2"}
}
},
{
"type": "object",
"properties": {
"IdentificatieSubject": {"$ref": "#/definitions/IdentificatieSubjectType"}
}
},
{
"type": "object",
"properties": {
"Verwerkingseenheid": {"$ref": "#/definitions/VerwerkingseenheidType"}
}
},
{
"type": "object",
"properties": {
"Verwerkingscategorie": {"$ref": "#/definitions/VerwerkingscategorieType"}
}
},
{
"type": "object",
"properties": {
"Instantie": {"$ref": "#/definitions/InstantieType2"}
}
}
]
}
(Note that the JSON Schema contains a VraagAfnemerType and a VraagAfnemerType (for the message as a whole) and a VraagAfnemerType2 (for the data group VraagAfnemer.))
Why is this? Why does the JSON Schema not force that a valid message should have a group VraagAfnemer?
I must admit that I am not experienced in using JSON and JSON Schema. Therefore, it might be that I a missing a point somewhere.
I hope anyone can help me out. As long as this problem still exists, the JSON Schema is worthless for us.