Conversation
toGoName now splits on any non-letter, non-digit character instead of
only underscore, hyphen, and dot. This handles XSD enumeration values
containing spaces ("EIR Sync Error"), slashes ("application/xml"),
colons ("1:M"), plus signs ("application/atom+xml"), and asterisks
("*/*") that previously produced unparsable Go source.
Values starting with a digit after sanitisation are prefixed with "V"
to remain valid Go identifiers (e.g. "1.0" → "V10").
Original casing within each word part is preserved to maintain
camelCase names like "GetWeather" and "DownloadRequest".
tnymlr
force-pushed
the
fix/enum-identifier-sanitisation
branch
from
April 8, 2026 04:36
1fe4213 to
0766525
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
toGoName()only splits on_,-, and., so XSD enumeration values containing spaces, slashes, colons, plus signs, or asterisks produce invalid Go identifiers in generated const names.Examples of values that break code generation:
"EIR Sync Error"→ExceptionTypeEIR Sync Error(space)"application/xml"→MediaTypeCodeApplication/xml(slash)"application/atom+xml"→MediaTypeCodeApplication/atom+xml(slash, plus)"*/*"→MediaTypeCode*/*(asterisk, slash)"1:M"→ExceptionType1:M(colon, digit-start)This causes
go/formatto reject the generated source with errors like:Fix
Change
toGoName()to split on any character that is not a letter or digit (!unicode.IsLetter(r) && !unicode.IsDigit(r)). This handles all non-identifier characters uniformly.Additional changes:
V(e.g."1.0"→V10)"Value"as a fallbackGetWeatherandDownloadRequestTest plan
TestToGoNamewith 30 test cases covering spaces, slashes, colons, plus signs, asterisks, MIME types, charset names, and digit-leading values