| 1 | """ |
| 2 | In this example Swagger UI is disabled. |
| 3 | """ |
| 4 | from flask import Flask |
| 5 | try: |
| 6 | from http import HTTPStatus |
| 7 | except ImportError: |
| 8 | import httplib as HTTPStatus |
| 9 | from flasgger import Swagger |
| 10 | |
| 11 | swagger_config = { |
| 12 | 'headers': [ |
| 13 | ], |
| 14 | 'specs': [ |
| 15 | { |
| 16 | 'endpoint': 'apispec', |
| 17 | 'route': '/apispec.json', |
| 18 | 'rule_filter': lambda rule: True, |
| 19 | 'model_filter': lambda tag: True, |
| 20 | } |
| 21 | ], |
| 22 | 'swagger_ui': False |
| 23 | } |
| 24 | |
| 25 | app = Flask(__name__) |
| 26 | swag = Swagger(app, config=swagger_config) |
| 27 | |
| 28 | |
| 29 | def test_swag(client, specs_data): |
| 30 | """ |
| 31 | This test is runs automatically in Travis CI |
| 32 | |
| 33 | :param client: Flask app test client |
| 34 | :param specs_data: {'url': {swag_specs}} for every spec in app |
| 35 | """ |
| 36 | |
| 37 | assert not specs_data |
| 38 | assert client.get('/apidocs/').status_code == HTTPStatus.NOT_FOUND |
| 39 | assert client.get('/apispec.json').status_code == HTTPStatus.OK |
| 40 | |
| 41 | if __name__ == '__main__': |
| 42 | app.run(debug=True) |