I tried to provide the "requestInterceptor" option to Swagger UI via SWAGGER_UI_CONFIG, but it did not work. The basic problem seems to be that apiflask assumes that all such options should be strings, but this is not the case for this option. If only some of the options are supported, this should be documented.
To reproduce, take your own example program and add the lines
app.config['SWAGGER_UI_CONFIG'] = {
'requestInterceptor': "(req) => { console.log('intercepted!'); return req; }"
}
Navigate to the docs page and it fails with the error "r.requestInterceptor is not a function /openapi.json"
But there does not seem to be any way to make it into a function in my Python code. I have done something similar in C# with Swashbuckle, where it works fine to provide it as a string in this way.
In ui_templates.py in apiflask are the lines
var userConfig = {{ config.SWAGGER_UI_CONFIG | tojson }}
for (var attr in userConfig) {
baseConfig[attr] = userConfig[attr]
}
which seems to just assume that all options are meant to be strings. If I change this to eval(userConfig[attr]) then it works (but would then not work for options that are meant to be strings rather than javascript code, so some kind of conditional logic would be needed. )
Environment:
- Python 3.10.6
- Flask version 2.1.3
- APIFlask version: 1.1.3
I tried to provide the "requestInterceptor" option to Swagger UI via SWAGGER_UI_CONFIG, but it did not work. The basic problem seems to be that apiflask assumes that all such options should be strings, but this is not the case for this option. If only some of the options are supported, this should be documented.
To reproduce, take your own example program and add the lines
Navigate to the docs page and it fails with the error "r.requestInterceptor is not a function /openapi.json"
But there does not seem to be any way to make it into a function in my Python code. I have done something similar in C# with Swashbuckle, where it works fine to provide it as a string in this way.
In ui_templates.py in apiflask are the lines
which seems to just assume that all options are meant to be strings. If I change this to
eval(userConfig[attr])then it works (but would then not work for options that are meant to be strings rather than javascript code, so some kind of conditional logic would be needed. )Environment: