From bfced82ae495071acb73b8a9c044149a0db4c9cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cristi=20V=C3=AEjdea?= Date: Sun, 10 Dec 2017 03:06:49 +0100 Subject: [PATCH] Add suport for Response schemas (#10) Schemas generated from Serializers will now be added to the `definitions` section by default, and used as `$ref` objects where needed. The Schema definition name is based on the serializer class name, and can be overriden by specifying a `__ref_name__` property on the Serializer. If this property is set to None, the schema will not be added to `definitions` and will be forced inline. Closes #6, #7. --- .codecov.yml | 4 +- .coveragerc | 4 + .idea/inspectionProfiles/Project_Default.xml | 2 +- pytest.ini | 3 - requirements/test.txt | 1 + src/drf_swagger/codecs.py | 10 +- src/drf_swagger/generators.py | 52 +- src/drf_swagger/inspectors.py | 392 ++++---- src/drf_swagger/middleware.py | 4 +- src/drf_swagger/openapi.py | 163 +++- src/drf_swagger/utils.py | 177 +++- src/drf_swagger/views.py | 2 +- testproj/articles/views.py | 17 +- testproj/snippets/serializers.py | 8 +- testproj/snippets/views.py | 1 + testproj/users/views.py | 23 +- tests/conftest.py | 8 +- tests/reference.json | 1 - tests/reference.yaml | 971 +++++++++++++++++++ tests/test_reference_schema.py | 13 +- tests/test_referenceresolver.py | 45 + tests/test_schema_generator.py | 5 +- tox.ini | 4 + 23 files changed, 1637 insertions(+), 273 deletions(-) delete mode 100644 pytest.ini delete mode 100644 tests/reference.json create mode 100644 tests/reference.yaml create mode 100644 tests/test_referenceresolver.py diff --git a/.codecov.yml b/.codecov.yml index 35c010e..368e8e4 100644 --- a/.codecov.yml +++ b/.codecov.yml @@ -24,8 +24,6 @@ coverage: changes: default: - enabled: yes - if_no_uploads: error - if_ci_failed: error + enabled: no comment: false diff --git a/.coveragerc b/.coveragerc index 9f1c676..e9f607d 100644 --- a/.coveragerc +++ b/.coveragerc @@ -14,6 +14,7 @@ exclude_lines = # Don't complain if tests don't hit defensive assertion code: raise AssertionError + raise TypeError raise NotImplementedError warnings.warn @@ -21,6 +22,9 @@ exclude_lines = if 0: if __name__ == .__main__.: + # Don't complain if we don't hit invalid schema configurations + raise SwaggerGenerationError + ignore_errors = True precision = 0 diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml index 2af15d1..a13a35f 100644 --- a/.idea/inspectionProfiles/Project_Default.xml +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -27,7 +27,7 @@ - +