gowsdl icon indicating copy to clipboard operation
gowsdl copied to clipboard

Handling plus (and probably some other characters) in enumerations

Open zerkms opened this issue 5 years ago • 2 comments

This type

    <xsd:simpleType name="SomeTypeName">
        <!-- omitted -->
        <xsd:restriction base="xsd:string">
            <xsd:enumeration value="FOO"/>
            <xsd:enumeration value="FOO2"/>
            <xsd:enumeration value="FOO2+"/>
        </xsd:restriction>
    </xsd:simpleType>

is being generated to

type SomeTypeName string

const (
	SomeTypeNameFOO SomeTypeName = "FOO"

	SomeTypeNameFOO2 SomeTypeName = "FOO2"

	SomeTypeNameFOO2 SomeTypeName = "FOO2+"
)

which is a duplicated identifier

The closest previously reported bug I could find is https://github.com/hooklift/gowsdl/issues/16

zerkms avatar Dec 04 '18 00:12 zerkms

I agree that my suggestion is very problem-specific and does not solve to problem in general.

After thinking some more I think that the better solution would be to implement a way to provide an external map of the names that cannot be mangled automatically.

Like a separate json file that would look like:

{
    "SomeTypeName": {
        "FOO2+": "Foo2Plus"
    }
}

And then used as wsdl --custom-map=/path/to/file.json

It's not necessary to be json but any serialisation format that would guarantee that all possible wsdl type names are decoded in an unambiguous manner.

zerkms avatar Dec 04 '18 03:12 zerkms

I like the idea of custom map because xml is such a problematic format. We will never handle all the cases to generate valid go code 😆

anjmao avatar Dec 04 '18 07:12 anjmao