-
Notifications
You must be signed in to change notification settings - Fork 515
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #173 from Teyras/master
Merge specs_dict recursively instead of just updating the top level
- Loading branch information
Showing
3 changed files
with
115 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
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" | ||
} | ||
}, | ||
"tags": ["Tag 1", "Tag 2"] | ||
}) | ||
def view(): | ||
""" | ||
A test view | ||
--- | ||
responses: | ||
200: | ||
description: OK | ||
tags: [Tag 3, Tag 4] | ||
""" | ||
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 "Tag 1" in example_spec["tags"] | ||
assert "Tag 2" in example_spec["tags"] | ||
assert "Tag 3" in example_spec["tags"] | ||
assert "Tag 4" in example_spec["tags"] | ||
|
||
|
||
if __name__ == "__main__": | ||
app.run(debug=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters