View Source OpenApiSpex.Plug.SwaggerUI (open_api_spex v3.16.0)

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

Functions

Initializes the plug.

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 the SwaggerUIBundle.initOAuth() function.
  • 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