Derive schemes from endpoint :url #222
Open
+10
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
When handling url schemes (http/https), phoenix swagger currently does only take into account if there is set up a
:https
server in the endpoint config. Instead, it should first lookup if under the endpoint:url
config a custom scheme is defined.Problem
Currently, phoenix swagger is generating the base url with scheme “https” only if in the phoenix
endpoint_config
it is set as distinct:https
server. (see https://github.com/xerions/phoenix_swagger/blob/master/lib/mix/tasks/swagger.generate.ex#L178) Thecollect_host_from_endpoint
. It does not consider the endpoint:url
config, in particular it ignores:scheme
(see below).On the other side, it is a common scenario to run one's application behind a (https) reverse proxy. It is therefore in the general interest, to allow generating https base paths for the client communication – although the phoenix server is running only in https.
The phoenix docs are clear on the issue. It says that
:url
is for “generating URLs throughout the app”. https://hexdocs.pm/phoenix/Phoenix.Endpoint.html Moreover, the docs explicitly mention the reverse proxy issue:The :scheme option accepts "http" and "https" values. Default value is infered from top level :http or :https option. It is useful when hosting Phoenix behind a load balancer or reverse proxy and terminating SSL there.
This PR alters the behavior of phoenix swagger to that extent, that first the configuration in
:url
is taken into account.