From ce975df7536fad745c15929deb23698efd25512b Mon Sep 17 00:00:00 2001 From: Leonardo Taglialegne Date: Thu, 2 Oct 2025 23:43:08 +0200 Subject: [PATCH 1/2] Support cookie auth --- src/OpenApi/Generate.elm | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/OpenApi/Generate.elm b/src/OpenApi/Generate.elm index 0cb115d..46ed659 100644 --- a/src/OpenApi/Generate.elm +++ b/src/OpenApi/Generate.elm @@ -1468,7 +1468,31 @@ operationToAuthorizationInfo operation = |> CliMonad.succeed OpenApi.SecurityScheme.Cookie -> - CliMonad.todoWithDefault acc "Unsupported security schema: ApiKey in Cookie" + if Dict.member "Cookie" acc.headers then + CliMonad.todoWithDefault acc "Cookie header already set" + + else + CliMonad.succeed + { acc + | headers = + Dict.insert "Cookie" + (\config -> + Elm.Op.append + (Elm.string (apiKey.name ++ "=")) + (config + |> Elm.get "authorization" + |> Elm.get cleanName + ) + ) + acc.headers + , params = + Dict.insert "authorization" + (Dict.insert cleanName Elm.Annotation.string <| + Maybe.withDefault Dict.empty <| + Dict.get "authorization" acc.params + ) + acc.params + } OpenApi.SecurityScheme.Http details -> case details.scheme of From 8c728391d342a354e9e2ba22012945286e79c032 Mon Sep 17 00:00:00 2001 From: Leonardo Taglialegne Date: Mon, 17 Nov 2025 13:27:19 +0100 Subject: [PATCH 2/2] Add example for cookie auth --- cli/example/cookie-auth.yaml | 28 ++++++++++++++++++++++++++++ cli/src/TestGenScript.elm | 5 +++++ 2 files changed, 33 insertions(+) create mode 100644 cli/example/cookie-auth.yaml diff --git a/cli/example/cookie-auth.yaml b/cli/example/cookie-auth.yaml new file mode 100644 index 0000000..d767fba --- /dev/null +++ b/cli/example/cookie-auth.yaml @@ -0,0 +1,28 @@ +openapi: 3.0.4 + +info: + title: Cookie auth + version: 1.0.0 +paths: + /users: + get: + security: + - cookieAuth: [] + description: Returns a list of users. + responses: + "200": + description: OK + content: + application/json: + schema: + type: string + +components: + securitySchemes: + cookieAuth: + type: apiKey + in: cookie + name: COOKIE-MONSTER! + +security: + - cookieAuth: [] diff --git a/cli/src/TestGenScript.elm b/cli/src/TestGenScript.elm index 351e891..e5daabb 100644 --- a/cli/src/TestGenScript.elm +++ b/cli/src/TestGenScript.elm @@ -86,6 +86,10 @@ run = nullableEnum = OpenApi.Config.inputFrom (OpenApi.Config.File "./example/nullable-enum.yaml") + cookieAuth : OpenApi.Config.Input + cookieAuth = + OpenApi.Config.inputFrom (OpenApi.Config.File "./example/cookie-auth.yaml") + config : OpenApi.Config.Config config = OpenApi.Config.init "./generated" @@ -106,6 +110,7 @@ run = |> OpenApi.Config.withInput anyOfEnums |> OpenApi.Config.withInput binaryResponse |> OpenApi.Config.withInput nullableEnum + |> OpenApi.Config.withInput cookieAuth in Pages.Script.withoutCliOptions (BackendTask.doEach