xuri / xgen

XSD (XML Schema Definition) parser and Go/C/Java/Rust/TypeScript code generator
BSD 3-Clause "New" or "Revised" License
313 stars 74 forks source link

Illegal characters in enum element names for TypeScript. #27

Open claudemartin opened 3 years ago

claudemartin commented 3 years ago

Description

Note: I'm only interested in TypeScript, so I didn't test any other languages.

When generating code for TS and there's an enum type (enumeration) it could have illegal characters, such as ".". Those should be replaced by underscore. It doesn't matter because the type uses the exact string as the value of each constant. So the name doesn't really matter as long as it's always generated the same way. Here's an example of how it would be done using JAX:

@XmlType(name = "exampleEnumType")
@XmlEnum
public enum ExampleEnumType{
    @XmlEnumValue("FOO.BAR")
    FOO_BAR("FOO.BAR"),
    ...

Steps to reproduce the issue:

  1. Use XSD that has enumeration with characters that are illegal in TS (i.e. EcmaScript)
  2. xgen -l TypeScript -i ".\foo.xsd" -o "foo"
  3. Compile the generated code.

You can use this as an example: https://share.ech.ch/xmlns/eCH-0196/2/eCH-0196-2-0.xsd The enum SecurityTypeType is the problem.

Describe the results you received:

Constant names with ".".

Describe the results you expected:

Constant names with "_" instead of ".".

Output of go version:

go version go1.16.5 windows/amd64

xgen version or commit ID:

xgen version: 0.1.0

Environment details (OS, physical, etc.):

Doesn't matter.