Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix elm-pages headers, deduplicate code #174

Merged
merged 1 commit into from
Dec 9, 2024
Merged
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
28 changes: 11 additions & 17 deletions src/OpenApi/Generate.elm
Original file line number Diff line number Diff line change
Expand Up @@ -708,9 +708,13 @@ toRequestFunctions server effectTypes method pathUrl operation =
CliMonad.succeed [ ( Common.UnsafeName "body", Gen.Bytes.annotation_.bytes ) ]
|> CliMonad.withRequiredPackage "elm/bytes"

headersFromList : (Elm.Expression -> Elm.Expression -> Elm.Expression) -> AuthorizationInfo -> Elm.Expression -> List ( Elm.Expression, Elm.Expression, Bool ) -> Elm.Expression
headersFromList f auth config headerParams =
headersFromList : (Elm.Expression -> Elm.Expression -> Elm.Expression) -> AuthorizationInfo -> Elm.Expression -> List (Elm.Expression -> ( Elm.Expression, Elm.Expression, Bool )) -> Elm.Expression
headersFromList f auth config headerFunctions =
let
headerParams : List ( Elm.Expression, Elm.Expression, Bool )
headerParams =
List.map (\toHeader -> toHeader config) headerFunctions

hasMaybes : Bool
hasMaybes =
List.any (\( _, _, isMaybe ) -> isMaybe) headerParams
Expand Down Expand Up @@ -857,9 +861,7 @@ toRequestFunctions server effectTypes method pathUrl operation =
[ ( "url", replaced config )
, ( "method", Elm.string method )
, ( "headers"
, toHeaderParams
|> List.map (\f -> f config)
|> headersFromList Gen.Http.call_.header auth config
, headersFromList Gen.Http.call_.header auth config toHeaderParams
)
, ( "expect", (expect <| toMsg config).core )
, ( "body", (toBody config).core )
Expand Down Expand Up @@ -931,9 +933,7 @@ toRequestFunctions server effectTypes method pathUrl operation =
[ ( "url", replaced config )
, ( "method", Elm.string method )
, ( "headers"
, toHeaderParams
|> List.map (\f -> f config)
|> headersFromList Gen.Http.call_.header auth config
, headersFromList Gen.Http.call_.header auth config toHeaderParams
)
, ( "resolver", resolver.core )
, ( "body", (toBody config).core )
Expand Down Expand Up @@ -1010,9 +1010,7 @@ toRequestFunctions server effectTypes method pathUrl operation =
[ ( "url", replaced config )
, ( "method", Elm.string method )
, ( "headers"
, toHeaderParams
|> List.map (\f -> f config)
|> headersFromList Gen.Http.call_.header auth config
, headersFromList Elm.tuple auth config toHeaderParams
)
, ( "body", (toBody config).elmPages )
, ( "retries", Gen.Maybe.make_.nothing )
Expand Down Expand Up @@ -1083,9 +1081,7 @@ toRequestFunctions server effectTypes method pathUrl operation =
[ ( "url", replaced config )
, ( "method", Elm.string method )
, ( "headers"
, toHeaderParams
|> List.map (\f -> f config)
|> headersFromList Gen.Effect.Http.call_.header auth config
, headersFromList Gen.Effect.Http.call_.header auth config toHeaderParams
)
, ( "expect", (expect <| toMsg config).lamderaProgramTest )
, ( "body", (toBody config).lamderaProgramTest )
Expand Down Expand Up @@ -1138,9 +1134,7 @@ toRequestFunctions server effectTypes method pathUrl operation =
[ ( "url", replaced config )
, ( "method", Elm.string method )
, ( "headers"
, toHeaderParams
|> List.map (\f -> f config)
|> headersFromList Gen.Effect.Http.call_.header auth config
, headersFromList Gen.Effect.Http.call_.header auth config toHeaderParams
)
, ( "resolver", resolver.lamderaProgramTest )
, ( "body", (toBody config).lamderaProgramTest )
Expand Down
Loading