| 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 | }) |
| 21 | def view(): |
| 22 | """ |
| 23 | A test view |
| 24 | |
| 25 | --- |
| 26 | responses: |
| 27 | 200: |
| 28 | description: OK |
| 29 | 400: |
| 30 | description: Modified description |
| 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 example_spec["responses"]["400"]["description"] == "Modified description" |
| 42 | |
| 43 | |
| 44 | if __name__ == "__main__": |
| 45 | app.run(debug=True) |