Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion docs/generators/elixir.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|BasicAuth|✓|OAS2,OAS3
|ApiKey|✗|OAS2,OAS3
|OpenIDConnect|✗|OAS3
|BearerToken||OAS3
|BearerToken||OAS3
|OAuth2_Implicit|✓|OAS2,OAS3
|OAuth2_Password|✗|OAS2,OAS3
|OAuth2_ClientCredentials|✗|OAS2,OAS3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ public ElixirClientCodegen() {
.includeDocumentationFeatures(DocumentationFeature.Readme)
.securityFeatures(EnumSet.of(
SecurityFeature.OAuth2_Implicit,
SecurityFeature.BasicAuth))
SecurityFeature.BasicAuth,
SecurityFeature.BearerToken))
.excludeGlobalFeatures(
GlobalFeature.XMLStructureDefinitions,
GlobalFeature.Callbacks,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ defmodule {{moduleName}}.Connection do
- `username`: A username for basic authentication.
- `password`: A password for basic authentication.
{{/hasHttpBasicMethods}}
{{#hasHttpBearerMethods}}
- `bearer_token`: A bearer token for bearer authentication.
Copy link
Contributor Author

@efcasado efcasado Apr 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I considered using token, but I noticed is already used by the OAuth2 implementation.

{{/hasHttpBearerMethods}}
"""
@type options :: [
{:base_url, String.t()},
Expand All @@ -64,6 +67,9 @@ defmodule {{moduleName}}.Connection do
{:username, String.t() | nil},
{:password, String.t() | nil},
{{/hasHttpBasicMethods}}
{{#hasHttpBearerMethods}}
{:bearer_token, String.t() | nil},
{{/hasHttpBearerMethods}}
]

@doc "Forward requests to Tesla."
Expand Down Expand Up @@ -240,6 +246,11 @@ defmodule {{moduleName}}.Connection do
end
{{/hasHttpBasicMethods}}

{{#hasHttpBearerMethods}}
bearer_token = Keyword.get(options, :bearer_token)
middleware = [{Tesla.Middleware.BearerAuth, token: bearer_token} | middleware]
{{/hasHttpBearerMethods}}

{{#hasOAuthMethods}}
middleware =
if token = Keyword.get(options, :token) do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ defmodule OpenapiPetstore.Connection do
fetcher function.
- `username`: A username for basic authentication.
- `password`: A password for basic authentication.
- `bearer_token`: A bearer token for bearer authentication.
"""
@type options :: [
{:base_url, String.t()},
Expand All @@ -54,6 +55,7 @@ defmodule OpenapiPetstore.Connection do
{:token_scopes, list(String.t())},
{:username, String.t() | nil},
{:password, String.t() | nil},
{:bearer_token, String.t() | nil},
]

@doc "Forward requests to Tesla."
Expand Down Expand Up @@ -175,6 +177,9 @@ defmodule OpenapiPetstore.Connection do
middleware
end

bearer_token = Keyword.get(options, :bearer_token)
middleware = [{Tesla.Middleware.BearerAuth, token: bearer_token} | middleware]

middleware =
if token = Keyword.get(options, :token) do
scopes = Keyword.get(options, :token_scopes, @default_scopes)
Expand Down
Loading