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

xsd:integer as int / string #58

Open
danielkwinsor opened this issue Jun 7, 2016 · 8 comments
Open

xsd:integer as int / string #58

danielkwinsor opened this issue Jun 7, 2016 · 8 comments

Comments

@danielkwinsor
Copy link

This xsd generates the following golang code, which fails to compile with the following reason.
What I see is xsd:integer is different from xsd:int and xsd:integer could probably be a string, since it is unbounded.

  <xsd:simpleType name="XyzType_e">
    <xsd:restriction base="xsd:integer">
      <xsd:enumeration value="0" codegen:cname="USER_0" />
      <xsd:enumeration value="1" codegen:cname="USER_1" />
      <xsd:enumeration value="2" codegen:cname="USER_2" />
      <xsd:enumeration value="3" codegen:cname="USER_3" />
    </xsd:restriction>
  </xsd:simpleType>
type XyzTypee int32

const (
    XyzTypee0 XyzTypee = "0"

    XyzTypee1 XyzTypee = "1"

    XyzTypee2 XyzTypee = "2"

    XyzTypee3 XyzTypee = "3"
)

myservice/myservice.go:105: cannot convert "0" to type XyzTypee
myservice/myservice.go:107: cannot convert "1" to type XyzTypee
myservice/myservice.go:109: cannot convert "2" to type XyzTypee
myservice/myservice.go:111: cannot convert "3" to type XyzTypee

@md5
Copy link
Contributor

md5 commented Jun 7, 2016

What about using big.Int for xsd:integer?

@danielkwinsor
Copy link
Author

Yeah, that sounds even better than a string, and I'll give it a try when I get back to work in a few days.

@danielkwinsor
Copy link
Author

type XyzTypee big.Int generates "invalid constant type" no matter whether 0 or "0"

@md5
Copy link
Contributor

md5 commented Jun 10, 2016

@danielkwinsor Can you be more specific about what generates that error and what you did?

@md5
Copy link
Contributor

md5 commented Jun 10, 2016

It looks like types_tmpl.go assumes that all restrictions are string enumerations currently.

@danielkwinsor
Copy link
Author

Yeah sure so, originally I changed line 405 of gowsdl.go in the support-for-imports branch -- to "integer": "string",
This worked to compile, though I haven't tested the client yet.

Tried "integer": "big.Int", and hand-imported math/big, but did not change types_tmpl.go
This did not work because

myservice/myservice.go:58: invalid constant type XyzTypee
myservice/myservice.go:60: invalid constant type XyzTypee
myservice/myservice.go:62: invalid constant type XyzTypee
myservice/myservice.go:64: invalid constant type XyzTypee
type XyzTypee big.Int

const (
    XyzTypee0 XyzTypee = "0"

    XyzTypee1 XyzTypee = "1"

    XyzTypee2 XyzTypee = "2"

    XyzTypee3 XyzTypee = "3"
)

@md5
Copy link
Contributor

md5 commented Jun 14, 2016

@danielkwinsor It looks like the problem you're seeing here is that big.Int is not an allowed constant type. Assuming that could be addressed, then the next issue to tackle is that Int.setString will need to be called to parse the enumerated values. Unfortunately, there doesn't seem to be an immutable version of big.Int from my reading of the docs.

@Halfi
Copy link

Halfi commented Jan 18, 2019

Now code generates:

type XyzTypee int32

const (
    XyzTypee0 XyzTypee = "0"

    XyzTypee1 XyzTypee = "1"

    XyzTypee2 XyzTypee = "2"

    XyzTypee3 XyzTypee = "3"
)

Expected

type XyzTypee int32

const (
    XyzTypee0 XyzTypee = 0

    XyzTypee1 XyzTypee = 1

    XyzTypee2 XyzTypee = 2

    XyzTypee3 XyzTypee = 3
)

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