11module 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
@@ -208,7 +209,8 @@ type Path
208209 | Url Url . Url -- https://petstore3.swagger.io/api/v3/openapi.json
209210
210211
211- {- | -}
212+ {- | Builds a `Path`. If the file is a valid URL, it will be used as such, otherwise it will be interpreted as a local file path.
213+ -}
212214pathFromString : String -> Path
213215pathFromString path =
214216 case Url . fromString path of
@@ -230,7 +232,15 @@ pathToString pathType =
230232 Url . toString url
231233
232234
233- {- | -}
235+ {- | Create an empty `Config` with no inputs and a given output directory.
236+
237+ The default options are to:
238+
239+ - run elm-format;
240+ - ask before converting Swagger specs to OpenAPI specs;
241+ - fail rather than generating `Debug.todo` or skipping unimplemented paths.
242+
243+ -}
234244init : String -> Config
235245init initialOutputDirectory =
236246 { inputs = []
@@ -242,6 +252,7 @@ init initialOutputDirectory =
242252 , staticFormats = defaultFormats
243253 , dynamicFormats = \ _ -> []
244254 , noElmFormat = False
255+ , keepGoing = False
245256 }
246257 |> Config
247258
@@ -266,7 +277,16 @@ inputFrom path =
266277-- -----------
267278
268279
269- {- | -}
280+ {- | The built-in formats:
281+
282+ - `date-time`
283+ - `date`
284+ - `uri`
285+ - `uuid`
286+ - `byte`
287+ - `password`
288+
289+ -}
270290defaultFormats : List Format
271291defaultFormats =
272292 [ dateTimeFormat
@@ -550,6 +570,11 @@ withNoElmFormat newNoElmFormat (Config config) =
550570 Config { config | noElmFormat = newNoElmFormat }
551571
552572
573+ withKeepGoing : Bool -> Config -> Config
574+ withKeepGoing newKeepGoing ( Config config) =
575+ Config { config | keepGoing = newKeepGoing }
576+
577+
553578
554579-- -----------
555580-- Getters --
@@ -592,6 +617,12 @@ noElmFormat (Config config) =
592617 config. noElmFormat
593618
594619
620+ {- | -}
621+ keepGoing : Config -> Bool
622+ keepGoing ( Config config) =
623+ config. keepGoing
624+
625+
595626{- | -}
596627oasPath : Input -> Path
597628oasPath ( Input input) =
@@ -624,6 +655,7 @@ type alias Generate =
624655 , server : Server
625656 , formats : List Format
626657 , warnOnMissingEnums : Bool
658+ , keepGoing : Bool
627659 }
628660
629661
@@ -657,6 +689,7 @@ toGenerationConfig formatsInput (Config config) augmentedInputs =
657689 , server = input. server
658690 , warnOnMissingEnums = input. warnOnMissingEnums
659691 , formats = config. staticFormats ++ config. dynamicFormats formatsInput
692+ , keepGoing = config. keepGoing
660693 }
661694 , spec
662695 )
0 commit comments