Skip to content

Commit

Permalink
Fix elm-pages headers, deduplicate code
Browse files Browse the repository at this point in the history
  • Loading branch information
miniBill committed Dec 9, 2024
1 parent deb4565 commit 7cf0eb3
Showing 1 changed file with 11 additions and 17 deletions.
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

0 comments on commit 7cf0eb3

Please sign in to comment.