elm-open-api-cli
elm-open-api-cli copied to clipboard
When "OneOf" types get too long, they cause a corruption error in the Elm compiler cache
trafficstars
We had a case where we have several errors types that get concatendated with "or" as part of OneOf case.
The compilation from scratch of the generated Elm code works fine, but a re-compilation generated this error:
It seems that the Elm compiler is not able to read back the cached files when type names are too long.
The solution that we adopted is to shorten these names with an hash.
Before:
type_ =
Common.OneOf
(names
|> List.map fixOneOfName
|> String.join "_or_"
)
sortedVariants
After:
type_ =
Common.OneOf
(names
|> List.map fixOneOfName
|> String.join "_or_"
|> (\s -> "OneOf" ++ String.fromInt (Murmur3.hashString 1234 s))
)
sortedVariants
I will send a PR as example, but there are probably more elegant solutions