Skip to content

Commit f5e36e9

Browse files
committed
Don't skip paths by default
1 parent 5ea9260 commit f5e36e9

5 files changed

Lines changed: 49 additions & 14 deletions

File tree

cli/src/Cli.elm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ type alias CliOptions =
5050
, overrides : List OpenApi.Config.Path
5151
, writeMergedTo : Maybe String
5252
, noElmFormat : Bool
53+
, keepGoing : Bool
5354
}
5455

5556

@@ -96,6 +97,8 @@ program =
9697
(Cli.Option.optionalKeywordArg "write-merged-to")
9798
|> Cli.OptionsParser.with
9899
(Cli.Option.flag "no-elm-format")
100+
|> Cli.OptionsParser.with
101+
(Cli.Option.flag "keep-going")
99102
|> Cli.OptionsParser.withDoc
100103
([ ""
101104
, """version: 0.7.0"""
@@ -166,6 +169,7 @@ program =
166169
, formatOption "overrides" [ "Load an additional file to override parts of the original Open API file." ]
167170
, formatOption "write-merged-to" [ "Write the merged Open API spec to the given file." ]
168171
, formatOption "no-elm-format" [ "Don't run elm-format on the outputs." ]
172+
, formatOption "keep-going" [ "If a route can't be generated, skip it instead of erroring out." ]
169173
]
170174
|> String.join "\n\n"
171175
)
@@ -370,6 +374,7 @@ parseCliOptions cliOptions =
370374
|> OpenApi.Config.withGenerateTodos cliOptions.generateTodos
371375
|> OpenApi.Config.withAutoConvertSwagger cliOptions.autoConvertSwagger
372376
|> OpenApi.Config.withNoElmFormat cliOptions.noElmFormat
377+
|> OpenApi.Config.withKeepGoing cliOptions.keepGoing
373378
|> maybe OpenApi.Config.withSwaggerConversionUrl cliOptions.swaggerConversionUrl
374379
|> maybe OpenApi.Config.withSwaggerConversionCommand
375380
(cliOptions.swaggerConversionCommand

src/CliMonad.elm

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import OpenApi exposing (OpenApi)
4444
import OpenApi.Config
4545
import Pretty
4646
import String.Extra
47+
import Triple.Extra
4748

4849

4950
type alias Message =
@@ -85,6 +86,7 @@ type alias Input =
8586
, namespace : List String
8687
, formats : FastDict.Dict InternalFormatName InternalFormat
8788
, warnOnMissingEnums : Bool
89+
, keepGoing : Bool
8890
}
8991

9092

@@ -126,6 +128,7 @@ run :
126128
, namespace : List String
127129
, formats : List OpenApi.Config.Format
128130
, warnOnMissingEnums : Bool
131+
, keepGoing : Bool
129132
}
130133
-> CliMonad (List Declaration)
131134
->
@@ -148,6 +151,7 @@ run oneOfDeclarations input (CliMonad x) =
148151
|> List.map toInternalFormat
149152
|> FastDict.fromList
150153
, warnOnMissingEnums = input.warnOnMissingEnums
154+
, keepGoing = input.keepGoing
151155
}
152156

153157
res : Result Message ( List Declaration, Output, Cache )
@@ -570,20 +574,28 @@ getApiSpec =
570574
CliMonad (\input cache -> Ok ( input.openApi, emptyOutput, cache ))
571575

572576

577+
{-| If the user has chosen to keep going in the face of errors, this will convert an error into a warning. Otherwise this returns the input
578+
-}
573579
errorToWarning : CliMonad a -> CliMonad (Maybe a)
574580
errorToWarning (CliMonad f) =
575581
CliMonad
576582
(\input cache ->
577-
case f input cache of
578-
Ok ( res, output, cache2 ) ->
579-
Ok ( Just res, output, cache2 )
583+
if input.keepGoing then
584+
case f input cache of
585+
Ok ( res, output, cache2 ) ->
586+
Ok ( Just res, output, cache2 )
580587

581-
Err { path, message } ->
582-
( Nothing
583-
, { emptyOutput | warnings = [ { path = path, message = message, details = Pretty.empty } ] }
584-
, cache
585-
)
586-
|> Ok
588+
Err { path, message } ->
589+
( Nothing
590+
, { emptyOutput | warnings = [ { path = path, message = message, details = Pretty.empty } ] }
591+
, cache
592+
)
593+
|> Ok
594+
595+
else
596+
Result.map
597+
(Triple.Extra.mapFirst Just)
598+
(f input cache)
587599
)
588600

589601

