View Source OpenApiSpex.Plug.SwaggerUI (open_api_spex v3.21.2)
Module plug that serves SwaggerUI.
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
SwaggerUI can be configured through plug opts
.
All options will be converted from snake_case
to camelCase
and forwarded to the SwaggerUIBundle
constructor.
See the swagger-ui configuration docs for details.
Should dynamic configuration be required, the config_url
option can be set to an API endpoint that will provide additional config.
Example
scope "/" do
pipe_through :browser # Use the default browser stack
get "/", MyAppWeb.PageController, :index
get "/swaggerui", OpenApiSpex.Plug.SwaggerUI,
path: "/api/openapi",
default_model_expand_depth: 3,
display_operation_id: true
end
# Other scopes may use custom stacks.
scope "/api" do
pipe_through :api
resources "/users", MyAppWeb.UserController, only: [:index, :create, :show]
get "/openapi", OpenApiSpex.Plug.RenderSpec, :show
end
# Use a different Swagger UI version
scope "/" do
pipe_through :browser
get "/swaggerui", OpenApiSpex.Plug.SwaggerUI,
path: "/api/openapi",
swagger_ui_js_bundle_url: "https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/4.14.0/swagger-ui-bundle.js",
swagger_ui_js_standalone_preset_url: "https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/4.14.0/swagger-ui-standalone-preset.js",
swagger_ui_css_url: "https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/4.14.0/swagger-ui.css"
end
Summary
Functions
Initializes the plug.
Options
:path
- Required. The URL path to the API definition.:oauth
- Optional. Config to pass to theSwaggerUIBundle.initOAuth()
function.:csp_nonce_assign_key
- Optional. An assign key to find the CSP nonce value used for assets. Supports eitheratom()
or a map of type%{optional(:script) => atom(), optional(:style) => atom()}
. You will probably want to set this on theSwaggerUIOAuth2Redirect
plug as well.:swagger_ui_js_bundle_url
- Optional. An URL to SwaggerUI JavaScript bundle.:swagger_ui_js_standalone_preset_url
- Optional. An URL to SwaggerUI JavaScript Standalone Preset.:swagger_ui_css_url
- Optional. An URL to SwaggerUI CSS bundle.- all other opts - forwarded to the
SwaggerUIBundle
constructor
Example
get "/swaggerui", OpenApiSpex.Plug.SwaggerUI,
path: "/api/openapi",
default_model_expand_depth: 3,
display_operation_id: true,
csp_nonce_assign_key: %{script: :script_src_nonce, style: :style_src_nonce}