Packages
PhoenixSwagger is the library that provides swagger integration to the phoenix web framework.
Current section
30 Versions
Jump to
Current section
30 Versions
Compare versions
5
files changed
+31
additions
-9
deletions
| @@ -1,3 +1,8 @@ | |
| 1 | + # 0.6.1 |
| 2 | + |
| 3 | + * Provide default host and port when generating swagger host config |
| 4 | + * Suppress host config when dynamic hostname or port are used |
| 5 | + |
| 1 6 | # 0.6.0 |
| 2 7 | |
| 3 8 | * Use phoenix 1.3 conventions for mix tasks and module names |
| @@ -20,7 +20,7 @@ dependencies in the `mix.exs` file: | |
| 20 20 | ```elixir |
| 21 21 | def deps do |
| 22 22 | [ |
| 23 | - {:phoenix_swagger, "~> 0.6.0"}, |
| 23 | + {:phoenix_swagger, "~> 0.6.1"}, |
| 24 24 | {:ex_json_schema, "~> 0.5"} # optional |
| 25 25 | ] |
| 26 26 | end |
| @@ -67,6 +67,21 @@ function. | |
| 67 67 | See the [swaggerObject specification](http://swagger.io/specification/#swaggerObject) for details |
| 68 68 | of other information that can be included. |
| 69 69 | |
| 70 | + The swagger `host` value is built from the your phoenix `Endpoint` `url` config. |
| 71 | + |
| 72 | + ```elixir |
| 73 | + # config.exs |
| 74 | + config :my_app, MyApp.Web.Endpoint, |
| 75 | + url: [host: "localhost"], # "host": "localhost:4000" in generated swagger |
| 76 | + ``` |
| 77 | + |
| 78 | + If the `host` is configured to be set dynamically, the swagger host will be omitted. SwaggerUI will default to sending requests to the same host that is serving the swagger file. |
| 79 | + |
| 80 | + ```elixir |
| 81 | + # prod.exs |
| 82 | + config :my_app, MyApp.Web.Endpoint, |
| 83 | + url: [host: {:system, "HOST"}, port: {:system, "PORT"}], # No "host" in generated swagger |
| 84 | + ``` |
| 70 85 | |
| 71 86 | ## Swagger Path DSL |
| @@ -65,4 +65,4 @@ | |
| 65 65 | {<<"name">>,<<"plug">>}, |
| 66 66 | {<<"optional">>,false}, |
| 67 67 | {<<"requirement">>,<<"~> 1.1">>}]]}. |
| 68 | - {<<"version">>,<<"0.6.0">>}. |
| 68 | + {<<"version">>,<<"0.6.1">>}. |
| @@ -184,13 +184,15 @@ defmodule Mix.Tasks.Phx.Swagger.Generate do | |
| 184 184 | |
| 185 185 | defp collect_host_from_endpoint(swagger_map, endpoint_config) do |
| 186 186 | url = Keyword.get(endpoint_config, :url) |
| 187 | - host = Keyword.get(url, :host) |
| 188 | - port = Keyword.get(url, :port) |
| 189 | - host_address = [host, port] |
| 190 | - |> Enum.filter(&(!is_nil(&1))) |
| 191 | - |> Enum.join(":") |
| 187 | + host = Keyword.get(url, :host, "localhost") |
| 188 | + port = Keyword.get(url, :port, 4000) |
| 192 189 | |
| 193 | - swagger_map = Map.put_new(swagger_map, :host, host_address) |
| 190 | + swagger_map = |
| 191 | + if is_binary(host) and (is_integer(port) or is_binary(port)) do |
| 192 | + Map.put_new(swagger_map, :host, "#{host}:#{port}") |
| 193 | + else |
| 194 | + swagger_map # host / port may be {:system, "ENV_VAR"} tuples |
| 195 | + end |
| 194 196 | |
| 195 197 | case endpoint_config[:https] do |
| 196 198 | nil -> |
| @@ -1,7 +1,7 @@ | |
| 1 1 | defmodule PhoenixSwagger.Mixfile do |
| 2 2 | use Mix.Project |
| 3 3 | |
| 4 | - @version "0.6.0" |
| 4 | + @version "0.6.1" |
| 5 5 | |
| 6 6 | def project do |
| 7 7 | [app: :phoenix_swagger, |