Skip to content

IDS: loading fails when a restriction has a single xs:enumeration or xs:pattern #867

Open

Description

@havs-mc

IDSSpecifications.load throws on a valid IDS file when a value restriction has exactly one
xs:enumeration:

TypeError: restriction.enumeration.map is not a function
    at getParameterValue (importers/parameter.ts)
    at createPropertyFacets
    at IDSSpecifications.load

fast-xml-parser returns a repeated child as an array but a single child as an object, and
getParameterValue assumes an array. The IDS 1.0 XSD allows one or more enumerations, and
a one-value list is common in generated files, for example an allowed-values list that
happens to hold one value.

xs:pattern has the mirror problem: one pattern is read through restriction.pattern.value,
but several patterns arrive as an array, so .value is undefined.

Minimal IDS:

<ids:ids xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ids="http://standards.buildingsmart.org/IDS">
  <ids:info><ids:title>Single enumeration</ids:title></ids:info>
  <ids:specifications>
    <ids:specification name="Walls" ifcVersion="IFC4">
      <ids:applicability minOccurs="0" maxOccurs="unbounded">
        <ids:entity><ids:name><ids:simpleValue>IFCWALL</ids:simpleValue></ids:name></ids:entity>
      </ids:applicability>
      <ids:requirements>
        <ids:property dataType="IFCLABEL">
          <ids:propertySet><ids:simpleValue>Pset_WallCommon</ids:simpleValue></ids:propertySet>
          <ids:baseName><ids:simpleValue>Reference</ids:simpleValue></ids:baseName>
          <ids:value>
            <xs:restriction base="xs:string"><xs:enumeration value="B12"/></xs:restriction>
          </ids:value>
        </ids:property>
      </ids:requirements>
    </ids:specification>
  </ids:specifications>
</ids:ids>

Expected: one specification whose property value is an enumeration ["B12"].
Actual: load throws, so no specification in the file can be checked.

We patch this locally (3.4.3) by normalising both children to arrays, and can send a PR with
a test if that approach suits you.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions