Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/src/Cli.elm
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,7 @@ yamlToJsonValueDecoder =


generateFilesFromOpenApiSpecs :
List ( OpenApi.Generate.Config, OpenApi.OpenApi )
List ( OpenApi.Config.Generate, OpenApi.OpenApi )
->
BackendTask.BackendTask
FatalError.FatalError
Expand Down
1 change: 1 addition & 0 deletions cli/src/TestGenScript.elm
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ run =
gitHub : OpenApi.Config.Input
gitHub =
OpenApi.Config.inputFrom (OpenApi.Config.File "./example/github-spec.json")
|> OpenApi.Config.withWarnOnMissingEnums False

ifconfigOvh : OpenApi.Config.Input
ifconfigOvh =
Expand Down
4 changes: 2 additions & 2 deletions review/suppressed/Docs.NoMissing.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"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" }
{ "count": 35, "filePath": "src/OpenApi/Config.elm" },
{ "count": 5, "filePath": "src/OpenApi/Generate.elm" }
]
}
8 changes: 0 additions & 8 deletions review/suppressed/NoUnused.Parameters.json

This file was deleted.

50 changes: 35 additions & 15 deletions src/CliMonad.elm
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ type CliMonad a
, enums : FastDict.Dict (List String) { name : Common.UnsafeName, documentation : Maybe String }
, namespace : List String
, formats : FastDict.Dict InternalFormatName InternalFormat
, warnOnMissingEnums : Bool
}
-> Result Message ( a, Output )
)
Expand Down Expand Up @@ -284,6 +285,7 @@ run :
, enums : FastDict.Dict (List String) { name : Common.UnsafeName, documentation : Maybe String }
, namespace : List String
, formats : List OpenApi.Config.Format
, warnOnMissingEnums : Bool
}
-> CliMonad (List Declaration)
->
Expand All @@ -301,6 +303,7 @@ run oneOfDeclarations input (CliMonad x) =
, enums : FastDict.Dict (List String) { name : Common.UnsafeName, documentation : Maybe String }
, namespace : List String
, formats : FastDict.Dict InternalFormatName InternalFormat
, warnOnMissingEnums : Bool
}
internalInput =
{ openApi = input.openApi
Expand All @@ -311,6 +314,7 @@ run oneOfDeclarations input (CliMonad x) =
input.formats
|> List.map toInternalFormat
|> FastDict.fromList
, warnOnMissingEnums = input.warnOnMissingEnums
}
in
x internalInput
Expand Down Expand Up @@ -441,20 +445,32 @@ enumName variants =
succeed (Just name)

Nothing ->
succeed Nothing
|> withWarning
("No named enum found for [ "
++ String.join ", "
(List.map
(\variant ->
variant
|> Common.unwrapUnsafe
|> escapeString
)
variants
)
++ " ]. Define one to improve type safety"
)
CliMonad
(\{ warnOnMissingEnums } ->
if warnOnMissingEnums then
let
variantNames : List String
variantNames =
List.map
(\variant ->
variant
|> Common.unwrapUnsafe
|> escapeString
)
variants

message : String
message =
"No named enum found for [ "
++ String.join ", " variantNames
++ " ]. Define one to improve type safety"
in
( Nothing, { emptyOutput | warnings = [ { path = [], message = message } ] } )
|> Ok

else
Ok ( Nothing, emptyOutput )
)
)
enums

Expand Down Expand Up @@ -548,7 +564,11 @@ withFormat basicType maybeFormatName getter default =

secondLine : String
secondLine =
" Available formats: " ++ String.join ", " available
if List.isEmpty available then
" No available formats."

