quicktype icon indicating copy to clipboard operation
quicktype copied to clipboard

custom acronym names are not recognized as acronym

Open yliu-d opened this issue 3 years ago • 0 comments

I'm using golang generator to generate type names with some custom enum values, such as

"enum": [
    "HLS",
    "DASH",
    "MSS"
]

These are not in the built-in acronym list, but they are all upper cases, so they should be considered as acronyms, but the generated golang code has:

type Format string
const (
	Dash Format = "DASH"
	HLS Format = "HLS"
	Mss Format = "MSS"
)

It should be:

type Format string
const (
	DASH Format = "DASH"
	HLS Format = "HLS"
	MSS Format = "MSS"
)

Then I checked the quicktype implementation and found this is how it detects acronyms: https://github.com/quicktype/quicktype/blob/df66617104acd2f6b1022719463382a9b5b6cbe0/src/quicktype-core/support/Strings.ts#L438 When the whole string is like DASH, lastLowerCaseIndex is undefined and allUpper is true, hence isAcronym is false. Why is lastLowerCaseIndex !== undefined needed?

yliu-d avatar Mar 26 '22 21:03 yliu-d