fullstack-lang / gongxsd

MIT License
0 stars 0 forks source link

Factor ALTERNATIVE_ID in reqif generation #8

Closed thomaspeugeot closed 2 months ago

thomaspeugeot commented 2 months ago

in the xsd,

there are 24

<xsd:element maxOccurs="1" minOccurs="0" name="ALTERNATIVE-ID">

Problème, this generates as many instances of ALTERNATIVE ID.

For instance

  <xsd:complexType name="ATTRIBUTE-DEFINITION-BOOLEAN">
    <xsd:all>
      <xsd:element maxOccurs="1" minOccurs="0" name="ALTERNATIVE-ID">
        <xsd:complexType>
          <xsd:choice maxOccurs="1" minOccurs="0">
            <xsd:element name="ALTERNATIVE-ID" type="REQIF:ALTERNATIVE-ID" />
          </xsd:choice>
        </xsd:complexType>
      </xsd:element>
    </xsd:all>
...
...
  </xsd:complexType>

This defines a boolean complex type attributes of type boolean

it haves a an "ALTERNATIVE-ID" with an anonymous complex_type with a "choice" of

    <xsd:all>
      <xsd:element maxOccurs="1" minOccurs="0" name="ALTERNATIVE-ID">
        <xsd:complexType>
          <xsd:choice maxOccurs="1" minOccurs="0">
            <xsd:element name="ALTERNATIVE-ID" type="REQIF:ALTERNATIVE-ID" />
          </xsd:choice>
        </xsd:complexType>
      </xsd:element>
      <xsd:element maxOccurs="1" minOccurs="0" name="DEFAULT-VALUE">
        <xsd:complexType>
          <xsd:choice maxOccurs="1" minOccurs="0">
            <xsd:element name="ATTRIBUTE-VALUE-STRING" type="REQIF:ATTRIBUTE-VALUE-STRING" />
          </xsd:choice>
        </xsd:complexType>
      </xsd:element>
      <xsd:element maxOccurs="1" minOccurs="1" name="TYPE">
        <xsd:complexType>
          <xsd:choice maxOccurs="1" minOccurs="1">
            <xsd:element name="DATATYPE-DEFINITION-STRING-REF" type="REQIF:LOCAL-REF" />
          </xsd:choice>
        </xsd:complexType>
      </xsd:element>
    </xsd:all>

in fact, the whole element definition

      <xsd:element maxOccurs="1" minOccurs="0" name="ALTERNATIVE-ID">
        <xsd:complexType>
          <xsd:choice maxOccurs="1" minOccurs="0">
            <xsd:element name="ALTERNATIVE-ID" type="REQIF:ALTERNATIVE-ID" />
          </xsd:choice>
        </xsd:complexType>
      </xsd:element>

is repeated in the xsd.

in the generated models.go,

// ATTRIBUTE_DEFINITION_BOOLEAN is generated from named complex type "ATTRIBUTE-DEFINITION-BOOLEAN"
type ATTRIBUTE_DEFINITION_BOOLEAN struct {
    Name string `xml:"-"`

    // generated from anonymous type within outer element "ALTERNATIVE-ID" of type A_ALTERNATIVE-ID.
    ALTERNATIVE_ID []*A_ALTERNATIVE_ID_14 `xml:"ALTERNATIVE-ID,omitempty"`

}

// ATTRIBUTE_DEFINITION_DATE is generated from named complex type "ATTRIBUTE-DEFINITION-DATE"
type ATTRIBUTE_DEFINITION_DATE struct {
    Name string `xml:"-"`

    // generated from anonymous type within outer element "ALTERNATIVE-ID" of type A_ALTERNATIVE-ID.
    ALTERNATIVE_ID []*A_ALTERNATIVE_ID_6 `xml:"ALTERNATIVE-ID,omitempty"`
}

Therefore, once one generate the anonymous complex type, one should check wether it already exists with this definition && its name

thomaspeugeot commented 2 months ago

Analysis:

those 24 instances of complex type with the same name exist in the xsd. There are parsed without error and therefore are generated.

If one want to factor them, on can do that AFTER the parsing but BEFORE the generation.

Tentative solution:

before stack.Stage.StageBranchSchema(&models.SchemaSingloton)

        <xsd:complexType>
          <xsd:choice maxOccurs="1" minOccurs="0">
            <xsd:element name="ALTERNATIVE-ID" type="REQIF:ALTERNATIVE-ID" />
          </xsd:choice>
        </xsd:complexType>
      <xsd:element maxOccurs="1" minOccurs="0" name="ALTERNATIVE-ID">