Skip to content

Commit

Permalink
Merge pull request #96 from 0xAX/disable-validator
Browse files Browse the repository at this point in the history
Disable validation of swagger-ui by default
  • Loading branch information
surik authored May 9, 2017
2 parents e7e5c2a + cb4ec18 commit f6f41aa
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# 0.6.2

* fix path assignation of a swagger specification file in UI plug
* add `disable_validator` option to disable/enable validation of a
swagger schema.

# 0.6.1

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ Add a swagger scope to your router, and forward all requests to SwaggerUI

```elixir
scope "/api/swagger" do
forward "/", PhoenixSwagger.Plug.SwaggerUI, otp_app: :myapp, swagger_file: "swagger.json"
forward "/", PhoenixSwagger.Plug.SwaggerUI, otp_app: :myapp, swagger_file: "swagger.json", opts: [disable_validator: true]
end
```

Expand Down
12 changes: 10 additions & 2 deletions lib/phoenix_swagger/plug/swaggerui.ex
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ defmodule PhoenixSwagger.Plug.SwaggerUI do
}
window.swaggerUi = new SwaggerUi({
url: url,
<%= validator_url %>
dom_id: "swagger-ui-container",
supportedSubmitMethods: ['get', 'post', 'put', 'delete', 'patch'],
onComplete: function(swaggerApi, swaggerUi){
Expand Down Expand Up @@ -165,8 +166,15 @@ defmodule PhoenixSwagger.Plug.SwaggerUI do
@doc """
Plug.init callback
"""
def init(otp_app: app, swagger_file: swagger_file) do
body = EEx.eval_string(@template, spec_url: swagger_file)
def init(otp_app: app, swagger_file: swagger_file, opts: opts) do
disable_validator = Keyword.get(opts, :disable_validator, false)
validator_url = cond do
disable_validator == true ->
"validatorUrl: null,"
true ->
""
end
body = EEx.eval_string(@template, spec_url: swagger_file, validator_url: validator_url)
swagger_file_path = Path.join(["priv", "static", swagger_file])
[app: app, body: body, spec_url: swagger_file, swagger_file_path: swagger_file_path]
end
Expand Down

0 comments on commit f6f41aa

Please sign in to comment.