diff --git a/cli/elm.json b/cli/elm.json new file mode 100644 index 0000000..5f6ae3f --- /dev/null +++ b/cli/elm.json @@ -0,0 +1,73 @@ +{ + "type": "application", + "source-directories": [ + "src", + "../src", + "../codegen" + ], + "elm-version": "0.19.1", + "dependencies": { + "direct": { + "dillonkearns/elm-cli-options-parser": "3.2.0", + "dillonkearns/elm-pages": "10.2.2", + "elm/bytes": "1.0.8", + "elm/core": "1.0.5", + "elm/json": "1.1.3", + "elm/regex": "1.0.0", + "elm/url": "1.0.0", + "elmcraft/core-extra": "2.2.0", + "json-tools/json-schema": "1.0.2", + "json-tools/json-value": "1.0.1", + "mdgriffith/elm-codegen": "5.2.0", + "miniBill/elm-fast-dict": "1.2.4", + "myrho/yaml": "1.0.0", + "turboMaCk/non-empty-list-alias": "1.4.0", + "wolfadex/elm-ansi": "3.0.0", + "wolfadex/elm-open-api": "2.0.0" + }, + "indirect": { + "Chadtech/elm-bool-extra": "2.4.2", + "NoRedInk/elm-json-decode-pipeline": "1.0.1", + "avh4/elm-color": "1.0.0", + "danfishgold/base64-bytes": "1.1.0", + "danyx23/elm-mimetype": "4.0.1", + "dillonkearns/elm-bcp47-language-tag": "2.0.0", + "dillonkearns/elm-date-or-date-time": "2.0.0", + "dillonkearns/elm-form": "3.0.1", + "dividat/elm-semver": "2.0.0", + "elm/browser": "1.0.2", + "elm/file": "1.0.5", + "elm/html": "1.0.0", + "elm/http": "2.0.0", + "elm/parser": "1.1.0", + "elm/random": "1.0.0", + "elm/time": "1.0.0", + "elm/virtual-dom": "1.0.4", + "elm-community/basics-extra": "4.1.0", + "elm-community/json-extra": "4.3.0", + "elm-community/list-extra": "8.7.0", + "elm-community/maybe-extra": "5.3.0", + "fredcy/elm-parseint": "2.0.1", + "jluckyiv/elm-utc-date-strings": "1.0.0", + "justinmimbs/date": "4.1.0", + "miniBill/elm-codec": "2.3.0", + "miniBill/elm-unicode": "1.1.1", + "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", + "stil4m/elm-syntax": "7.3.9", + "stil4m/structured-writer": "1.0.3", + "the-sett/elm-pretty-printer": "3.1.2", + "the-sett/elm-syntax-dsl": "6.0.3", + "zwilias/elm-utf-tools": "2.0.1" + } + }, + "test-dependencies": { + "direct": {}, + "indirect": {} + } +} diff --git a/src/Cli.elm b/cli/src/Cli.elm similarity index 100% rename from src/Cli.elm rename to cli/src/Cli.elm diff --git a/cli/src/TestGenScript.elm b/cli/src/TestGenScript.elm index 4394f05..351e891 100644 --- a/cli/src/TestGenScript.elm +++ b/cli/src/TestGenScript.elm @@ -116,5 +116,4 @@ run = , Pages.Script.exec "sh" [ "-c", "cd example && npx --no -- elm make src/Example.elm --output=/dev/null" ] ] - |> BackendTask.inDir "cli" ) diff --git a/elm.json b/elm.json index 32ebe9c..a923553 100644 --- a/elm.json +++ b/elm.json @@ -1,76 +1,28 @@ { - "type": "application", - "source-directories": [ - "src", - "codegen", - "cli/src" + "type": "package", + "name": "wolfadex/elm-open-api-cli", + "summary": "A CLI tool for generating Elm modules from Open API specs. ", + "license": "MIT", + "version": "1.0.0", + "exposed-modules": [ + "OpenApi.Config", + "OpenApi.Generate" ], - "elm-version": "0.19.1", + "elm-version": "0.19.0 <= v < 0.20.0", "dependencies": { - "direct": { - "dillonkearns/elm-cli-options-parser": "3.2.0", - "dillonkearns/elm-pages": "10.2.0", - "elm/core": "1.0.5", - "elm/json": "1.1.3", - "elm/regex": "1.0.0", - "elm/url": "1.0.0", - "elmcraft/core-extra": "2.1.0", - "json-tools/json-schema": "1.0.2", - "json-tools/json-value": "1.0.1", - "mdgriffith/elm-codegen": "5.2.0", - "miniBill/elm-fast-dict": "1.2.1", - "myrho/yaml": "1.0.0", - "turboMaCk/non-empty-list-alias": "1.4.0", - "wolfadex/elm-ansi": "3.0.0", - "wolfadex/elm-open-api": "2.0.0" - }, - "indirect": { - "Chadtech/elm-bool-extra": "2.4.2", - "NoRedInk/elm-json-decode-pipeline": "1.0.1", - "avh4/elm-color": "1.0.0", - "danfishgold/base64-bytes": "1.1.0", - "danyx23/elm-mimetype": "4.0.1", - "dillonkearns/elm-bcp47-language-tag": "2.0.0", - "dillonkearns/elm-date-or-date-time": "2.0.0", - "dillonkearns/elm-form": "3.0.1", - "dividat/elm-semver": "2.0.0", - "elm/browser": "1.0.2", - "elm/bytes": "1.0.8", - "elm/file": "1.0.5", - "elm/html": "1.0.0", - "elm/http": "2.0.0", - "elm/parser": "1.1.0", - "elm/random": "1.0.0", - "elm/time": "1.0.0", - "elm/virtual-dom": "1.0.3", - "elm-community/basics-extra": "4.1.0", - "elm-community/json-extra": "4.3.0", - "elm-community/list-extra": "8.7.0", - "elm-community/maybe-extra": "5.3.0", - "fredcy/elm-parseint": "2.0.1", - "jluckyiv/elm-utc-date-strings": "1.0.0", - "justinmimbs/date": "4.1.0", - "miniBill/elm-codec": "2.2.0", - "miniBill/elm-unicode": "1.1.1", - "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", - "stil4m/elm-syntax": "7.3.8", - "stil4m/structured-writer": "1.0.3", - "the-sett/elm-pretty-printer": "3.1.0", - "the-sett/elm-syntax-dsl": "6.0.3", - "zwilias/elm-utf-tools": "2.0.1" - } + "elm/core": "1.0.0 <= v < 2.0.0", + "elm/json": "1.1.3 <= v < 2.0.0", + "elm/regex": "1.0.0 <= v < 2.0.0", + "elm/url": "1.0.0 <= v < 2.0.0", + "elmcraft/core-extra": "2.2.0 <= v < 3.0.0", + "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", + "turboMaCk/non-empty-list-alias": "1.4.0 <= v < 2.0.0", + "wolfadex/elm-open-api": "2.0.0 <= v < 3.0.0" }, "test-dependencies": { - "direct": { - "elm-explorations/test": "2.2.0", - "miniBill/elm-unicode": "1.1.1" - }, - "indirect": {} + "elm-explorations/test": "2.2.0 <= v < 3.0.0", + "miniBill/elm-unicode": "1.1.1 <= v < 2.0.0" } } diff --git a/package.json b/package.json index c4a6b11..04890f1 100644 --- a/package.json +++ b/package.json @@ -6,13 +6,14 @@ "bin": "dist/elm-open-api.js", "type": "module", "scripts": { - "dev": "elm-pages run src/Cli.elm", - "build": "elm-pages bundle-script src/Cli.elm --output dist/elm-open-api.js --debug", + "dev": "cd cli && elm-pages run src/Cli.elm", + "docs": "elm make --docs=docs.json", + "build": "cd cli && elm-pages bundle-script src/Cli.elm --output ../dist/elm-open-api.js --debug", "review": "elm-review", "review:watch": "elm-review --watch --fix", "format": "elm-format src tests --validate", "test": "elm-test", - "test:gen": "elm-pages run cli/src/TestGenScript.elm", + "test:gen": "cd cli && elm-pages run src/TestGenScript.elm", "test:watch": "elm-test --watch", "pub": "npm run build && npm publish" }, diff --git a/review/src/ReviewConfig.elm b/review/src/ReviewConfig.elm index c4f8678..1acb095 100644 --- a/review/src/ReviewConfig.elm +++ b/review/src/ReviewConfig.elm @@ -52,6 +52,7 @@ exceptCodegenRules = , NoExposingEverything.rule , NoImportingEverything.rule [] , NoMissingTypeAnnotation.rule + |> Rule.ignoreErrorsForDirectories [ "src/Gen" ] , NoMissingTypeAnnotationInLetIn.rule , NoMissingTypeExpose.rule , NoSimpleLetBody.rule @@ -73,9 +74,9 @@ includingCodegenRules : List Rule includingCodegenRules = [ NoUnused.Exports.rule |> Rule.ignoreErrorsForFiles - [ "src/Cli.elm" + [ "cli/src/Cli.elm" , "src/OpenApi/Config.elm" - , "src/TestGenScript.elm" + , "cli/src/TestGenScript.elm" ] , NoUnused.Variables.rule ] diff --git a/review/suppressed/Docs.NoMissing.json b/review/suppressed/Docs.NoMissing.json new file mode 100644 index 0000000..3afae60 --- /dev/null +++ b/review/suppressed/Docs.NoMissing.json @@ -0,0 +1,9 @@ +{ + "version": 1, + "automatically created by": "elm-review suppress", + "learn more": "elm-review suppress --help", + "suppressions": [ + { "count": 33, "filePath": "src/OpenApi/Config.elm" }, + { "count": 6, "filePath": "src/OpenApi/Generate.elm" } + ] +} diff --git a/review/suppressed/Docs.ReviewAtDocs.json b/review/suppressed/Docs.ReviewAtDocs.json new file mode 100644 index 0000000..e434233 --- /dev/null +++ b/review/suppressed/Docs.ReviewAtDocs.json @@ -0,0 +1,14 @@ +{ + "version": 1, + "automatically created by": "elm-review suppress", + "learn more": "elm-review suppress --help", + "suppressions": [ + { "count": 3, "filePath": "src/Gen/BackendTask/Http.elm" }, + { "count": 3, "filePath": "src/Gen/Dict.elm" }, + { "count": 3, "filePath": "src/Gen/Http.elm" }, + { "count": 3, "filePath": "src/Gen/Result.elm" }, + { "count": 2, "filePath": "src/Gen/BackendTask.elm" }, + { "count": 2, "filePath": "src/Gen/List.elm" }, + { "count": 2, "filePath": "src/Gen/Task.elm" } + ] +} diff --git a/review/suppressed/NoMissingTypeExpose.json b/review/suppressed/NoMissingTypeExpose.json new file mode 100644 index 0000000..56dc427 --- /dev/null +++ b/review/suppressed/NoMissingTypeExpose.json @@ -0,0 +1,9 @@ +{ + "version": 1, + "automatically created by": "elm-review suppress", + "learn more": "elm-review suppress --help", + "suppressions": [ + { "count": 4, "filePath": "src/OpenApi/Config.elm" }, + { "count": 1, "filePath": "src/OpenApi/Generate.elm" } + ] +} diff --git a/review/suppressed/NoUnused.Exports.json b/review/suppressed/NoUnused.Exports.json index 437eb4d..98e6579 100644 --- a/review/suppressed/NoUnused.Exports.json +++ b/review/suppressed/NoUnused.Exports.json @@ -3,6 +3,7 @@ "automatically created by": "elm-review suppress", "learn more": "elm-review suppress --help", "suppressions": [ - { "count": 1, "filePath": "cli/src/TestGenScript.elm" } + { "count": 1, "filePath": "src/BackendTask/Extra.elm" }, + { "count": 1, "filePath": "src/OpenApi/Common/Internal.elm" } ] } diff --git a/codegen/Gen/BackendTask.elm b/src/Gen/BackendTask.elm similarity index 100% rename from codegen/Gen/BackendTask.elm rename to src/Gen/BackendTask.elm diff --git a/codegen/Gen/BackendTask/Http.elm b/src/Gen/BackendTask/Http.elm similarity index 100% rename from codegen/Gen/BackendTask/Http.elm rename to src/Gen/BackendTask/Http.elm diff --git a/codegen/Gen/Base64.elm b/src/Gen/Base64.elm similarity index 100% rename from codegen/Gen/Base64.elm rename to src/Gen/Base64.elm diff --git a/codegen/Gen/Basics.elm b/src/Gen/Basics.elm similarity index 100% rename from codegen/Gen/Basics.elm rename to src/Gen/Basics.elm diff --git a/codegen/Gen/Bytes.elm b/src/Gen/Bytes.elm similarity index 100% rename from codegen/Gen/Bytes.elm rename to src/Gen/Bytes.elm diff --git a/codegen/Gen/Bytes/Decode.elm b/src/Gen/Bytes/Decode.elm similarity index 100% rename from codegen/Gen/Bytes/Decode.elm rename to src/Gen/Bytes/Decode.elm diff --git a/codegen/Gen/Date.elm b/src/Gen/Date.elm similarity index 100% rename from codegen/Gen/Date.elm rename to src/Gen/Date.elm diff --git a/codegen/Gen/Debug.elm b/src/Gen/Debug.elm similarity index 100% rename from codegen/Gen/Debug.elm rename to src/Gen/Debug.elm diff --git a/codegen/Gen/Dict.elm b/src/Gen/Dict.elm similarity index 100% rename from codegen/Gen/Dict.elm rename to src/Gen/Dict.elm diff --git a/codegen/Gen/Effect/Http.elm b/src/Gen/Effect/Http.elm similarity index 100% rename from codegen/Gen/Effect/Http.elm rename to src/Gen/Effect/Http.elm diff --git a/codegen/Gen/Effect/Task.elm b/src/Gen/Effect/Task.elm similarity index 100% rename from codegen/Gen/Effect/Task.elm rename to src/Gen/Effect/Task.elm diff --git a/codegen/Gen/FatalError.elm b/src/Gen/FatalError.elm similarity index 100% rename from codegen/Gen/FatalError.elm rename to src/Gen/FatalError.elm diff --git a/codegen/Gen/Http.elm b/src/Gen/Http.elm similarity index 100% rename from codegen/Gen/Http.elm rename to src/Gen/Http.elm diff --git a/codegen/Gen/Json/Decode.elm b/src/Gen/Json/Decode.elm similarity index 100% rename from codegen/Gen/Json/Decode.elm rename to src/Gen/Json/Decode.elm diff --git a/codegen/Gen/Json/Encode.elm b/src/Gen/Json/Encode.elm similarity index 100% rename from codegen/Gen/Json/Encode.elm rename to src/Gen/Json/Encode.elm diff --git a/codegen/Gen/List.elm b/src/Gen/List.elm similarity index 100% rename from codegen/Gen/List.elm rename to src/Gen/List.elm diff --git a/codegen/Gen/Maybe.elm b/src/Gen/Maybe.elm similarity index 100% rename from codegen/Gen/Maybe.elm rename to src/Gen/Maybe.elm diff --git a/codegen/Gen/Parser/Advanced.elm b/src/Gen/Parser/Advanced.elm similarity index 100% rename from codegen/Gen/Parser/Advanced.elm rename to src/Gen/Parser/Advanced.elm diff --git a/codegen/Gen/Result.elm b/src/Gen/Result.elm similarity index 100% rename from codegen/Gen/Result.elm rename to src/Gen/Result.elm diff --git a/codegen/Gen/Rfc3339.elm b/src/Gen/Rfc3339.elm similarity index 100% rename from codegen/Gen/Rfc3339.elm rename to src/Gen/Rfc3339.elm diff --git a/codegen/Gen/String.elm b/src/Gen/String.elm similarity index 100% rename from codegen/Gen/String.elm rename to src/Gen/String.elm diff --git a/codegen/Gen/Task.elm b/src/Gen/Task.elm similarity index 100% rename from codegen/Gen/Task.elm rename to src/Gen/Task.elm diff --git a/codegen/Gen/Time.elm b/src/Gen/Time.elm similarity index 100% rename from codegen/Gen/Time.elm rename to src/Gen/Time.elm diff --git a/codegen/Gen/Url.elm b/src/Gen/Url.elm similarity index 100% rename from codegen/Gen/Url.elm rename to src/Gen/Url.elm diff --git a/codegen/Gen/Url/Builder.elm b/src/Gen/Url/Builder.elm similarity index 100% rename from codegen/Gen/Url/Builder.elm rename to src/Gen/Url/Builder.elm diff --git a/codegen/Gen/Uuid.elm b/src/Gen/Uuid.elm similarity index 100% rename from codegen/Gen/Uuid.elm rename to src/Gen/Uuid.elm diff --git a/src/OpenApi/Config.elm b/src/OpenApi/Config.elm index 41b3e82..6d76876 100644 --- a/src/OpenApi/Config.elm +++ b/src/OpenApi/Config.elm @@ -69,6 +69,7 @@ import Url import Utils +{-| -} type Config = Config { inputs : List Input @@ -82,6 +83,7 @@ type Config } +{-| -} type Input = Input { oasPath : Path @@ -93,6 +95,7 @@ type Input } +{-| -} type EffectType = ElmHttpCmd | ElmHttpCmdRecord @@ -110,6 +113,7 @@ type EffectType | LamderaProgramTestTaskRecord +{-| -} effectTypeToPackage : EffectType -> Common.Package effectTypeToPackage effectType = case effectType of @@ -156,12 +160,14 @@ effectTypeToPackage effectType = Common.LamderaProgramTest +{-| -} type Server = Default | Single String | Multiple (Dict.Dict String String) +{-| -} type alias Format = { basicType : Common.BasicType , format : String @@ -174,11 +180,13 @@ type alias Format = } +{-| -} type Path = File String -- swagger.json ./swagger.json /folder/swagger.json | Url Url.Url -- https://petstore3.swagger.io/api/v3/openapi.json +{-| -} pathFromString : String -> Path pathFromString path = case Url.fromString path of @@ -189,6 +197,7 @@ pathFromString path = File path +{-| -} pathToString : Path -> String pathToString pathType = case pathType of @@ -199,6 +208,7 @@ pathToString pathType = Url.toString url +{-| -} init : String -> Config init initialOutputDirectory = { inputs = [] @@ -213,6 +223,7 @@ init initialOutputDirectory = |> Config +{-| -} inputFrom : Path -> Input inputFrom path = { oasPath = path @@ -231,6 +242,7 @@ inputFrom path = ------------- +{-| -} defaultFormats : List Format defaultFormats = [ dateTimeFormat @@ -406,56 +418,67 @@ byteFormat = ------------- +{-| -} withEffectTypes : List EffectType -> Input -> Input withEffectTypes effectTypes (Input input) = Input { input | effectTypes = effectTypes } +{-| -} withOutputModuleName : List String -> Input -> Input withOutputModuleName moduleName (Input input) = Input { input | outputModuleName = Just moduleName } +{-| -} withOverrides : List Path -> Input -> Input withOverrides newOverrides (Input input) = Input { input | overrides = newOverrides } +{-| -} withGenerateTodos : Bool -> Config -> Config withGenerateTodos generateTodos (Config config) = Config { config | generateTodos = generateTodos } +{-| -} withAutoConvertSwagger : Bool -> Config -> Config withAutoConvertSwagger newAutoConvertSwagger (Config config) = Config { config | autoConvertSwagger = newAutoConvertSwagger } +{-| -} withSwaggerConversionUrl : String -> Config -> Config withSwaggerConversionUrl newSwaggerConversionUrl (Config config) = Config { config | swaggerConversionUrl = newSwaggerConversionUrl } +{-| -} withSwaggerConversionCommand : { command : String, args : List String } -> Config -> Config withSwaggerConversionCommand newSwaggerConversionCommand (Config config) = Config { config | swaggerConversionCommand = Just newSwaggerConversionCommand } +{-| -} withServer : Server -> Input -> Input withServer newServer (Input input) = Input { input | server = newServer } +{-| -} withWriteMergedTo : String -> Input -> Input withWriteMergedTo newWriteMergedTo (Input input) = Input { input | writeMergedTo = Just newWriteMergedTo } +{-| -} withFormat : Format -> Config -> Config withFormat newFormat (Config config) = Config { config | staticFormats = newFormat :: config.staticFormats } +{-| -} withFormats : (List { format : String, basicType : Common.BasicType } -> List Format) -> Config @@ -464,6 +487,7 @@ withFormats newFormat (Config config) = Config { config | dynamicFormats = \input -> newFormat input ++ config.dynamicFormats input } +{-| -} withInput : Input -> Config -> Config withInput input (Config config) = Config { config | inputs = input :: config.inputs } @@ -475,41 +499,49 @@ withInput input (Config config) = ------------- +{-| -} swaggerConversionUrl : Config -> String swaggerConversionUrl (Config config) = config.swaggerConversionUrl +{-| -} swaggerConversionCommand : Config -> Maybe { command : String, args : List String } swaggerConversionCommand (Config config) = config.swaggerConversionCommand +{-| -} autoConvertSwagger : Config -> Bool autoConvertSwagger (Config config) = config.autoConvertSwagger +{-| -} outputDirectory : Config -> String outputDirectory (Config config) = config.outputDirectory +{-| -} inputs : Config -> List Input inputs (Config config) = List.reverse config.inputs +{-| -} oasPath : Input -> Path oasPath (Input input) = input.oasPath +{-| -} writeMergedTo : Input -> Maybe String writeMergedTo (Input input) = input.writeMergedTo +{-| -} overrides : Input -> List Path overrides (Input input) = input.overrides @@ -521,6 +553,7 @@ overrides (Input input) = ------------ +{-| -} toGenerationConfig : List { format : String, basicType : Common.BasicType } -> Config diff --git a/src/OpenApi/Generate.elm b/src/OpenApi/Generate.elm index 3eaa166..cab580d 100644 --- a/src/OpenApi/Generate.elm +++ b/src/OpenApi/Generate.elm @@ -1,11 +1,11 @@ -module OpenApi.Generate exposing - ( Config - , ContentSchema(..) - , Mime - , files - ) - -import Cli.Validate +module OpenApi.Generate exposing (Config, ContentSchema(..), Message, Path, Mime, files) + +{-| + +@docs Config, ContentSchema, Message, Path, Mime, files + +-} + import CliMonad exposing (CliMonad) import Common import Dict @@ -55,14 +55,29 @@ import OpenApi.Schema import OpenApi.SecurityRequirement import OpenApi.SecurityScheme import OpenApi.Server +import Regex exposing (Regex) import SchemaUtils import String.Extra +{-| -} type alias Mime = String +{-| -} +type alias Message = + { message : String + , path : Path + } + + +{-| -} +type alias Path = + List String + + +{-| -} type ContentSchema = EmptyContent | JsonContent Common.Type @@ -86,6 +101,7 @@ type alias PerPackage a = } +{-| -} type alias Config = { namespace : List String , generateTodos : Bool @@ -95,18 +111,19 @@ type alias Config = } +{-| -} files : Config -> OpenApi.OpenApi -> Result - CliMonad.Message + Message { modules : List { moduleName : List String , declarations : FastDict.Dict String { group : String, declaration : Elm.Declaration } } - , warnings : List CliMonad.Message + , warnings : List Message , requiredPackages : FastSet.Set String } files { namespace, generateTodos, effectTypes, server, formats } apiSpec = @@ -168,7 +185,7 @@ extractEnums : OpenApi.OpenApi -> Result - CliMonad.Message + Message (FastDict.Dict (List String) { name : Common.UnsafeName, documentation : Maybe String }) extractEnums openApi = openApi @@ -1587,19 +1604,15 @@ operationToContentSchema operation = |> CliMonad.map (\ref -> JsonContent (Common.Ref <| String.split "/" <| OpenApi.Reference.ref ref)) -regexToCheckIfJson : String -> Cli.Validate.ValidationResult -regexToCheckIfJson = - Cli.Validate.regex "^application\\/(vnd\\.[a-z0-9]+(\\.v\\d+)?(\\.[a-z0-9]+)?)?\\+?json$" +jsonRegex : Regex +jsonRegex = + Regex.fromString "^application\\/(vnd\\.[a-z0-9]+(\\.v\\d+)?(\\.[a-z0-9]+)?)?\\+?json$" + |> Maybe.withDefault Regex.never searchForJsonMediaType : String -> a -> Bool searchForJsonMediaType mediaType _ = - case regexToCheckIfJson mediaType of - Cli.Validate.Valid -> - True - - Cli.Validate.Invalid _ -> - False + Regex.contains jsonRegex mediaType contentToContentSchema : Bool -> Dict.Dict String OpenApi.MediaType.MediaType -> CliMonad ContentSchema