Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Child element omitted if attribute with enumeration is passed #28

Closed
fwielstra opened this issue Jun 23, 2021 · 2 comments
Closed

Child element omitted if attribute with enumeration is passed #28

fwielstra opened this issue Jun 23, 2021 · 2 comments

Comments

@fwielstra
Copy link

Description

I've tried to boil it down to the simplest example. I have an XSD as follows:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
  <xs:element name="template">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="requests"/>
        <xs:element minOccurs="0" ref="responses"/>
      </xs:sequence>
      <xs:attribute name="type" use="required">
        <xs:simpleType>
          <xs:restriction base="xs:string">
            <xs:enumeration value="avp"/>
            <xs:enumeration value="condition"/>
            <xs:enumeration value="routing"/>
          </xs:restriction>
        </xs:simpleType>
      </xs:attribute>
    </xs:complexType>
  </xs:element>
  <xs:element name="requests" />
  <xs:element name="responses" />
</xs:schema>

After generating, the following is generated:

// Code generated by xgen. DO NOT EDIT.

package schema

import (
	"encoding/xml"
)

// Template ...
type Template struct {
	XMLName  xml.Name    `xml:"template"`
	TypeAttr interface{} `xml:"type,attr"`
	Requests *Requests   `xml:"requests"`
	Template string      `xml:"template"`
}

// Requests ...
type Requests *Requests

// Responses ...
type Responses *Responses

This is missing the Responses key in the Template struct, but adds a Template string property from.. somewhere.

Removing the <xs:simpleType> segment:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
  <xs:element name="template">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="requests" />
        <xs:element minOccurs="0" ref="responses" />
      </xs:sequence>
      <xs:attribute name="type" use="required" />
    </xs:complexType>
  </xs:element>
  <xs:element name="requests" />
  <xs:element name="responses" />
</xs:schema>

results in a struct that looks more correct:

// Template ...
type Template struct {
	XMLName   xml.Name    `xml:"template"`
	TypeAttr  interface{} `xml:"type,attr"`
	Requests  *Requests   `xml:"requests"`
	Responses *Responses  `xml:"responses"`
}

// Requests ...
type Requests *Requests

// Responses ...
type Responses *Responses

Output of go version:

go version go1.16.2 darwin/amd64

xgen version or commit ID:

v0.0.0-20210301142127-04f2cd700cdb

Environment details (OS, physical, etc.):
MacOS, physical

alexandre-normand added a commit to alexandre-normand/xgen that referenced this issue Nov 15, 2021
…Type Was Aborted Prematurely

Signed-off-by: Alex Normand <alexandre.normand@gmail.com>
alexandre-normand added a commit to alexandre-normand/xgen that referenced this issue Nov 15, 2021
…n ComplexType

Fixes issue xuri#28

Signed-off-by: Alex Normand <alexandre.normand@gmail.com>
alexandre-normand added a commit to alexandre-normand/xgen that referenced this issue Nov 15, 2021
…n ComplexType

Fixes issue xuri#28

Signed-off-by: Alex Normand <alexandre.normand@gmail.com>
xuri added a commit that referenced this issue Nov 18, 2021
…arsing

Fix for #28: Attribute Enumeration Parsing Aborted Prematurely When Enclosed in ComplexType
@alexandre-normand
Copy link
Contributor

@xuri : It looks like I didn't use the right message format for github to auto-close this issue with my fix in #34. Do you mind closing it since it's now fixed?

@xuri xuri closed this as completed Nov 19, 2021
@xuri
Copy link
Owner

xuri commented Nov 19, 2021

I closed this issue, thanks @alexandre-normand.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants