jsonix-schema-compiler icon indicating copy to clipboard operation
jsonix-schema-compiler copied to clipboard

xsd choice with an element and a sequence generates an array type!

Open veepuris opened this issue 9 years ago • 2 comments
trafficstars

Please see the Input XSD and the Output JSON below. The "BackStub" is a choice between a single element("None") and a sequence("Period", "Calculation"). However, the generated JSON schema suggests the "BackStub" is an array with minItems=1 & maxItems=2. This seems wrong to me, could you please advise?

Input XSD:

<xsd:complexType name="FloatingLegStubs">
    <xsd:sequence>
        <xsd:element name="FrontStub">
            <xsd:complexType>
                <xsd:choice>
                    <xsd:element name="None" type="ctr:None"/>
                    <xsd:sequence>
                        <xsd:element name="Period" type="ctr:FrontStubPeriod"/>
                        <xsd:element name="Calculation" type="ctr:StubCalculationStyle"/>
                    </xsd:sequence>
                </xsd:choice>
            </xsd:complexType>
        </xsd:element>
        <xsd:element name="BackStub">
            <xsd:complexType>
                <xsd:choice>
                    <xsd:element name="None" type="ctr:None"/>
                    <xsd:sequence>
                        <xsd:element name="Period" type="ctr:BackStubPeriod"/>
                        <xsd:element name="Calculation" type="ctr:StubCalculationStyle"/>
                    </xsd:sequence>
                </xsd:choice>
            </xsd:complexType>
        </xsd:element>
    </xsd:sequence>
</xsd:complexType>

Output JSON:

    "FloatingLegStubs.BackStub":{
        "type":"object",
        "title":"FloatingLegStubs.BackStub",
        "required":[
            "noneOrPeriodAndCalculation"
        ],
        "properties":{
            "noneOrPeriodAndCalculation":{
                "title":"noneOrPeriodAndCalculation",
                "allOf":[
                    {
                        "type":"array",
                        "items":{
                            "anyOf":[
                                {
                                    "anyOf":[
                                        {
                                            "$ref":"#/definitions/None"
                                        }
                                    ],
                                    "elementName":{
                                        "localPart":"None",
                                        "namespaceURI":""
                                    }
                                },
                                {
                                    "anyOf":[
                                        {
                                            "$ref":"#/definitions/BackStubPeriod"
                                        }
                                    ],
                                    "elementName":{
                                        "localPart":"Period",
                                        "namespaceURI":""
                                    }
                                },
                                {
                                    "anyOf":[
                                        {
                                            "$ref":"#/definitions/StubCalculationStyle"
                                        }
                                    ],
                                    "elementName":{
                                        "localPart":"Calculation",
                                        "namespaceURI":""
                                    }
                                }
                            ]
                        },
                        "maxItems":2,
                        "minItems":1
                    }
                ],
                "propertyType":"elements"
            }
        },
        "typeType":"classInfo",
        "propertiesOrder":[
            "noneOrPeriodAndCalculation"
        ]
    }

veepuris avatar Jun 23 '16 10:06 veepuris

Why (or what exactly) do you think it is wrong? Cardinality is correct, minimum is 1 element, maximum is 2 (Period, Calculation).

highsource avatar Jun 24 '16 08:06 highsource

In my opinion, the representation is a bit misleading and cardinality is not of much help.

type:array items/anyOf: [{None}, {Period}, {calculation}] minItems:1 maxItems:2

Based on the excerpt from the above JSON, it appears the array can possibly contain 2 "None" elements or 1 "Period" or 1 "Calculation" element which is incorrect..

veepuris avatar Jun 24 '16 10:06 veepuris