hooklift / gowsdl

WSDL2Go code generation as well as its SOAP proxy
Mozilla Public License 2.0
1.15k stars 389 forks source link

Handling plus (and probably some other characters) in enumerations #113

Open zerkms opened 5 years ago

zerkms commented 5 years ago

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 commented 5 years ago

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.

anjmao commented 5 years ago

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 😆