Skip to content

Commit

Permalink
Add support for the http + bearer security scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfadex committed Nov 10, 2024
1 parent 25fca98 commit 491a15d
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions src/OpenApi/Generate.elm
Original file line number Diff line number Diff line change
Expand Up @@ -1677,8 +1677,42 @@ operationToAuthorizationInfo operation =
OpenApi.SecurityScheme.Cookie ->
CliMonad.todoWithDefault acc "Unsupported security schema: ApiKey in Cookie"

OpenApi.SecurityScheme.Http _ ->
CliMonad.todoWithDefault acc "Unsupported security schema: Http"
OpenApi.SecurityScheme.Http details ->
case details.scheme of
"bearer" ->
let
unsafeName : Common.UnsafeName
unsafeName =
Common.UnsafeName (String.toLower name)

cleanName : String
cleanName =
Common.toValueName unsafeName
in
{ acc
| headers =
Dict.insert "authorization"
(\config ->
Elm.Op.append
(Elm.string "Bearer ")
(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
}
|> CliMonad.succeed

unsupportedScheme ->
CliMonad.todoWithDefault acc ("Unsupported security schema 'Http' with scheme of '" ++ unsupportedScheme ++ "'")

OpenApi.SecurityScheme.MutualTls ->
CliMonad.todoWithDefault acc "Unsupported security schema: MutualTls"
Expand Down

0 comments on commit 491a15d

Please sign in to comment.