Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow the baseUrl of elixir APIs to be overridden #12268

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,11 @@ end
Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
be found at [https://hexdocs.pm/{{#underscored}}{{packageName}}{{/underscored}}](https://hexdocs.pm/{{#underscored}}{{packageName}}{{/underscored}}).


## Configuration

You can override the URL of your server (e.g. if you have a separate development and production server in your configuration files.
```elixir
config :{{#underscored}}{{appName}}{{/underscored}}, base_url: "{{{basePath}}}"
```
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ use Mix.Config
# config :logger, level: :info
#

config :{{#underscored}}{{appName}}{{/underscored}}, base_url: "{{{basePath}}}"

# It is also possible to import configuration files, relative to this
# directory. For example, you can emulate configuration per environment
# by uncommenting the line below and defining dev.exs, test.exs and such.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ defmodule {{moduleName}}.Connection do
use Tesla

# Add any middleware here (authentication)
plug Tesla.Middleware.BaseUrl, "{{{basePath}}}"
plug Tesla.Middleware.BaseUrl, Application.get_env(:{{#underscored}}{{appName}}{{/underscored}}, :base_url)
johannesE marked this conversation as resolved.
Show resolved Hide resolved
plug Tesla.Middleware.Headers, [{"user-agent", "Elixir"}]
plug Tesla.Middleware.EncodeJson, engine: Poison

Expand Down
8 changes: 8 additions & 0 deletions samples/client/petstore/elixir/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,11 @@ end
Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
be found at [https://hexdocs.pm/openapi_petstore](https://hexdocs.pm/openapi_petstore).


## Configuration

You can override the URL of your server (e.g. if you have a separate development and production server in your configuration files.
```elixir
config :open_api_petstore, base_url: "http://petstore.swagger.io:80/v2"
```
2 changes: 2 additions & 0 deletions samples/client/petstore/elixir/config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ use Mix.Config
# config :logger, level: :info
#

config :open_api_petstore, base_url: "http://petstore.swagger.io:80/v2"

# It is also possible to import configuration files, relative to this
# directory. For example, you can emulate configuration per environment
# by uncommenting the line below and defining dev.exs, test.exs and such.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ defmodule OpenapiPetstore.Connection do
use Tesla

# Add any middleware here (authentication)
plug Tesla.Middleware.BaseUrl, "http://petstore.swagger.io:80/v2"
plug Tesla.Middleware.BaseUrl, Application.get_env(:open_api_petstore, :base_url)
plug Tesla.Middleware.Headers, [{"user-agent", "Elixir"}]
plug Tesla.Middleware.EncodeJson, engine: Poison

Expand Down