File: swag_from_overriding.py

package info (click to toggle)
python-flasgger 0.9.5%2Bdfsg.2-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 13,152 kB
  • sloc: javascript: 6,403; python: 3,665; makefile: 9; sh: 1
file content (45 lines) | stat: -rw-r--r-- 939 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from flask import Flask
from flask import jsonify
from flasgger import Swagger
from flasgger import swag_from

app = Flask(__name__)
swag = Swagger(app)


@app.route("/example")
@swag_from({
    "responses": {
        400: {
            "description": "Invalid action"
        },
        401: {
            "description": "Login required"
        }
    }
})
def view():
    """
    A test view

    ---
    responses:
      200:
        description: OK
      400:
        description: Modified description
    """
    return jsonify(hello="world")


def test_swag(client, specs_data):
    example_spec = specs_data["/apispec_1.json"]["paths"]["/example"]["get"]
    assert "400" in example_spec["responses"]
    assert "401" in example_spec["responses"]
    assert "200" in example_spec["responses"]

    assert example_spec["responses"]["400"]["description"] == "Modified description"


if __name__ == "__main__":
    app.run(debug=True)