Skip to content

Commit

Permalink
Merge pull request #139 from wolfadex/dump
Browse files Browse the repository at this point in the history
Allow dumping the merged file
  • Loading branch information
miniBill authored Aug 12, 2024
2 parents adbf321 + 1abe230 commit 3b16258
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/Cli.elm
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type alias CliOptions =
, swaggerConversionCommandArgs : List String
, server : OpenApi.Generate.Server
, overrides : List String
, writeMergedTo : Maybe String
}


Expand Down Expand Up @@ -79,6 +80,8 @@ program =
)
|> Cli.OptionsParser.with
(Cli.Option.keywordArgList "overrides")
|> Cli.OptionsParser.with
(Cli.Option.optionalKeywordArg "write-merged-to")
|> Cli.OptionsParser.withDoc """
version: 0.6.1
Expand Down Expand Up @@ -140,6 +143,8 @@ options:
instead of failing use one of: `yes`, `y`, `true`.
--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.
"""
)

Expand Down Expand Up @@ -289,6 +294,13 @@ run =
cliOptions.overrides
|> Pages.Script.Spinner.withStep "Merging overrides" mergeOverrides
)
|> (case cliOptions.writeMergedTo of
Nothing ->
identity

Just destination ->
Pages.Script.Spinner.withStep "Writing merged OAS" (writeMerged destination)
)
|> Pages.Script.Spinner.withStep "Parse OAS" (decodeOpenApiSpecOrFail { hasAttemptedToConvertFromSwagger = False } cliOptions)
|> Pages.Script.Spinner.withStep "Generate Elm modules"
(generateFileFromOpenApiSpec
Expand Down Expand Up @@ -342,6 +354,16 @@ mergeOverrides ( overrides, original ) =
|> BackendTask.fromResult


writeMerged : String -> Json.Decode.Value -> BackendTask.BackendTask FatalError.FatalError Json.Decode.Value
writeMerged destination spec =
Pages.Script.writeFile
{ path = destination
, body = spec |> Json.Encode.encode 4
}
|> BackendTask.allowFatal
|> BackendTask.map (\_ -> spec)


decodeOpenApiSpecOrFail : { hasAttemptedToConvertFromSwagger : Bool } -> CliOptions -> Json.Decode.Value -> BackendTask.BackendTask FatalError.FatalError OpenApi.OpenApi
decodeOpenApiSpecOrFail config cliOptions value =
value
Expand Down

0 comments on commit 3b16258

Please sign in to comment.