diff --git a/cli/elm.json b/cli/elm.json index 5f6ae3f..64ffe60 100644 --- a/cli/elm.json +++ b/cli/elm.json @@ -21,6 +21,7 @@ "mdgriffith/elm-codegen": "5.2.0", "miniBill/elm-fast-dict": "1.2.4", "myrho/yaml": "1.0.0", + "robinheghan/murmur3": "1.0.0", "turboMaCk/non-empty-list-alias": "1.4.0", "wolfadex/elm-ansi": "3.0.0", "wolfadex/elm-open-api": "2.0.0" @@ -55,7 +56,6 @@ "myrho/elm-parser-extras": "1.0.1", "noahzgordon/elm-color-extra": "1.0.2", "robinheghan/fnv1a": "1.0.0", - "robinheghan/murmur3": "1.0.0", "rtfeldman/elm-css": "18.0.0", "rtfeldman/elm-hex": "1.0.0", "rtfeldman/elm-iso8601-date-strings": "1.1.4", diff --git a/elm.json b/elm.json index a923553..81b5968 100644 --- a/elm.json +++ b/elm.json @@ -18,6 +18,7 @@ "json-tools/json-schema": "1.0.0 <= v < 2.0.0", "mdgriffith/elm-codegen": "5.2.0 <= v < 6.0.0", "miniBill/elm-fast-dict": "1.2.0 <= v < 2.0.0", + "robinheghan/murmur3": "1.0.0 <= v < 2.0.0", "turboMaCk/non-empty-list-alias": "1.4.0 <= v < 2.0.0", "wolfadex/elm-open-api": "2.0.0 <= v < 3.0.0" }, diff --git a/src/SchemaUtils.elm b/src/SchemaUtils.elm index fc07b75..9fbf1af 100644 --- a/src/SchemaUtils.elm +++ b/src/SchemaUtils.elm @@ -38,6 +38,7 @@ import Json.Decode import Json.Encode import Json.Schema.Definitions import Maybe.Extra +import Murmur3 import OpenApi import OpenApi.Common.Internal import OpenApi.Components @@ -510,12 +511,20 @@ oneOfType types = names : List Common.UnsafeName names = List.map .name sortedVariants + + readableName : String + readableName = + names + |> List.map fixOneOfName + |> String.join "_Or_" in { type_ = Common.OneOf - (names - |> List.map fixOneOfName - |> String.join "_Or_" + (if String.length readableName > 200 then + "OneOf" ++ String.fromInt (Murmur3.hashString 1234 readableName) + + else + readableName ) sortedVariants , documentation =