Skip to content

Commit 8443ff7

Browse files
authored
Merge pull request #206 from lucamug/issue-205
Replace "OneOf" type names with hash to reduce the size,… #205
2 parents b0278ce + f50f15a commit 8443ff7

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

cli/elm.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"mdgriffith/elm-codegen": "5.2.0",
2222
"miniBill/elm-fast-dict": "1.2.4",
2323
"myrho/yaml": "1.0.0",
24+
"robinheghan/murmur3": "1.0.0",
2425
"turboMaCk/non-empty-list-alias": "1.4.0",
2526
"wolfadex/elm-ansi": "3.0.0",
2627
"wolfadex/elm-open-api": "2.0.0"
@@ -55,7 +56,6 @@
5556
"myrho/elm-parser-extras": "1.0.1",
5657
"noahzgordon/elm-color-extra": "1.0.2",
5758
"robinheghan/fnv1a": "1.0.0",
58-
"robinheghan/murmur3": "1.0.0",
5959
"rtfeldman/elm-css": "18.0.0",
6060
"rtfeldman/elm-hex": "1.0.0",
6161
"rtfeldman/elm-iso8601-date-strings": "1.1.4",

elm.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"json-tools/json-schema": "1.0.0 <= v < 2.0.0",
1919
"mdgriffith/elm-codegen": "5.2.0 <= v < 6.0.0",
2020
"miniBill/elm-fast-dict": "1.2.0 <= v < 2.0.0",
21+
"robinheghan/murmur3": "1.0.0 <= v < 2.0.0",
2122
"turboMaCk/non-empty-list-alias": "1.4.0 <= v < 2.0.0",
2223
"wolfadex/elm-open-api": "2.0.0 <= v < 3.0.0"
2324
},

src/SchemaUtils.elm

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import Json.Decode
3838
import Json.Encode
3939
import Json.Schema.Definitions
4040
import Maybe.Extra
41+
import Murmur3
4142
import OpenApi
4243
import OpenApi.Common.Internal
4344
import OpenApi.Components
@@ -510,12 +511,20 @@ oneOfType types =
510511
names : List Common.UnsafeName
511512
names =
512513
List.map .name sortedVariants
514+
515+
readableName : String
516+
readableName =
517+
names
518+
|> List.map fixOneOfName
519+
|> String.join "_Or_"
513520
in
514521
{ type_ =
515522
Common.OneOf
516-
(names
517-
|> List.map fixOneOfName
518-
|> String.join "_Or_"
523+
(if String.length readableName > 200 then
524+
"OneOf" ++ String.fromInt (Murmur3.hashString 1234 readableName)
525+
526+
else
527+
readableName
519528
)
520529
sortedVariants
521530
, documentation =

0 commit comments

Comments
 (0)