glideapps / quicktype

Generate types and converters from JSON, Schema, and GraphQL
https://app.quicktype.io
Apache License 2.0
12.12k stars 1.06k forks source link

Enums are ALWAYS sorted #2401

Open patrickdejong opened 12 months ago

patrickdejong commented 12 months ago

As shown in the image below: image

Enums will always be sorted on their name alphabetically. This will lead to unexpected behaviour with values being swapped.

enum RandomDay{
Monday,
Tuesday,
Friday,
Sunday
}

will become:

enum RandomDay{
Friday,
Monday,
Sunday,
Tuesday
}

So the values do not match anymore. Could you make it an option to enable the alphabetic sorting?

marcselman commented 12 months ago

Yeah, we saw this as well. The generated code does not match the schema.

Source can be found here: https://github.com/glideapps/quicktype/blob/9b570a73a896306778940c793c0037a38815304a/packages/quicktype-core/src/ConvenienceRenderer.ts#L707

Related: #1289