diff --git a/docs/generators/elixir.md b/docs/generators/elixir.md index 8f7ec5a796c..9d76b6b09f5 100644 --- a/docs/generators/elixir.md +++ b/docs/generators/elixir.md @@ -188,7 +188,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 diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ElixirClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ElixirClientCodegen.java index edea3a420a6..05b626fdc1a 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ElixirClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ElixirClientCodegen.java @@ -71,7 +71,8 @@ public class ElixirClientCodegen extends DefaultCodegen { .includeDocumentationFeatures(DocumentationFeature.Readme) .securityFeatures(EnumSet.of( SecurityFeature.OAuth2_Implicit, - SecurityFeature.BasicAuth)) + SecurityFeature.BasicAuth, + SecurityFeature.BearerToken)) .excludeGlobalFeatures( GlobalFeature.XMLStructureDefinitions, GlobalFeature.Callbacks, diff --git a/modules/openapi-generator/src/main/resources/elixir/connection.ex.mustache b/modules/openapi-generator/src/main/resources/elixir/connection.ex.mustache index 09fb6d5dc0a..f0bcb4754fe 100644 --- a/modules/openapi-generator/src/main/resources/elixir/connection.ex.mustache +++ b/modules/openapi-generator/src/main/resources/elixir/connection.ex.mustache @@ -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. + {{/hasHttpBearerMethods}} """ @type options :: [ {:base_url, String.t()}, @@ -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." @@ -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 diff --git a/samples/client/petstore/elixir/lib/openapi_petstore/connection.ex b/samples/client/petstore/elixir/lib/openapi_petstore/connection.ex index 61f3fc2cd56..067cbe05ad4 100644 --- a/samples/client/petstore/elixir/lib/openapi_petstore/connection.ex +++ b/samples/client/petstore/elixir/lib/openapi_petstore/connection.ex @@ -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()}, @@ -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." @@ -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)