else
" Available formats: " ++ String.join ", " available ++ "."
in
{ emptyOutput
| warnings =
Expand Down
35 changes: 25 additions & 10 deletions src/OpenApi/Config.elm
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ module OpenApi.Config exposing
( Config, EffectType(..), effectTypeToPackage, Format, Input, Path(..), Server(..)
, init, inputFrom, pathFromString
, withAutoConvertSwagger, withEffectTypes, withFormat, withFormats, withGenerateTodos, withInput, withSwaggerConversionCommand, withSwaggerConversionUrl
, withOutputModuleName, withOverrides, withServer, withWriteMergedTo
, withOutputModuleName, withOverrides, withServer, withWriteMergedTo, withWarnOnMissingEnums
, autoConvertSwagger, inputs, outputDirectory, swaggerConversionCommand, swaggerConversionUrl
, oasPath, overrides, writeMergedTo
, toGenerationConfig, pathToString
, toGenerationConfig, Generate, pathToString
, defaultFormats
)

Expand All @@ -21,7 +21,7 @@ module OpenApi.Config exposing

@docs init, inputFrom, pathFromString
@docs withAutoConvertSwagger, withEffectTypes, withFormat, withFormats, withGenerateTodos, withInput, withSwaggerConversionCommand, withSwaggerConversionUrl
@docs withOutputModuleName, withOverrides, withServer, withWriteMergedTo
@docs withOutputModuleName, withOverrides, withServer, withWriteMergedTo, withWarnOnMissingEnums


# Config properties
Expand All @@ -36,7 +36,7 @@ module OpenApi.Config exposing

# Output

@docs toGenerationConfig, pathToString
@docs toGenerationConfig, Generate, pathToString


# Internal
Expand Down Expand Up @@ -92,6 +92,7 @@ type Input
, overrides : List Path
, writeMergedTo : Maybe String
, effectTypes : List EffectType
, warnOnMissingEnums : Bool
}


Expand Down Expand Up @@ -232,6 +233,7 @@ inputFrom path =
, overrides = []
, writeMergedTo = Nothing
, effectTypes = [ ElmHttpCmd, ElmHttpTask ]
, warnOnMissingEnums = False
}
|> Input

Expand Down Expand Up @@ -472,6 +474,12 @@ withWriteMergedTo newWriteMergedTo (Input input) =
Input { input | writeMergedTo = Just newWriteMergedTo }


{-| -}
withWarnOnMissingEnums : Bool -> Input -> Input
withWarnOnMissingEnums newWarnOnMissingEnums (Input input) =
Input { input | warnOnMissingEnums = newWarnOnMissingEnums }


{-| -}
withFormat : Format -> Config -> Config
withFormat newFormat (Config config) =
Expand Down Expand Up @@ -553,19 +561,25 @@ overrides (Input input) =
------------


{-| -}
type alias Generate =
{ namespace : List String
, generateTodos : Bool
, effectTypes : List EffectType
, server : Server
, formats : List Format
, warnOnMissingEnums : Bool
}


{-| -}
toGenerationConfig :
List { format : String, basicType : Common.BasicType }
-> Config
-> List ( Input, OpenApi.OpenApi )
->
List
( { namespace : List String
, generateTodos : Bool
, effectTypes : List EffectType
, server : Server
, formats : List Format
}
( Generate
, OpenApi.OpenApi
)
toGenerationConfig formatsInput (Config config) augmentedInputs =
Expand All @@ -586,6 +600,7 @@ toGenerationConfig formatsInput (Config config) augmentedInputs =
, generateTodos = config.generateTodos
, effectTypes = input.effectTypes
, server = input.server
, warnOnMissingEnums = input.warnOnMissingEnums
, formats = config.staticFormats ++ config.dynamicFormats formatsInput
}
, spec
Expand Down
19 changes: 5 additions & 14 deletions src/OpenApi/Generate.elm
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module OpenApi.Generate exposing (Config, ContentSchema(..), Message, Path, Mime, files)
module OpenApi.Generate exposing (ContentSchema(..), Message, Path, Mime, files)

{-|

@docs Config, ContentSchema, Message, Path, Mime, files
@docs ContentSchema, Message, Path, Mime, files

-}

Expand Down Expand Up @@ -100,19 +100,9 @@ type alias PerPackage a =
}


{-| -}
type alias Config =
{ namespace : List String
, generateTodos : Bool
, effectTypes : List OpenApi.Config.EffectType
, server : OpenApi.Config.Server
, formats : List OpenApi.Config.Format
}


{-| -}
files :
Config
OpenApi.Config.Generate
-> OpenApi.OpenApi
->
Result
Expand All @@ -125,7 +115,7 @@ files :
, warnings : List Message
, requiredPackages : FastSet.Set String
}
files { namespace, generateTodos, effectTypes, server, formats } apiSpec =
files { namespace, generateTodos, effectTypes, server, formats, warnOnMissingEnums } apiSpec =
case extractEnums apiSpec of
Err e ->
Err e
Expand All @@ -151,6 +141,7 @@ files { namespace, generateTodos, effectTypes, server, formats } apiSpec =
, enums = enums
, namespace = namespace
, formats = formats
, warnOnMissingEnums = warnOnMissingEnums
}
|> Result.map
(\{ declarations, warnings, requiredPackages } ->
Expand Down
Loading