Skip to content

Commit 4576ddb

Browse files
committed
Suppress missing enum warnings on github spec
1 parent 221bc0c commit 4576ddb

File tree

5 files changed

+47
-19
lines changed

5 files changed

+47
-19
lines changed

cli/src/TestGenScript.elm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ run =
7373
gitHub : OpenApi.Config.Input
7474
gitHub =
7575
OpenApi.Config.inputFrom (OpenApi.Config.File "./example/github-spec.json")
76+
|> OpenApi.Config.withWarnOnMissingEnums False
7677

7778
ifconfigOvh : OpenApi.Config.Input
7879
ifconfigOvh =

review/suppressed/Docs.NoMissing.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"automatically created by": "elm-review suppress",
44
"learn more": "elm-review suppress --help",
55
"suppressions": [
6-
{ "count": 33, "filePath": "src/OpenApi/Config.elm" },
7-
{ "count": 6, "filePath": "src/OpenApi/Generate.elm" }
6+
{ "count": 35, "filePath": "src/OpenApi/Config.elm" },
7+
{ "count": 5, "filePath": "src/OpenApi/Generate.elm" }
88
]
99
}

src/CliMonad.elm

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ type CliMonad a
7676
, enums : FastDict.Dict (List String) { name : Common.UnsafeName, documentation : Maybe String }
7777
, namespace : List String
7878
, formats : FastDict.Dict InternalFormatName InternalFormat
79+
, warnOnMissingEnums : Bool
7980
}
8081
-> Result Message ( a, Output )
8182
)
@@ -284,6 +285,7 @@ run :
284285
, enums : FastDict.Dict (List String) { name : Common.UnsafeName, documentation : Maybe String }
285286
, namespace : List String
286287
, formats : List OpenApi.Config.Format
288+
, warnOnMissingEnums : Bool
287289
}
288290
-> CliMonad (List Declaration)
289291
->
@@ -301,6 +303,7 @@ run oneOfDeclarations input (CliMonad x) =
301303
, enums : FastDict.Dict (List String) { name : Common.UnsafeName, documentation : Maybe String }
302304
, namespace : List String
303305
, formats : FastDict.Dict InternalFormatName InternalFormat
306+
, warnOnMissingEnums : Bool
304307
}
305308
internalInput =
306309
{ openApi = input.openApi
@@ -311,6 +314,7 @@ run oneOfDeclarations input (CliMonad x) =
311314
input.formats
312315
|> List.map toInternalFormat
313316
|> FastDict.fromList
317+
, warnOnMissingEnums = input.warnOnMissingEnums
314318
}
315319
in
316320
x internalInput
@@ -441,20 +445,32 @@ enumName variants =
441445
succeed (Just name)
442446

443447
Nothing ->
444-
succeed Nothing
445-
|> withWarning
446-
("No named enum found for [ "
447-
++ String.join ", "
448-
(List.map
449-
(\variant ->
450-
variant
451-
|> Common.unwrapUnsafe
452-
|> escapeString
453-
)
454-
variants
455-
)
456-
++ " ]. Define one to improve type safety"
457-
)
448+
CliMonad
449+
(\{ warnOnMissingEnums } ->
450+
if warnOnMissingEnums then
451+
let
452+
variantNames : List String
453+
variantNames =
454+
List.map
455+
(\variant ->
456+
variant
457+
|> Common.unwrapUnsafe
458+
|> escapeString
459+
)
460+
variants
461+
462+
message : String
463+
message =
464+
"No named enum found for [ "
465+
++ String.join ", " variantNames
466+
++ " ]. Define one to improve type safety"
467+
in
468+
( Nothing, { emptyOutput | warnings = [ { path = [], message = message } ] } )
469+
|> Ok
470+
471+
else
472+
Ok ( Nothing, emptyOutput )
473+
)
458474
)
459475
enums
460476

src/OpenApi/Config.elm

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module OpenApi.Config exposing
22
( Config, EffectType(..), effectTypeToPackage, Format, Input, Path(..), Server(..)
33
, init, inputFrom, pathFromString
44
, withAutoConvertSwagger, withEffectTypes, withFormat, withFormats, withGenerateTodos, withInput, withSwaggerConversionCommand, withSwaggerConversionUrl
5-
, withOutputModuleName, withOverrides, withServer, withWriteMergedTo
5+
, withOutputModuleName, withOverrides, withServer, withWriteMergedTo, withWarnOnMissingEnums
66
, autoConvertSwagger, inputs, outputDirectory, swaggerConversionCommand, swaggerConversionUrl
77
, oasPath, overrides, writeMergedTo
88
, toGenerationConfig, Generate, pathToString
@@ -21,7 +21,7 @@ module OpenApi.Config exposing
2121
2222
@docs init, inputFrom, pathFromString
2323
@docs withAutoConvertSwagger, withEffectTypes, withFormat, withFormats, withGenerateTodos, withInput, withSwaggerConversionCommand, withSwaggerConversionUrl
24-
@docs withOutputModuleName, withOverrides, withServer, withWriteMergedTo
24+
@docs withOutputModuleName, withOverrides, withServer, withWriteMergedTo, withWarnOnMissingEnums
2525
2626
2727
# Config properties
@@ -92,6 +92,7 @@ type Input
9292
, overrides : List Path
9393
, writeMergedTo : Maybe String
9494
, effectTypes : List EffectType
95+
, warnOnMissingEnums : Bool
9596
}
9697

9798

@@ -232,6 +233,7 @@ inputFrom path =
232233
, overrides = []
233234
, writeMergedTo = Nothing
234235
, effectTypes = [ ElmHttpCmd, ElmHttpTask ]
236+
, warnOnMissingEnums = False
235237
}
236238
|> Input
237239

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

474476

477+
{-| -}
478+
withWarnOnMissingEnums : Bool -> Input -> Input
479+
withWarnOnMissingEnums newWarnOnMissingEnums (Input input) =
480+
Input { input | warnOnMissingEnums = newWarnOnMissingEnums }
481+
482+
475483
{-| -}
476484
withFormat : Format -> Config -> Config
477485
withFormat newFormat (Config config) =
@@ -560,6 +568,7 @@ type alias Generate =
560568
, effectTypes : List EffectType
561569
, server : Server
562570
, formats : List Format
571+
, warnOnMissingEnums : Bool
563572
}
564573

565574

@@ -591,6 +600,7 @@ toGenerationConfig formatsInput (Config config) augmentedInputs =
591600
, generateTodos = config.generateTodos
592601
, effectTypes = input.effectTypes
593602
, server = input.server
603+
, warnOnMissingEnums = input.warnOnMissingEnums
594604
, formats = config.staticFormats ++ config.dynamicFormats formatsInput
595605
}
596606
, spec

src/OpenApi/Generate.elm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ files :
115115
, warnings : List Message
116116
, requiredPackages : FastSet.Set String
117117
}
118-
files { namespace, generateTodos, effectTypes, server, formats } apiSpec =
118+
files { namespace, generateTodos, effectTypes, server, formats, warnOnMissingEnums } apiSpec =
119119
case extractEnums apiSpec of
120120
Err e ->
121121
Err e
@@ -141,6 +141,7 @@ files { namespace, generateTodos, effectTypes, server, formats } apiSpec =
141141
, enums = enums
142142
, namespace = namespace
143143
, formats = formats
144+
, warnOnMissingEnums = warnOnMissingEnums
144145
}
145146
|> Result.map
146147
(\{ declarations, warnings, requiredPackages } ->

0 commit comments

Comments
 (0)