glideapps / quicktype

Generate types and converters from JSON, Schema, and GraphQL

Home Page:https://app.quicktype.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

custom acronym names are not recognized as acronym

yliu-d opened this issue · 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?