| 1 | from flask import Flask |
| 2 | from flask import jsonify |
| 3 | from flasgger import Swagger |
| 4 | from flasgger import swag_from |
| 5 | |
| 6 | app = Flask(__name__) |
| 7 | swag = Swagger(app) |
| 8 | |
| 9 | |
| 10 | @app.route("/example") |
| 11 | @swag_from({ |
| 12 | "responses": { |
| 13 | 400: { |
| 14 | "description": "Invalid action" |
| 15 | }, |
| 16 | 401: { |
| 17 | "description": "Login required" |
| 18 | } |
| 19 | }, |
| 20 | "tags": ["Tag 1", "Tag 2"] |
| 21 | }) |
| 22 | def view(): |
| 23 | """ |
| 24 | A test view |
| 25 | |
| 26 | --- |
| 27 | responses: |
| 28 | 200: |
| 29 | description: OK |
| 30 | tags: [Tag 3, Tag 4] |
| 31 | """ |
| 32 | return jsonify(hello="world") |
| 33 | |
| 34 | |
| 35 | def test_swag(client, specs_data): |
| 36 | example_spec = specs_data["/apispec_1.json"]["paths"]["/example"]["get"] |
| 37 | assert "400" in example_spec["responses"] |
| 38 | assert "401" in example_spec["responses"] |
| 39 | assert "200" in example_spec["responses"] |
| 40 | |
| 41 | assert "Tag 1" in example_spec["tags"] |
| 42 | assert "Tag 2" in example_spec["tags"] |
| 43 | assert "Tag 3" in example_spec["tags"] |
| 44 | assert "Tag 4" in example_spec["tags"] |
| 45 | |
| 46 | |
| 47 | if __name__ == "__main__": |
| 48 | app.run(debug=True) |