View Source OpenApiSpex.Plug.SwaggerUI (open_api_spex v3.20.1)
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
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
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
Link to this section Summary
Link to this section Functions
Initializes the plug.
options
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.- all other opts - forwarded to the
SwaggerUIBundle
constructor
example
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}