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
12 changes: 11 additions & 1 deletion cli/src/Cli.elm
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type alias CliOptions =
, server : OpenApi.Config.Server
, overrides : List OpenApi.Config.Path
, writeMergedTo : Maybe String
, noElmFormat : Bool
}


Expand Down Expand Up @@ -93,6 +94,8 @@ program =
)
|> Cli.OptionsParser.with
(Cli.Option.optionalKeywordArg "write-merged-to")
|> Cli.OptionsParser.with
(Cli.Option.flag "no-elm-format")
|> Cli.OptionsParser.withDoc """
version: 0.7.0

Expand Down Expand Up @@ -159,6 +162,7 @@ options:
--overrides Load an additional file to override parts of the original Open API file.

--write-merged-to Write the merged Open API spec to the given file.
--no-elm-format Don't run elm-format on the outputs.
"""
)

Expand Down Expand Up @@ -343,6 +347,7 @@ parseCliOptions cliOptions =
|> OpenApi.Config.withInput input
|> OpenApi.Config.withGenerateTodos cliOptions.generateTodos
|> OpenApi.Config.withAutoConvertSwagger cliOptions.autoConvertSwagger
|> OpenApi.Config.withNoElmFormat cliOptions.noElmFormat
|> maybe OpenApi.Config.withSwaggerConversionUrl cliOptions.swaggerConversionUrl
|> maybe OpenApi.Config.withSwaggerConversionCommand
(cliOptions.swaggerConversionCommand
Expand Down Expand Up @@ -451,7 +456,12 @@ withConfig config =
OpenApi.Config.toGenerationConfig (List.concat allFormats) config apiSpecs
|> generateFilesFromOpenApiSpecs
)
|> Pages.Script.Spinner.withStep "Format with elm-format" (onFirst attemptToFormat)
|> (if OpenApi.Config.noElmFormat config then
identity

else
Pages.Script.Spinner.withStep "Format with elm-format" (onFirst attemptToFormat)
)
|> Pages.Script.Spinner.withStep "Write to disk" (onFirst (writeSdkToDisk (OpenApi.Config.outputDirectory config)))
|> Pages.Script.Spinner.runSteps
|> BackendTask.map convertElmCodegenWarnings
Expand Down
2 changes: 2 additions & 0 deletions cli/src/TestGenScript.elm
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ run =
profileConfig =
-- Slimmed config for profiling
OpenApi.Config.init "./generated"
|> OpenApi.Config.withNoElmFormat True
|> OpenApi.Config.withInput additionalProperties
|> OpenApi.Config.withInput recursiveAllofRefs
|> OpenApi.Config.withInput overridingGlobalSecurity
Expand Down Expand Up @@ -142,6 +143,7 @@ run =
|> OpenApi.Config.withInput dbFahrplanApi
|> OpenApi.Config.withInput gitHub
|> OpenApi.Config.withInput telegramBot
|> OpenApi.Config.withNoElmFormat False
|> OpenApi.Config.withAutoConvertSwagger OpenApi.Config.AlwaysConvert
in
Pages.Script.withCliOptions programConfig
Expand Down
2 changes: 1 addition & 1 deletion 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": 32, "filePath": "src/OpenApi/Config.elm" },
{ "count": 30, "filePath": "src/OpenApi/Config.elm" },
{ "count": 5, "filePath": "src/OpenApi/Generate.elm" }
]
}
34 changes: 26 additions & 8 deletions src/OpenApi/Config.elm
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module OpenApi.Config exposing
( Config, EffectType(..), effectTypeToPackage, Format, Input, Path(..), Server(..)
, init, inputFrom, pathFromString
, withAutoConvertSwagger, AutoConvertSwagger(..), withEffectTypes, withFormat, withFormats, withGenerateTodos, withInput, withSwaggerConversionCommand, withSwaggerConversionUrl
, withAutoConvertSwagger, AutoConvertSwagger(..), withEffectTypes, withFormat, withFormats, withGenerateTodos, withInput, withSwaggerConversionCommand, withSwaggerConversionUrl, withNoElmFormat
, withOutputModuleName, withOverrides, withServer, withWriteMergedTo, withWarnOnMissingEnums
, autoConvertSwagger, inputs, outputDirectory, swaggerConversionCommand, swaggerConversionUrl
, autoConvertSwagger, inputs, outputDirectory, swaggerConversionCommand, swaggerConversionUrl, noElmFormat
, oasPath, overrides, writeMergedTo
, toGenerationConfig, Generate, pathToString
, defaultFormats
Expand All @@ -20,13 +20,13 @@ module OpenApi.Config exposing
# Creation

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


# Config properties

@docs autoConvertSwagger, inputs, outputDirectory, swaggerConversionCommand, swaggerConversionUrl
@docs autoConvertSwagger, inputs, outputDirectory, swaggerConversionCommand, swaggerConversionUrl, noElmFormat


# Input properties
Expand Down Expand Up @@ -82,6 +82,7 @@ type Config
, swaggerConversionCommand : Maybe { command : String, args : List String }
, staticFormats : List Format
, dynamicFormats : List { format : String, basicType : Common.BasicType } -> List Format
, noElmFormat : Bool
}


Expand Down Expand Up @@ -129,7 +130,8 @@ type EffectType
| LamderaProgramTestTaskRisky -- `Effect.Http.riskyTask` from lamdera/program-test


{-| -}
{-| Gets the package that an `EffectType` is defined in.
-}
effectTypeToPackage : EffectType -> Common.Package
effectTypeToPackage effectType =
case effectType of
Expand Down Expand Up @@ -176,14 +178,16 @@ effectTypeToPackage effectType =
Common.LamderaProgramTest


{-| -}
{-| One or multiple servers that the API will connect to.
-}
type Server
= Default
| Single String
| Multiple (Dict.Dict String String)


{-| -}
{-| A custom `format` for basic types.
-}
type alias Format =
{ basicType : Common.BasicType
, format : String
Expand All @@ -197,7 +201,8 @@ type alias Format =
}


{-| -}
{-| An input path. Can be either a local file or an URL.
-}
type Path
= File String -- swagger.json ./swagger.json /folder/swagger.json
| Url Url.Url -- https://petstore3.swagger.io/api/v3/openapi.json
Expand Down Expand Up @@ -236,6 +241,7 @@ init initialOutputDirectory =
, swaggerConversionCommand = Nothing
, staticFormats = defaultFormats
, dynamicFormats = \_ -> []
, noElmFormat = False
}
|> Config

Expand Down Expand Up @@ -538,6 +544,12 @@ withInput input (Config config) =
Config { config | inputs = input :: config.inputs }


{-| -}
withNoElmFormat : Bool -> Config -> Config
withNoElmFormat newNoElmFormat (Config config) =
Config { config | noElmFormat = newNoElmFormat }



-------------
-- Getters --
Expand Down Expand Up @@ -574,6 +586,12 @@ inputs (Config config) =
List.reverse config.inputs


{-| -}
noElmFormat : Config -> Bool
noElmFormat (Config config) =
config.noElmFormat


{-| -}
oasPath : Input -> Path
oasPath (Input input) =
Expand Down