Allow the baseUrl of elixir APIs to be overridden (#12268)

* Allow the baseUrl of elixir APIs to be overridden

* Run generator

* Add missing `:`

* Update modules/openapi-generator/src/main/resources/elixir/connection.ex.mustache

Co-authored-by: Michael Ramstein <633688+mrmstn@users.noreply.github.com>

* Generate sample with new change

Co-authored-by: Joe Eifert <joe@databerg.rocks>
Co-authored-by: Michael Ramstein <633688+mrmstn@users.noreply.github.com>
This commit is contained in:
Johannes
2022-05-01 09:48:52 +02:00
committed by GitHub
parent 036e22b359
commit 3e5ec3c6ef
6 changed files with 22 additions and 2 deletions

View File

@@ -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}}}"
```

View File

@@ -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.

View File

@@ -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, "{{{basePath}}}")
plug Tesla.Middleware.Headers, [{"user-agent", "Elixir"}]
plug Tesla.Middleware.EncodeJson, engine: Poison

View File

@@ -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"
```

View File

@@ -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.

View File

@@ -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, "http://petstore.swagger.io:80/v2")
plug Tesla.Middleware.Headers, [{"user-agent", "Elixir"}]
plug Tesla.Middleware.EncodeJson, engine: Poison