Search code examples
authenticationbuttonflaskswaggerflask-restplus

Flask RESTPlus API Swagger doesn't show Authorize button


When documented using Swagger UI, Flask RestPlus API doesn't reveal Authorize button when Api instance is configured to use authorizations.

Whether Api is configured at instantiation or later using init_app method, it makes no difference. Authorizations field is ignored.

from flask import Blueprint
from flask_restplus import Api
from MyPackage import settings

authorizations = {
    'apikey': {
        'type': 'apiKey',
        'in': 'header',
        'name': 'oauth2'
    }
}

api = Api(
    authorizations=authorizations,
    description=settings.API_DESCRIPTION,
    title=settings.API_TITLE,
    version=settings.API_VERSION,
)

blueprint = Blueprint('api', __name__, url_prefix='/api')
api.init_app(blueprint)
app.register_blueprint(blueprint)

app.config['SWAGGER_UI_DOC_EXPANSION'] = settings.RESTPLUS_SWAGGER_UI_DOC_EXPANSION
app.config['RESTPLUS_MASK_SWAGGER'] = settings.RESTPLUS_MASK_SWAGGER
...

When server starts it silently ignores the configuration parameter and authorization interface is missing. If someone could shed some light on why this fails, it would be very helpful. Thanks!


Solution

  • Apparently, there was a dependency in requirements.txt which installed stale version of flask-restplus library. Updating (0.9 -> 0.11) solved the issue (and pulled in fresh visual design of the Swagger UI, nice...).