Altinn / altinn-studio

Next generation open source Altinn platform and applications.
https://docs.altinn.studio
BSD 3-Clause "New" or "Revised" License
111 stars 70 forks source link

Array limits are not in sync with custom keywords. #9435

Closed mirkoSekulic closed 1 year ago

mirkoSekulic commented 1 year ago

Description of the bug

When xds with specified min and max occurs is uploaded, it converts to JsonSchema with @xsdMinOccurs and @xsdMaxOccurs custom keywords. Those keywords have highest priority for setting up min and max occurs attributes in conversion to c#, and if present, minItems and maxItems keywords are overridden when converting back to xsd. This is problematic when min/max Items are changed after upload. Here is example problematic json schema:

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "schema.json",
  "type": "object",
  "properties": {
    "stringArray": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "minItems": 2,
      "maxItems": 5,
      "@xsdMinOccurs": 3,
      "@xsdMaxOccurs": "4"
    }
  },
  "required": [
    "stringArray"
  ]
}

converts to following xsd:

<?xml version="1.0" encoding="utf-16"?>
<xsd:schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xs:element name="root">
    <xs:complexType>
      <xs:sequence>
        <xs:element minOccurs="3" maxOccurs="4" name="stringArray" type="xs:string" />
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xsd:schema>

Proposed solutions:

Note

Keep in mind that value of @xsdMaxOccurs is string since it can have "unbounded" value.

Steps To Reproduce

Upload xsd containing minOccurs or maxOccurs attributes, and than update array limits in datamodeling tool. Produced xsd won't be changed.

Additional Information

No response

mijohansen commented 1 year ago

This should be fixed in the backend part of the code, right?