Skip to content

Conversation

D4no0
Copy link

@D4no0 D4no0 commented Sep 7, 2022

This PR is related to #492

You are able now to define configs in the following way:

defmodule RuntimeConfig do
  def on_complete do
    "function() { ui.preauthorizeApiKey("bearer", "your generated token here"); }"
  end
end

scope "/" do
  pipe_through :browser # Use the default browser stack
  get "/swaggerui", OpenApiSpex.Plug.SwaggerUI,
    path: "/api/openapi",
    on_complete: {RuntimeConfig, :on_complete}
end

The configuration is evaluated each time the call/2 function from the plug is invoked.


defmodule RuntimeConfig do
def on_complete do
"function() { ui.preauthorizeApiKey("bearer", "your generated token here"); }"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please escape double quotes or use the ~S sigil.

## Runtime Configuration

SwaggerUI also accepts functions as parameters, allowing runtime configurations.
Because of limitations of `router.ex` file, the functions can be defined only as: `{module, function_name}`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The SwaggerUI module is a Plug, it can be used even by a non-phoenix app specifying its routes in a router.ex.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah my bad, I will update the documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants