Skip to content

Commit

Permalink
Use latest version of SwaggerUI by default, but allow it to be config…
Browse files Browse the repository at this point in the history
…ured
  • Loading branch information
jarmo committed Aug 17, 2024
1 parent 5dfd3f5 commit 5cfc49d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ mix help openapi.spec.yaml
Once your API spec is available through a route (see ["Serve the Spec"](#serve-the-spec)), the `OpenApiSpex.Plug.SwaggerUI` plug can be used to
serve a SwaggerUI interface. The `path:` plug option must be supplied to give the path to the API spec.

All JavaScript and CSS assets are sourced from cdnjs.cloudflare.com, rather than vendoring into this package.
All JavaScript and CSS assets are sourced from unpkg.com, rather than vendoring into this package.

```elixir
scope "/" do
Expand Down
16 changes: 13 additions & 3 deletions lib/open_api_spex/plug/swagger_ui.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ defmodule OpenApiSpex.Plug.SwaggerUI do
The full path to the API spec must be given as a plug option.
The API spec should be served at the given path, see `OpenApiSpex.Plug.RenderSpec`
## Configuring SwaggerUI version
Latest version of SwaggerUI is used by default, but it is possible to configure a different version:
```elixir
config :open_api_spex, :swagger_ui_version, "4.14.0"
```
## Configuring SwaggerUI
SwaggerUI can be configured through plug `opts`.
Expand Down Expand Up @@ -33,14 +41,16 @@ defmodule OpenApiSpex.Plug.SwaggerUI do
"""
@behaviour Plug

@swagger_ui_version Application.compile_env(:open_api_spex, :swagger_ui_version, "latest")

@html """
<!-- HTML for static distribution bundle build -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Swagger UI</title>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/4.14.0/swagger-ui.css" >
<link rel="stylesheet" type="text/css" href="https://unpkg.com/swagger-ui-dist@#{@swagger_ui_version}/swagger-ui.css" >
<link rel="icon" type="image/png" href="./favicon-32x32.png" sizes="32x32" />
<link rel="icon" type="image/png" href="./favicon-16x16.png" sizes="16x16" />
<%= if style_src_nonce do %>
Expand Down Expand Up @@ -70,8 +80,8 @@ defmodule OpenApiSpex.Plug.SwaggerUI do
<body>
<div id="swagger-ui"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/4.14.0/swagger-ui-bundle.js" charset="UTF-8"> </script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/4.14.0/swagger-ui-standalone-preset.js" charset="UTF-8"> </script>
<script src="https://unpkg.com/swagger-ui-dist@#{@swagger_ui_version}/swagger-ui-bundle.js" charset="UTF-8"> </script>
<script src="https://unpkg.com/swagger-ui-dist@#{@swagger_ui_version}/swagger-ui-standalone-preset.js" charset="UTF-8"> </script>
<%= if script_src_nonce do %>
<script nonce="<%= script_src_nonce %>">
<% else %>
Expand Down

0 comments on commit 5cfc49d

Please sign in to comment.