swagger-api/swagger-ui
Swagger UI renders interactive API docs from your OpenAPI (Swagger) spec, letting teams and consumers explore endpoints without implementation details. Available as npm packages (swagger-ui, swagger-ui-dist) and Docker for easy hosting and bundling.
Swagger UI accepts configuration parameters in three locations.
From lowest to highest precedence:
SwaggerUI({ ... }))configUrlParameters with dots in their names are single strings used to organize subordinate parameters, and are not indicative of a nested structure.
For readability, parameters are grouped by category and sorted alphabetically.
Type notations are formatted like so:
String="" means a String type with a default value of "".String=["a"*, "b", "c", "d"] means a String type that can be a, b, c, or d, with the * indicating that a is the default value.| Parameter name | Docker variable | Description |
|---|---|---|
configUrl |
CONFIG_URL |
String. URL to fetch external configuration document from. |
dom_id |
DOM_ID |
String, REQUIRED if domNode is not provided. The ID of a DOM element inside which SwaggerUI will put its user interface. |
domNode |
Unavailable | Element, REQUIRED if dom_id is not provided. The HTML DOM element inside which SwaggerUI will put its user interface. Overrides dom_id. |
spec |
SPEC |
Object={}. A JavaScript object describing the OpenAPI definition. When used, the url parameter will not be parsed. This is useful for testing manually-generated definitions without hosting them. |
url |
URL |
String. The URL pointing to API definition (normally swagger.json or swagger.yaml). Will be ignored if urls or spec is used. |
urls |
URLS |
Array. An array of API definition objects ([{url: "<url1>", name: "<name1>"},{url: "<url2>", name: "<name2>"}]) used by Topbar plugin. When used and Topbar plugin is enabled, the url parameter will not be parsed. Names and URLs must be unique among all items in this array, since they're used as identifiers. |
urls.primaryName |
URLS_PRIMARY_NAME |
String. When using urls, you can use this subparameter. If the value matches the name of a spec provided in urls, that spec will be displayed when Swagger UI loads, instead of defaulting to the first spec in urls. |
queryConfigEnabled |
QUERY_CONFIG_ENABLED |
Boolean=false. Enables overriding configuration parameters via URL search params. |
Read more about the plugin system in the Customization documentation.
| Parameter name | Docker variable | Description |
|---|---|---|
layout |
Unavailable | String="BaseLayout". The name of a component available via the plugin system to use as the top-level layout for Swagger UI. |
plugins |
Unavailable | Array=[]. An array of plugin functions to use in Swagger UI. |
presets |
Unavailable | Array=[SwaggerUI.presets.ApisPreset]. An array of presets to use in Swagger UI. Usually, you'll want to include ApisPreset if you use this option. |
| Parameter name | Docker variable | Description |
|---|---|---|
oauth2RedirectUrl |
OAUTH2_REDIRECT_URL |
String. OAuth redirect URL. |
requestInterceptor |
Unavailable | Function=(a => a). MUST be a function. Function to intercept remote definition, "Try it out", and OAuth 2.0 requests. Accepts one argument requestInterceptor(request) and must return the modified request, or a Promise that resolves to the modified request. |
request.curlOptions |
Unavailable | Array. If set, MUST be an array of command line options available to the curl command. This can be set on the mutated request in the requestInterceptor function. For example request.curlOptions = ["-g", "--limit-rate 20k"] |
responseInterceptor |
Unavailable | Function=(a => a). MUST be a function. Function to intercept remote definition, "Try it out", and OAuth 2.0 responses. Accepts one argument responseInterceptor(response) and must return the modified response, or a Promise that resolves to the modified response. |
showMutatedRequest |
SHOW_MUTATED_REQUEST |
Boolean=true. If set to true, uses the mutated request returned from a requestInterceptor to produce the curl command in the UI, otherwise the request before the requestInterceptor was applied is used. |
supportedSubmitMethods |
SUPPORTED_SUBMIT_METHODS |
Array=["get", "put", "post", "delete", "options", "head", "patch", "trace"]. List of HTTP methods that have the "Try it out" feature enabled. An empty array disables "Try it out" for all operations. This does not filter the operations from the display. |
validatorUrl |
VALIDATOR_URL |
String="https://validator.swagger.io/validator" OR null. By default, Swagger UI attempts to validate specs against swagger.io's online validator. You can use this parameter to set a different validator URL, for example for locally deployed validators (Validator Badge). Setting it to either none, 127.0.0.1 or localhost will disable validation. |
withCredentials |
WITH_CREDENTIALS |
Boolean=false If set to true, enables passing credentials, as defined in the Fetch standard, in CORS requests that are sent by the browser. Note that Swagger UI cannot currently set cookies cross-domain (see swagger-js#1163) - as a result, you will have to rely on browser-supplied cookies (which this setting enables sending) that Swagger UI cannot control. |
| Parameter name | Docker variable | Description |
|---|---|---|
modelPropertyMacro |
Unavailable | Function. Function to set default values to each property in model. Accepts one argument modelPropertyMacro(property), property is immutable |
parameterMacro |
Unavailable | Function. Function to set default value to parameters. Accepts two arguments parameterMacro(operation, parameter). Operation and parameter are objects passed for context, both remain immutable |
| Parameter name | Docker variable | Description |
|---|---|---|
persistAuthorization |
PERSIST_AUTHORIZATION |
Boolean=false. If set to true, it persists authorization data and it would not be lost on browser close/refresh |
💡 Take note! These are methods, not parameters.
| Method name | Docker variable | Description |
|---|---|---|
initOAuth |
See oauth2.md |
(configObj) => void. Provide Swagger UI with information about your OAuth server - see the OAuth 2.0 documentation for more information. |
preauthorizeBasic |
Unavailable | (authDefinitionKey, username, password) => action. Programmatically set values for a Basic authorization scheme. |
preauthorizeApiKey |
Unavailable | (authDefinitionKey, apiKeyValue) => action. Programmatically set values for an API key or Bearer authorization scheme. In case of OpenAPI 3.0 Bearer scheme, apiKeyValue must contain just the token itself without the Bearer prefix. |
If you're using the Docker image, you can also control most of these options with environment variables. Each parameter has its environment variable name noted, if available.
Below are the general guidelines for using the environment variable interface.
Set the value to whatever string you'd like, taking care to escape characters where necessary
Example:
FILTER="myFilterValue"
LAYOUT="BaseLayout"
Set the value to true or false.
Example:
DISPLAY_OPERATION_ID="true"
DEEP_LINKING="false"
Set the value to n, where n is the number you'd like to provide.
Example:
DEFAULT_MODELS_EXPAND_DEPTH="5"
DEFAULT_MODEL_EXPAND_DEPTH="7"
Set the value to the literal array value you'd like, taking care to escape characters where necessary.
Example:
SUPPORTED_SUBMIT_METHODS="[\"get\", \"post\"]"
URLS="[ { url: \"https://petstore.swagger.io/v2/swagger.json\", name: \"Petstore\" } ]"
Set the value to the literal object value you'd like, taking care to escape characters where necessary.
Example:
SPEC="{ \"openapi\": \"3.0.4\" }"
SUPPORTED_SUBMIT_METHODS=['get', 'post']
URLS=[ { url: 'https://petstore.swagger.io/v2/swagger.json', name: 'Petstore' } ]
How can I help you explore Laravel packages today?