Add swagger_auto_schema method decorator for Operation customization

See #5.
This commit is contained in:
Cristi Vîjdea
2017-12-08 05:33:01 +01:00
parent 82cac4ef0d
commit 652795f5db
11 changed files with 443 additions and 215 deletions
+9
View File
@@ -1,3 +1,6 @@
import json
import os
import pytest
from ruamel import yaml
@@ -53,3 +56,9 @@ def bad_settings():
SWAGGER_DEFAULTS['SECURITY_DEFINITIONS'].update(bad_security)
yield swagger_settings
del SWAGGER_DEFAULTS['SECURITY_DEFINITIONS']['bad']
@pytest.fixture
def reference_schema():
with open(os.path.join(os.path.dirname(__file__), 'reference.json')) as reference:
return json.load(reference)
File diff suppressed because one or more lines are too long
+11
View File
@@ -1,6 +1,17 @@
from drf_swagger import openapi
def test_operation_docstrings(swagger_dict):
users_list = swagger_dict['paths']['/users/']
assert users_list['get']['description'] == "UserList cbv classdoc"
assert users_list['post']['description'] == "apiview post description override"
users_detail = swagger_dict['paths']['/users/{id}/']
assert users_detail['get']['description'] == "user_detail fbv docstring"
assert users_detail['put']['description'] == "user_detail fbv docstring"
def test_parameter_docstrings(swagger_dict):
users_detail = swagger_dict['paths']['/users/{id}/']
assert users_detail['get']['parameters'][0]['description'] == "test manual param"
assert users_detail['put']['parameters'][0]['in'] == openapi.IN_BODY
+2 -2
View File
@@ -18,12 +18,12 @@ def test_operation_docstrings(swagger_dict):
articles_detail = swagger_dict['paths']['/articles/{slug}/']
assert articles_detail['get']['description'] == "retrieve class docstring"
assert articles_detail['put']['description'] == "update method docstring"
assert articles_detail['patch']['description'] == "ArticleViewSet class docstring"
assert articles_detail['patch']['description'] == "partial_update description override"
assert articles_detail['delete']['description'] == "destroy method docstring"
articles_today = swagger_dict['paths']['/articles/today/']
assert articles_today['get']['description'] == "ArticleViewSet class docstring"
articles_image = swagger_dict['paths']['/articles/{slug}/image/']
assert articles_image['get']['description'] == "image method docstring"
assert articles_image['get']['description'] == "image GET description override"
assert articles_image['post']['description'] == "image method docstring"
+2
View File
@@ -0,0 +1,2 @@
def test_reference_schema(swagger_dict, reference_schema):
return swagger_dict == reference_schema