Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ swaggerui_blueprint = get_swaggerui_blueprint(
SWAGGER_URL, # Swagger UI static files will be mapped to '{SWAGGER_URL}/dist/'
API_URL,
config={ # Swagger UI config overrides
'app_name': "Test application"
'app_name': "Test application",
'requestInterceptor' : 'function requestInterceptor(request) {return request;}'
},
# oauth_config={ # OAuth config. See https://github.com/swagger-api/swagger-ui#oauth2-configuration .
# 'clientId': "your-client-id",
Expand All @@ -52,6 +53,9 @@ app.run()
The blueprint supports overloading all Swagger UI configuration options that can be JSON serialized.
See https://github.com/swagger-api/swagger-ui#parameters for options.

Plugins and function parameters are not supported at this time.
Function parameters are supported in the form of strings that are evaluated as javascript. They must
define a function that is of the same name as the parameter.

Plugins are not supported at this time.

OAuth2 parameters can be found at https://github.com/swagger-api/swagger-ui#oauth2-configuration .
27 changes: 27 additions & 0 deletions flask_swagger_ui/templates/index.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,33 @@
var user_config = {{config_json|safe}}; // User config options provided from Python code
for (var attrname in user_config) { config[attrname] = user_config[attrname]; }

// Parse a string to a javascript function.
// If it's not possible to parse it to a function, return the string.
function parse_function(function_name, value) {
try {
eval(value);
var evaluated_value = eval(function_name);
if (typeof(evaluated_value) === 'function') {
return evaluated_value;
} else {
console.error(`error evaluating function for config attribute ${attrname}. Not a function (${typeof(evaluated_value)}).`);
}
}
catch(e) {
console.error(`error evaluating function "${user_config[attrname]}" for config attribute ${attrname}. Exception: `, e);
}

return value;
}

// For all the function attributes, parse them if they're present.
var function_attrs = ["requestInterceptor", "responseInterceptor", "operationsSorter", "tagsSorter", "onComplete"];
function_attrs.forEach(function f(function_attr) {
if (function_attr in config) {
config[function_attr] = parse_function(function_attr, config[function_attr])
}
});

window.onload = function() {
// Build a system
const ui = SwaggerUIBundle(config)
Expand Down