src/OpenApi/Config.elm

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
module OpenApi.Config exposing
22
( Config, EffectType(..), effectTypeToPackage, Format, Input, Path(..), Server(..)
33
, init, inputFrom, pathFromString
4-
, withAutoConvertSwagger, AutoConvertSwagger(..), withEffectTypes, withFormat, withFormats, withGenerateTodos, withInput, withSwaggerConversionCommand, withSwaggerConversionUrl, withNoElmFormat
4+
, withAutoConvertSwagger, AutoConvertSwagger(..), withEffectTypes, withFormat, withFormats, withGenerateTodos, withInput, withSwaggerConversionCommand, withSwaggerConversionUrl, withNoElmFormat, withKeepGoing
55
, withOutputModuleName, withOverrides, withServer, withWriteMergedTo, withWarnOnMissingEnums
6-
, autoConvertSwagger, inputs, outputDirectory, swaggerConversionCommand, swaggerConversionUrl, noElmFormat
6+
, autoConvertSwagger, inputs, outputDirectory, swaggerConversionCommand, swaggerConversionUrl, noElmFormat, keepGoing
77
, oasPath, overrides, writeMergedTo
88
, toGenerationConfig, Generate, pathToString
99
, defaultFormats
@@ -20,13 +20,13 @@ module OpenApi.Config exposing
2020
# Creation
2121
2222
@docs init, inputFrom, pathFromString
23-
@docs withAutoConvertSwagger, AutoConvertSwagger, withEffectTypes, withFormat, withFormats, withGenerateTodos, withInput, withSwaggerConversionCommand, withSwaggerConversionUrl, withNoElmFormat
23+
@docs withAutoConvertSwagger, AutoConvertSwagger, withEffectTypes, withFormat, withFormats, withGenerateTodos, withInput, withSwaggerConversionCommand, withSwaggerConversionUrl, withNoElmFormat, withKeepGoing
2424
@docs withOutputModuleName, withOverrides, withServer, withWriteMergedTo, withWarnOnMissingEnums
2525
2626
2727
# Config properties
2828
29-
@docs autoConvertSwagger, inputs, outputDirectory, swaggerConversionCommand, swaggerConversionUrl, noElmFormat
29+
@docs autoConvertSwagger, inputs, outputDirectory, swaggerConversionCommand, swaggerConversionUrl, noElmFormat, keepGoing
3030
3131
3232
# Input properties
@@ -83,6 +83,7 @@ type Config
8383
, staticFormats : List Format
8484
, dynamicFormats : List { format : String, basicType : Common.BasicType } -> List Format
8585
, noElmFormat : Bool
86+
, keepGoing : Bool
8687
}
8788

8889

@@ -242,6 +243,7 @@ init initialOutputDirectory =
242243
, staticFormats = defaultFormats
243244
, dynamicFormats = \_ -> []
244245
, noElmFormat = False
246+
, keepGoing = False
245247
}
246248
|> Config
247249

@@ -550,6 +552,11 @@ withNoElmFormat newNoElmFormat (Config config) =
550552
Config { config | noElmFormat = newNoElmFormat }
551553

552554

555+
withKeepGoing : Bool -> Config -> Config
556+
withKeepGoing newKeepGoing (Config config) =
557+
Config { config | keepGoing = newKeepGoing }
558+
559+
553560

554561
-------------
555562
-- Getters --
@@ -592,6 +599,12 @@ noElmFormat (Config config) =
592599
config.noElmFormat
593600

594601

602+
{-| -}
603+
keepGoing : Config -> Bool
604+
keepGoing (Config config) =
605+
config.keepGoing
606+
607+
595608
{-| -}
596609
oasPath : Input -> Path
597610
oasPath (Input input) =
@@ -624,6 +637,7 @@ type alias Generate =
624637
, server : Server
625638
, formats : List Format
626639
, warnOnMissingEnums : Bool
640+
, keepGoing : Bool
627641
}
628642

629643

@@ -657,6 +671,7 @@ toGenerationConfig formatsInput (Config config) augmentedInputs =
657671
, server = input.server
658672
, warnOnMissingEnums = input.warnOnMissingEnums
659673
, formats = config.staticFormats ++ config.dynamicFormats formatsInput
674+
, keepGoing = config.keepGoing
660675
}
661676
, spec
662677
)

src/OpenApi/Generate.elm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ files :
119119
, warnings : List Message
120120
, requiredPackages : FastSet.Set String
121121
}
122-
files { namespace, generateTodos, effectTypes, server, formats, warnOnMissingEnums } apiSpec =
122+
files { namespace, generateTodos, effectTypes, server, formats, warnOnMissingEnums, keepGoing } apiSpec =
123123
case extractEnums apiSpec of
124124
Err e ->
125125
Err e
@@ -148,6 +148,7 @@ files { namespace, generateTodos, effectTypes, server, formats, warnOnMissingEnu
148148
, namespace = namespace
149149
, formats = formats
150150
, warnOnMissingEnums = warnOnMissingEnums
151+
, keepGoing = keepGoing
151152
}
152153
|> Result.map
153154
(\{ declarations, warnings, requiredPackages } ->

tests/Test/OpenApi/Generate.elm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ fuzzTitle =
129129
, server = OpenApi.Config.Default
130130
, formats = OpenApi.Config.defaultFormats
131131
, warnOnMissingEnums = True
132+
, keepGoing = False
132133
}
133134
oas
134135
in
@@ -257,6 +258,7 @@ pr267 =
257258
, server = OpenApi.Config.Default
258259
, formats = OpenApi.Config.defaultFormats
259260
, warnOnMissingEnums = True
261+
, keepGoing = False
260262
}
261263
oas
262264
in

0 commit comments

Comments
 (0)