Compare commits
30 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 51ec07261d | |||
| a9cdf6d561 | |||
| a64ce95e3c | |||
| c9147a5746 | |||
| ccdf646c0e | |||
| 04252ebec3 | |||
| 848fb69009 | |||
| 309a6eb8cd | |||
| a7fbba4967 | |||
| 66785b1ee8 | |||
| fb240f6a5b | |||
| 2c459024d1 | |||
| b62161f762 | |||
| 9ad55bac99 | |||
| 3d3b7899e5 | |||
| 6ea8711a1f | |||
| ee46f59fb1 | |||
| 3f7ad62950 | |||
| b38d3e6805 | |||
| 058fd7096d | |||
| a32321d43a | |||
| f15e70b7db | |||
| 64c280e222 | |||
| d5073081d9 | |||
| 10c7e22940 | |||
| 6c497b32b4 | |||
| 73c60a8fda | |||
| 97082e8898 | |||
| 743396617e | |||
| 97cd1b63d9 |
Generated
+3
-3
@@ -13,9 +13,9 @@
|
||||
</component>
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/testproj" isTestSource="false" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="Python 3.6 (drf-yasg)" jdkType="Python SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
@@ -24,7 +24,7 @@
|
||||
<option name="TEMPLATE_CONFIGURATION" value="Django" />
|
||||
<option name="TEMPLATE_FOLDERS">
|
||||
<list>
|
||||
<option value="$MODULE_DIR$/drf_yasg/templates" />
|
||||
<option value="$MODULE_DIR$/src/drf_yasg/templates" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
@@ -32,4 +32,4 @@
|
||||
<option name="projectConfiguration" value="py.test" />
|
||||
<option name="PROJECT_TEST_RUNNER" value="py.test" />
|
||||
</component>
|
||||
</module>
|
||||
</module>
|
||||
+2
-2
@@ -134,7 +134,7 @@ In ``urls.py``:
|
||||
)
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^swagger(?P<format>.json|.yaml)$', schema_view.without_ui(cache_timeout=None), name='schema-json'),
|
||||
url(r'^swagger(?P<format>\.json|\.yaml)$', schema_view.without_ui(cache_timeout=None), name='schema-json'),
|
||||
url(r'^swagger/$', schema_view.with_ui('swagger', cache_timeout=None), name='schema-swagger-ui'),
|
||||
url(r'^redoc/$', schema_view.with_ui('redoc', cache_timeout=None), name='schema-redoc'),
|
||||
...
|
||||
@@ -362,7 +362,7 @@ provided out of the box - if you have ``djangorestframework-camel-case`` install
|
||||
:alt: Codecov
|
||||
|
||||
.. |pypi-version| image:: https://img.shields.io/pypi/v/drf-yasg.svg
|
||||
:target: https://pypi.python.org/pypi/drf-yasg/
|
||||
:target: https://pypi.org/project/drf-yasg/
|
||||
:alt: PyPI
|
||||
|
||||
.. |rtd-badge| image:: https://img.shields.io/readthedocs/drf-yasg.svg
|
||||
|
||||
@@ -2,10 +2,115 @@
|
||||
Changelog
|
||||
#########
|
||||
|
||||
|
||||
*********
|
||||
**1.6.0**
|
||||
*********
|
||||
|
||||
*Release date: Mar 24, 2018*
|
||||
|
||||
- **IMPROVED:** ``OAUTH2_REDIRECT_URL`` will now default to the built in ``oauth2-redirect.html`` file
|
||||
|
||||
*********
|
||||
**1.5.1**
|
||||
*********
|
||||
|
||||
*Release date: Mar 18, 2018*
|
||||
|
||||
- **IMPROVED:** updated ``swagger-ui`` to version 3.13.0
|
||||
- **FIXED:** fixed a crash caused by ``serializers.OneToOneRel`` (:pr:`81`, thanks to :ghuser:`ko-pp`)
|
||||
|
||||
*********
|
||||
**1.5.0**
|
||||
*********
|
||||
|
||||
*Release date: Mar 12, 2018*
|
||||
|
||||
- **IMPROVED:** ``serializers.HiddenField`` are now hidden (:issue:`78`, :pr:`79`, thanks to :ghuser:`therefromhere`)
|
||||
|
||||
*NOTE:* in order for this to work, you will have to add the new ``drf_yasg.inspectors.HiddenFieldInspector`` to your
|
||||
``DEFAULT_FIELD_INSPECTORS`` array if you changed it from the default value
|
||||
|
||||
- **IMPROVED:** type of model field is now detected for ``serializers.SlugRelatedField`` with ``read_only=True``
|
||||
(:issue:`82`, :pr:`83`, thanks to :ghuser:`therefromhere`)
|
||||
|
||||
*********
|
||||
**1.4.7**
|
||||
*********
|
||||
|
||||
*Release date: Mar 05, 2018*
|
||||
|
||||
- **FIXED:** prevent crashes caused by attempting to delete object attributes which do not exist in the first place
|
||||
(:issue:`76`)
|
||||
|
||||
*********
|
||||
**1.4.6**
|
||||
*********
|
||||
|
||||
*Release date: Mar 05, 2018*
|
||||
|
||||
- **IMPROVED:** updated ``swagger-ui`` to version 3.12.0
|
||||
- **IMPROVED:** updated ``ReDoc`` to version 1.21.2
|
||||
|
||||
*********
|
||||
**1.4.5**
|
||||
*********
|
||||
|
||||
*Release date: Mar 05, 2018*
|
||||
|
||||
- **FIXED:** fixed an issue with modification of ``swagger_auto_schema`` arguments in-place during introspection, which
|
||||
would sometimes cause an incomplete Swagger document to be generated after the first pass (:issue:`74`, :pr:`75`)
|
||||
|
||||
*********
|
||||
**1.4.4**
|
||||
*********
|
||||
|
||||
*Release date: Feb 26, 2018*
|
||||
|
||||
- **IMPROVED:** ``type`` for ``ChoiceField`` generated by a ``ModelSerializer`` from a model field with ``choices=...``
|
||||
will now be set according to the associated model field (:issue:`69`)
|
||||
- **FIXED:** ``lookup_field`` and ``lookup_value_regex`` on the same ``ViewSet`` will no longer trigger an exception
|
||||
(:issue:`68`)
|
||||
|
||||
*********
|
||||
**1.4.3**
|
||||
*********
|
||||
|
||||
*Release date: Feb 22, 2018*
|
||||
|
||||
- **FIXED:** added a missing assignment that would cause the ``default`` argument to ``openapi.Parameter.__init__`` to
|
||||
be ignored
|
||||
|
||||
*********
|
||||
**1.4.2**
|
||||
*********
|
||||
|
||||
*Release date: Feb 22, 2018*
|
||||
|
||||
- **FIXED:** fixed a bug that causes a ``ModelViewSet`` generated from models with nested ``ForeignKey`` to output
|
||||
models named ``Nested`` into the ``definitions`` section (:issue:`59`, :pr:`65`)
|
||||
- **FIXED:** ``Response`` objects without a ``schema`` are now properly handled when passed through
|
||||
``swagger_auto_schema`` (:issue:`66`)
|
||||
|
||||
*********
|
||||
**1.4.1**
|
||||
*********
|
||||
|
||||
*Release date: Feb 21, 2018*
|
||||
|
||||
- **FIXED:** the ``coerce_to_string`` is now respected when setting the type, default value and min/max values of
|
||||
``DecimalField`` in the OpenAPI schema (:issue:`62`)
|
||||
- **FIXED:** error responses from web UI views are now rendered with ``TemplateHTMLRenderer`` instead of throwing
|
||||
confusing errors (:issue:`58`)
|
||||
- **IMPROVED:** updated ``swagger-ui`` to version 3.10.0
|
||||
- **IMPROVED:** updated ``ReDoc`` to version 1.21.0
|
||||
|
||||
*********
|
||||
**1.4.0**
|
||||
*********
|
||||
|
||||
*Release date: Feb 04, 2018*
|
||||
|
||||
- **ADDED:** added settings for OAuth2 client configuration in ``swagger-ui`` (:issue:`53`)
|
||||
- **IMPROVED:** updated ``swagger-ui`` to version 3.9.3
|
||||
|
||||
@@ -13,6 +118,8 @@ Changelog
|
||||
**1.3.1**
|
||||
*********
|
||||
|
||||
*Release date: Jan 24, 2018*
|
||||
|
||||
- **FIXED:** fixed a bug that would sometimes cause endpoints to wrongly be output as form operations (:issue:`50`)
|
||||
- **IMPROVED:** added generation of ``produces`` based on renderer classes
|
||||
- **IMPROVED:** added generation of top-level ``consumes`` and ``produces`` based on
|
||||
@@ -22,6 +129,8 @@ Changelog
|
||||
**1.3.0**
|
||||
*********
|
||||
|
||||
*Release date: Jan 23, 2018*
|
||||
|
||||
- **ADDED:** security requirements are now correctly set and can be customized; this should fix problems related
|
||||
to authentication in ``swagger-ui`` Try it out! (:issue:`50`, :pr:`54`)
|
||||
- **IMPROVED:** updated ``swagger-ui`` to version 3.9.2
|
||||
@@ -32,6 +141,8 @@ Changelog
|
||||
**1.2.2**
|
||||
*********
|
||||
|
||||
*Release date: Jan 12, 2018*
|
||||
|
||||
- **FIXED:** djangorestframework>=3.7.7 is now required because of breaking changes
|
||||
(:issue:`44`, :pr:`45`, thanks to :ghuser:`h-hirokawa`)
|
||||
|
||||
@@ -39,12 +150,16 @@ Changelog
|
||||
**1.2.1**
|
||||
*********
|
||||
|
||||
*Release date: Jan 12, 2018*
|
||||
|
||||
- Fixed deployment issues
|
||||
|
||||
*********
|
||||
**1.2.0**
|
||||
*********
|
||||
|
||||
*Release date: Jan 12, 2018 (missing from PyPI due to deployment issues)*
|
||||
|
||||
- **ADDED:** ``basePath`` is now generated by taking into account the ``SCRIPT_NAME`` variable and the
|
||||
longest common prefix of API urls (:issue:`37`, :pr:`42`)
|
||||
- **IMPROVED:** removed inline scripts and styles from bundled HTML templates to increase CSP compatibility
|
||||
@@ -56,6 +171,8 @@ Changelog
|
||||
**1.1.3**
|
||||
*********
|
||||
|
||||
*Release date: Jan 02, 2018*
|
||||
|
||||
- **FIXED:** schema view cache will now always ``Vary`` on the ``Cookie`` and ``Authentication`` (the
|
||||
``Vary`` header was previously only added if ``public`` was set to ``True``) - this fixes issues related to Django
|
||||
authentication in ``swagger-ui`` and ``CurrentUserDefault`` values in the schema
|
||||
@@ -64,6 +181,8 @@ Changelog
|
||||
**1.1.2**
|
||||
*********
|
||||
|
||||
*Release date: Jan 01, 2018*
|
||||
|
||||
- **IMPROVED:** updated ``swagger-ui`` to version 3.8.1
|
||||
- **IMPROVED:** removed some unneeded static files
|
||||
|
||||
@@ -71,6 +190,8 @@ Changelog
|
||||
**1.1.1**
|
||||
*********
|
||||
|
||||
*Release date: Dec 27, 2017*
|
||||
|
||||
- **ADDED:** :ref:`generate_swagger management command <management-command>`
|
||||
(:issue:`29`, :pr:`31`, thanks to :ghuser:`beaugunderson`)
|
||||
- **FIXED:** fixed improper generation of ``\Z`` regex tokens - will now be repalced by ``$``
|
||||
@@ -79,6 +200,8 @@ Changelog
|
||||
**1.1.0**
|
||||
*********
|
||||
|
||||
*Release date: Dec 27, 2017*
|
||||
|
||||
- **ADDED:** added support for APIs versioned with ``URLPathVersioning`` or ``NamespaceVersioning``
|
||||
- **ADDED:** added ability to recursively customize schema generation
|
||||
:ref:`using pluggable inspector classes <custom-spec-inspectors>`
|
||||
@@ -94,6 +217,8 @@ Changelog
|
||||
**1.0.6**
|
||||
*********
|
||||
|
||||
*Release date: Dec 23, 2017*
|
||||
|
||||
- **FIXED:** Swagger UI "Try it out!" should now work with Django login
|
||||
- **FIXED:** callable ``default`` values on serializer fields will now be properly called (:pr:`24`, :issue:`25`)
|
||||
- **IMPROVED:** updated ``swagger-ui`` to version 3.8.0
|
||||
@@ -105,6 +230,8 @@ Changelog
|
||||
**1.0.5**
|
||||
*********
|
||||
|
||||
*Release date: Dec 18, 2017*
|
||||
|
||||
- **FIXED:** fixed a crash caused by having read-only Serializers nested by reference
|
||||
- **FIXED:** removed erroneous backslashes in paths when routes are generated using Django 2
|
||||
`path() <https://docs.djangoproject.com/en/2.0/ref/urls/#django.urls.path>`_
|
||||
@@ -116,6 +243,8 @@ Changelog
|
||||
**1.0.4**
|
||||
*********
|
||||
|
||||
*Release date: Dec 16, 2017*
|
||||
|
||||
- **FIXED:** fixed improper generation of YAML references
|
||||
- **ADDED:** added ``query_serializer`` parameter to
|
||||
:func:`@swagger_auto_schema <.swagger_auto_schema>` (:issue:`16`, :pr:`17`)
|
||||
@@ -124,6 +253,8 @@ Changelog
|
||||
**1.0.3**
|
||||
*********
|
||||
|
||||
*Release date: Dec 15, 2017*
|
||||
|
||||
- **FIXED:** fixed bug that caused schema views returned from cache to fail (:issue:`14`)
|
||||
- **FIXED:** disabled automatic generation of response schemas for form operations to avoid confusing errors caused by
|
||||
attempting to shove file parameters into Schema objects
|
||||
@@ -132,4 +263,6 @@ Changelog
|
||||
**1.0.2**
|
||||
*********
|
||||
|
||||
*Release date: Dec 13, 2017*
|
||||
|
||||
- First published version
|
||||
|
||||
+24
-24
@@ -162,6 +162,18 @@ autodoc_mock_imports = []
|
||||
|
||||
nitpick_ignore = [
|
||||
('py:class', 'object'),
|
||||
('py:class', 'bool'),
|
||||
('py:class', 'dict'),
|
||||
('py:class', 'list'),
|
||||
('py:class', 'str'),
|
||||
('py:class', 'int'),
|
||||
('py:class', 'bytes'),
|
||||
('py:class', 'tuple'),
|
||||
('py:class', 'callable'),
|
||||
('py:class', 'type'),
|
||||
('py:class', 'OrderedDict'),
|
||||
('py:class', 'None'),
|
||||
|
||||
('py:class', 'Exception'),
|
||||
('py:class', 'collections.OrderedDict'),
|
||||
|
||||
@@ -174,29 +186,17 @@ nitpick_ignore = [
|
||||
('py:class', 'OpenAPICodecJson'),
|
||||
('py:class', 'OpenAPISchemaGenerator'),
|
||||
|
||||
('py:obj', 'bool'),
|
||||
('py:obj', 'dict'),
|
||||
('py:obj', 'list'),
|
||||
('py:obj', 'str'),
|
||||
('py:obj', 'int'),
|
||||
('py:obj', 'bytes'),
|
||||
('py:obj', 'tuple'),
|
||||
('py:obj', 'callable'),
|
||||
('py:obj', 'type'),
|
||||
('py:obj', 'OrderedDict'),
|
||||
('py:obj', 'None'),
|
||||
|
||||
('py:obj', 'coreapi.Field'),
|
||||
('py:obj', 'BaseFilterBackend'),
|
||||
('py:obj', 'BasePagination'),
|
||||
('py:obj', 'Request'),
|
||||
('py:obj', 'rest_framework.request.Request'),
|
||||
('py:obj', 'rest_framework.serializers.Field'),
|
||||
('py:obj', 'serializers.Field'),
|
||||
('py:obj', 'serializers.BaseSerializer'),
|
||||
('py:obj', 'Serializer'),
|
||||
('py:obj', 'BaseSerializer'),
|
||||
('py:obj', 'APIView'),
|
||||
('py:class', 'coreapi.Field'),
|
||||
('py:class', 'BaseFilterBackend'),
|
||||
('py:class', 'BasePagination'),
|
||||
('py:class', 'Request'),
|
||||
('py:class', 'rest_framework.request.Request'),
|
||||
('py:class', 'rest_framework.serializers.Field'),
|
||||
('py:class', 'serializers.Field'),
|
||||
('py:class', 'serializers.BaseSerializer'),
|
||||
('py:class', 'Serializer'),
|
||||
('py:class', 'BaseSerializer'),
|
||||
('py:class', 'APIView'),
|
||||
]
|
||||
|
||||
# even though the package should be already installed, the sphinx build on RTD
|
||||
@@ -273,7 +273,7 @@ def role_github_user(name, rawtext, text, lineno, inliner, options=None, content
|
||||
options = options or {}
|
||||
content = content or []
|
||||
|
||||
if not re.match(r"^[a-z\d](?:[a-z\d]|-(?=[a-z\d])){0,38}$", text):
|
||||
if not re.match(r"^[a-z\d](?:[a-z\d]|-(?=[a-z\d])){0,38}$", text, re.IGNORECASE):
|
||||
return sphinx_err(inliner, lineno, rawtext, '"%s" is not a valid GitHub username.' % text)
|
||||
|
||||
ref = gh_user_uri.format(text)
|
||||
|
||||
+27
-1
@@ -172,7 +172,11 @@ You can define some per-serializer options by adding a ``Meta`` class to your se
|
||||
Currently, the only option you can add here is
|
||||
|
||||
* ``ref_name`` - a string which will be used as the model definition name for this serializer class; setting it to
|
||||
``None`` will force the serializer to be generated as an inline model everywhere it is used
|
||||
``None`` will force the serializer to be generated as an inline model everywhere it is used. If two serializers
|
||||
have the same ``ref_name``, both their usages will be replaced with a reference to the same definition.
|
||||
If this option is not specified, all serializers have an implicit name derived from their class name, minus any
|
||||
``Serializer`` suffix (e.g. ``UserSerializer`` -> ``User``, ``SerializerWithSuffix`` -> ``SerializerWithSuffix``)
|
||||
|
||||
|
||||
*************************
|
||||
Subclassing and extending
|
||||
@@ -301,3 +305,25 @@ A second example, of a :class:`~.inspectors.FieldInspector` that removes the ``t
|
||||
This means that you should generally avoid view or method-specific ``FieldInspector``\ s if you are dealing with
|
||||
references (a.k.a named models), because you can never know which view will be the first to generate the schema
|
||||
for a given serializer.
|
||||
|
||||
**IMPORTANT:** nested fields on ``ModelSerializer``\ s that are generated from model ``ForeignKeys`` will always be
|
||||
output by value. If you want the by-reference behaviour you have to explictly set the serializer class of nested
|
||||
fields instead of letting ``ModelSerializer`` generate one automatically; for example:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
class OneSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = SomeModel
|
||||
fields = ('id',)
|
||||
|
||||
|
||||
class AnotherSerializer(serializers.ModelSerializer):
|
||||
chilf = OneSerializer()
|
||||
|
||||
class Meta:
|
||||
model = SomeParentModel
|
||||
fields = ('id', 'child')
|
||||
|
||||
Another caveat that stems from this is that any serializer named "``NestedSerializer``" will be forced inline
|
||||
unless it has a ``ref_name`` set explicitly.
|
||||
|
||||
@@ -63,3 +63,37 @@ settings described below were added as a result of discussion in issue :issue:`5
|
||||
The settings of interest can be found on the :ref:`settings page <oauth2-settings>`. Configuration options are similar
|
||||
to most OAuth client setups like web or mobile applications. Reading the relevant ``swagger-ui`` docmentation linked
|
||||
will also probably help.
|
||||
|
||||
|
||||
Example
|
||||
^^^^^^^
|
||||
|
||||
A very simple working configuration was provided by :ghuser:`Vigrond`, originally at
|
||||
`https://github.com/Vigrond/django_oauth2_example <https://github.com/Vigrond/django_oauth2_example>`_.
|
||||
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
SWAGGER_SETTINGS = {
|
||||
'USE_SESSION_AUTH': False,
|
||||
'SECURITY_DEFINITIONS': {
|
||||
'Your App API - Swagger': {
|
||||
'type': 'oauth2',
|
||||
'authorizationUrl': '/yourapp/o/authorize',
|
||||
'tokenUrl': '/yourapp/o/token/',
|
||||
'flow": "accessCode',
|
||||
'scopes': {
|
||||
'read:groups': 'read groups',
|
||||
}
|
||||
}
|
||||
},
|
||||
'OAUTH2_CONFIG': {
|
||||
'clientId': 'yourAppClientId',
|
||||
'clientSecret': 'yourAppClientSecret',
|
||||
'appName': 'your application name'
|
||||
},
|
||||
}
|
||||
|
||||
If the OAuth2 provider requires you to provide the full absolute redirect URL, the default value for most
|
||||
``staticfiles`` configurations will be ``<origin>/static/drf-yasg/swagger-ui-dist/oauth2-redirect.html``. If this is
|
||||
not suitable for some reason, you can override the ``OAUTH2_REDIRECT_URL`` setting as appropriate.
|
||||
|
||||
+5
-1
@@ -66,6 +66,7 @@ to this list.
|
||||
:class:`'drf_yasg.inspectors.ChoiceFieldInspector' <.inspectors.ChoiceFieldInspector>`, |br| \
|
||||
:class:`'drf_yasg.inspectors.FileFieldInspector' <.inspectors.FileFieldInspector>`, |br| \
|
||||
:class:`'drf_yasg.inspectors.DictFieldInspector' <.inspectors.DictFieldInspector>`, |br| \
|
||||
:class:`'drf_yasg.inspectors.HiddenFieldInspector' <.inspectors.HiddenFieldInspector>`, |br| \
|
||||
:class:`'drf_yasg.inspectors.SimpleFieldInspector' <.inspectors.SimpleFieldInspector>`, |br| \
|
||||
:class:`'drf_yasg.inspectors.StringDefaultFieldInspector' <.inspectors.StringDefaultFieldInspector>`, |br| \
|
||||
``]``
|
||||
@@ -258,7 +259,10 @@ Controls how many levels are expaned by default when showing nested models.
|
||||
OAUTH2_REDIRECT_URL
|
||||
-------------------
|
||||
|
||||
Used when OAuth2 authenitcation of API requests via swagger-ui is desired.
|
||||
Used when OAuth2 authenitcation of API requests via swagger-ui is desired. If ``None`` is passed, the
|
||||
``oauth2RedirectUrl`` parameter will be set to ``{% static 'drf-yasg/swagger-ui-dist/oauth2-redirect.html' %}``. This
|
||||
is the default `https://github.com/swagger-api/swagger-ui/blob/master/dist/oauth2-redirect.html <oauth2-redirect>`_
|
||||
file provided by ``swagger-ui``.
|
||||
|
||||
**Default**: :python:`None` |br|
|
||||
*Maps to parameter*: ``oauth2RedirectUrl``
|
||||
|
||||
Generated
+45
-42
@@ -4,9 +4,9 @@
|
||||
"lockfileVersion": 1,
|
||||
"dependencies": {
|
||||
"argparse": {
|
||||
"version": "1.0.9",
|
||||
"resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.9.tgz",
|
||||
"integrity": "sha1-c9g7wmP4bpf4zE9rrhsOkKfSLIY=",
|
||||
"version": "1.0.10",
|
||||
"resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz",
|
||||
"integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==",
|
||||
"requires": {
|
||||
"sprintf-js": "1.0.3"
|
||||
}
|
||||
@@ -38,9 +38,9 @@
|
||||
}
|
||||
},
|
||||
"commander": {
|
||||
"version": "2.13.0",
|
||||
"resolved": "https://registry.npmjs.org/commander/-/commander-2.13.0.tgz",
|
||||
"integrity": "sha512-MVuS359B+YzaWqjCL/c+22gfryv+mCBPHAv3zyVI2GN8EY6IRP8VwtasXn8jyyhvvq84R4ImN1OKRtcbIasjYA==",
|
||||
"version": "2.14.1",
|
||||
"resolved": "https://registry.npmjs.org/commander/-/commander-2.14.1.tgz",
|
||||
"integrity": "sha512-+YR16o3rK53SmWHU3rEM3tPAh2rwb1yPcQX5irVn7mb0gXbwuCCrnkbV5+PBfETdfg1vui07nM6PCG1zndcjQw==",
|
||||
"optional": true
|
||||
},
|
||||
"core-js": {
|
||||
@@ -73,9 +73,9 @@
|
||||
"integrity": "sha1-8TyUAhQdoJ50rfTmN5jXkiBEOPI="
|
||||
},
|
||||
"es6-promise": {
|
||||
"version": "4.2.2",
|
||||
"resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.2.2.tgz",
|
||||
"integrity": "sha512-LSas5vsuA6Q4nEdf9wokY5/AJYXry98i0IzXsv49rYsgDGDNDPbqAYR1Pe23iFxygfbGZNR/5VrHXBCh2BhvUQ=="
|
||||
"version": "4.2.4",
|
||||
"resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.2.4.tgz",
|
||||
"integrity": "sha512-/NdNZVJg+uZgtm9eS3O6lrOLYmQag2DjdEXuPaHlZ6RuVqgqaVZfgYCepEIKsLqwdQArOPtC3XzRLqGGfT8KQQ=="
|
||||
},
|
||||
"esprima": {
|
||||
"version": "4.0.0",
|
||||
@@ -126,7 +126,7 @@
|
||||
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.10.0.tgz",
|
||||
"integrity": "sha512-O2v52ffjLa9VeM43J4XocZE//WT9N0IiwDa3KSHH7Tu8CtH+1qM8SIZvnsTh6v+4yFy5KUY3BHUVwjpfAWsjIA==",
|
||||
"requires": {
|
||||
"argparse": "1.0.9",
|
||||
"argparse": "1.0.10",
|
||||
"esprima": "4.0.0"
|
||||
}
|
||||
},
|
||||
@@ -145,10 +145,10 @@
|
||||
"requires": {
|
||||
"call-me-maybe": "1.0.1",
|
||||
"debug": "3.1.0",
|
||||
"es6-promise": "4.2.2",
|
||||
"es6-promise": "4.2.4",
|
||||
"js-yaml": "3.10.0",
|
||||
"ono": "4.0.3",
|
||||
"z-schema": "3.19.0"
|
||||
"z-schema": "3.19.1"
|
||||
}
|
||||
},
|
||||
"lodash.get": {
|
||||
@@ -185,9 +185,12 @@
|
||||
}
|
||||
},
|
||||
"openapi-sampler": {
|
||||
"version": "0.4.3",
|
||||
"resolved": "https://registry.npmjs.org/openapi-sampler/-/openapi-sampler-0.4.3.tgz",
|
||||
"integrity": "sha512-Ml6o1gt++ZQ4JKL344YRo/fX05yuM6C+l/mGVX2yjhu1BRKyrRK4Z46uBTKSVaag1xINBFwYG7dZdz/10AmPzA=="
|
||||
"version": "1.0.0-beta.8",
|
||||
"resolved": "https://registry.npmjs.org/openapi-sampler/-/openapi-sampler-1.0.0-beta.8.tgz",
|
||||
"integrity": "sha1-v0P/R3N/xOH5iNDiCC1JeI9B3q0=",
|
||||
"requires": {
|
||||
"json-pointer": "0.6.0"
|
||||
}
|
||||
},
|
||||
"perfect-scrollbar": {
|
||||
"version": "0.8.1",
|
||||
@@ -195,36 +198,36 @@
|
||||
"integrity": "sha512-RNC5tX/JMRYR+qVdJTEAWnRxw0Yf9lvbO8lTuAOvgDODkiA8lveTSkvrNMhmaGKEyimJpJl+myb/syVS9YyPuw=="
|
||||
},
|
||||
"prismjs": {
|
||||
"version": "1.10.0",
|
||||
"resolved": "https://registry.npmjs.org/prismjs/-/prismjs-1.10.0.tgz",
|
||||
"integrity": "sha1-d+UYfCrmsyU/zDEwKc8l/lN3hyE=",
|
||||
"version": "1.11.0",
|
||||
"resolved": "https://registry.npmjs.org/prismjs/-/prismjs-1.11.0.tgz",
|
||||
"integrity": "sha1-KXrvM+t5Qhv9sZJzpQkspRWXDSk=",
|
||||
"requires": {
|
||||
"clipboard": "1.7.1"
|
||||
}
|
||||
},
|
||||
"process-nextick-args": {
|
||||
"version": "1.0.7",
|
||||
"resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-1.0.7.tgz",
|
||||
"integrity": "sha1-FQ4gt1ZZCtP5EJPyWk8q2L/zC6M="
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.0.tgz",
|
||||
"integrity": "sha512-MtEC1TqN0EU5nephaJ4rAtThHtC86dNN9qCuEhtshvpVBkAW5ZO7BASN9REnF9eoXGcRub+pFuKEpOHE+HbEMw=="
|
||||
},
|
||||
"readable-stream": {
|
||||
"version": "2.3.3",
|
||||
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.3.tgz",
|
||||
"integrity": "sha512-m+qzzcn7KUxEmd1gMbchF+Y2eIUbieUaxkWtptyHywrX0rE8QEYqPC07Vuy4Wm32/xE16NcdBctb8S0Xe/5IeQ==",
|
||||
"version": "2.3.5",
|
||||
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.5.tgz",
|
||||
"integrity": "sha512-tK0yDhrkygt/knjowCUiWP9YdV7c5R+8cR0r/kt9ZhBU906Fs6RpQJCEilamRJj1Nx2rWI6LkW9gKqjTkshhEw==",
|
||||
"requires": {
|
||||
"core-util-is": "1.0.2",
|
||||
"inherits": "2.0.3",
|
||||
"isarray": "1.0.0",
|
||||
"process-nextick-args": "1.0.7",
|
||||
"process-nextick-args": "2.0.0",
|
||||
"safe-buffer": "5.1.1",
|
||||
"string_decoder": "1.0.3",
|
||||
"util-deprecate": "1.0.2"
|
||||
}
|
||||
},
|
||||
"redoc": {
|
||||
"version": "1.20.0",
|
||||
"resolved": "https://registry.npmjs.org/redoc/-/redoc-1.20.0.tgz",
|
||||
"integrity": "sha1-1c16xoQKJ8/7RzvSiYAFUq+CHq8=",
|
||||
"version": "1.21.2",
|
||||
"resolved": "https://registry.npmjs.org/redoc/-/redoc-1.21.2.tgz",
|
||||
"integrity": "sha1-uMeLfDxtwFjmeZniwvYbqFjewaY=",
|
||||
"requires": {
|
||||
"core-js": "2.5.3",
|
||||
"dropkickjs": "2.1.10",
|
||||
@@ -234,9 +237,9 @@
|
||||
"json-schema-ref-parser": "3.3.1",
|
||||
"lunr": "1.0.0",
|
||||
"mark.js": "8.11.1",
|
||||
"openapi-sampler": "0.4.3",
|
||||
"openapi-sampler": "1.0.0-beta.8",
|
||||
"perfect-scrollbar": "0.8.1",
|
||||
"prismjs": "1.10.0",
|
||||
"prismjs": "1.11.0",
|
||||
"remarkable": "1.7.1",
|
||||
"scrollparent": "2.0.1",
|
||||
"slugify": "1.2.9",
|
||||
@@ -298,7 +301,7 @@
|
||||
"requires": {
|
||||
"builtin-status-codes": "3.0.0",
|
||||
"inherits": "2.0.3",
|
||||
"readable-stream": "2.3.3",
|
||||
"readable-stream": "2.3.5",
|
||||
"to-arraybuffer": "1.0.1",
|
||||
"xtend": "4.0.1"
|
||||
}
|
||||
@@ -312,9 +315,9 @@
|
||||
}
|
||||
},
|
||||
"swagger-ui-dist": {
|
||||
"version": "3.9.3",
|
||||
"resolved": "https://registry.npmjs.org/swagger-ui-dist/-/swagger-ui-dist-3.9.3.tgz",
|
||||
"integrity": "sha1-yrqR6FUNfSRkoIRWvZNtfEMPDdM="
|
||||
"version": "3.13.0",
|
||||
"resolved": "https://registry.npmjs.org/swagger-ui-dist/-/swagger-ui-dist-3.13.0.tgz",
|
||||
"integrity": "sha1-NPpclKDx3EAWVBmIEV38rhOKirE="
|
||||
},
|
||||
"tiny-emitter": {
|
||||
"version": "2.0.2",
|
||||
@@ -348,9 +351,9 @@
|
||||
"integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8="
|
||||
},
|
||||
"validator": {
|
||||
"version": "9.2.0",
|
||||
"resolved": "https://registry.npmjs.org/validator/-/validator-9.2.0.tgz",
|
||||
"integrity": "sha512-6Ij4Eo0KM4LkR0d0IegOwluG5453uqT5QyF5SV5Ezvm8/zmkKI/L4eoraafZGlZPC9guLkwKzgypcw8VGWWnGA=="
|
||||
"version": "9.4.1",
|
||||
"resolved": "https://registry.npmjs.org/validator/-/validator-9.4.1.tgz",
|
||||
"integrity": "sha512-YV5KjzvRmSyJ1ee/Dm5UED0G+1L4GZnLN3w6/T+zZm8scVua4sOhYKWTUrKa0H/tMiJyO9QLHMPN+9mB/aMunA=="
|
||||
},
|
||||
"xtend": {
|
||||
"version": "4.0.1",
|
||||
@@ -358,14 +361,14 @@
|
||||
"integrity": "sha1-pcbVMr5lbiPbgg77lDofBJmNY68="
|
||||
},
|
||||
"z-schema": {
|
||||
"version": "3.19.0",
|
||||
"resolved": "https://registry.npmjs.org/z-schema/-/z-schema-3.19.0.tgz",
|
||||
"integrity": "sha512-V94f3ODuluBS4kQLLjNhwoMek0dyIXCsvNu/A17dAyJ6sMhT5KkJQwSn07R0naByLIXJWMDk+ruMfI/3G3hS4Q==",
|
||||
"version": "3.19.1",
|
||||
"resolved": "https://registry.npmjs.org/z-schema/-/z-schema-3.19.1.tgz",
|
||||
"integrity": "sha512-jPNzqmOu3+AGbb4krDODqo4QBzwUGDVzyfGyy1HtWaUnafltQotatSpxxWd6Mp0iSZOUwHU5sqKYi+U8HsHMkg==",
|
||||
"requires": {
|
||||
"commander": "2.13.0",
|
||||
"commander": "2.14.1",
|
||||
"lodash.get": "4.4.2",
|
||||
"lodash.isequal": "4.5.0",
|
||||
"validator": "9.2.0"
|
||||
"validator": "9.4.1"
|
||||
}
|
||||
},
|
||||
"zone.js": {
|
||||
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
{
|
||||
"name": "drf-yasg",
|
||||
"dependencies": {
|
||||
"redoc": "^1.20.0",
|
||||
"swagger-ui-dist": "^3.9.3"
|
||||
"redoc": "^1.21.2",
|
||||
"swagger-ui-dist": "^3.13.0"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
@@ -4,7 +4,7 @@ openapi_codec>=1.3.2
|
||||
ruamel.yaml>=0.15.34
|
||||
inflection>=0.3.1
|
||||
future>=0.16.0
|
||||
six>=1.11.0
|
||||
six>=1.10.0
|
||||
uritemplate>=3.0.0
|
||||
|
||||
djangorestframework>=3.7.7
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# used by the 'docs' tox env for building the documentation
|
||||
Sphinx>=1.6.5
|
||||
Sphinx>=1.7.0
|
||||
sphinx_rtd_theme>=0.2.4
|
||||
Pillow>=4.3.0
|
||||
readme_renderer>=17.2
|
||||
|
||||
@@ -11,6 +11,7 @@ SWAGGER_DEFAULTS = {
|
||||
'drf_yasg.inspectors.ChoiceFieldInspector',
|
||||
'drf_yasg.inspectors.FileFieldInspector',
|
||||
'drf_yasg.inspectors.DictFieldInspector',
|
||||
'drf_yasg.inspectors.HiddenFieldInspector',
|
||||
'drf_yasg.inspectors.SimpleFieldInspector',
|
||||
'drf_yasg.inspectors.StringDefaultFieldInspector',
|
||||
],
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import copy
|
||||
import logging
|
||||
import re
|
||||
from collections import OrderedDict, defaultdict
|
||||
@@ -355,9 +356,9 @@ class OpenAPISchemaGenerator(object):
|
||||
|
||||
view_inspector = view_inspector_cls(view, path, method, components, request, overrides)
|
||||
operation = view_inspector.get_operation(operation_keys)
|
||||
if set(operation.consumes) == set(self.consumes):
|
||||
if 'consumes' in operation and set(operation.consumes) == set(self.consumes):
|
||||
del operation.consumes
|
||||
if set(operation.produces) == set(self.produces):
|
||||
if 'produces' in operation and set(operation.produces) == set(self.produces):
|
||||
del operation.produces
|
||||
return operation
|
||||
|
||||
@@ -388,7 +389,7 @@ class OpenAPISchemaGenerator(object):
|
||||
if method in overrides:
|
||||
overrides = overrides[method]
|
||||
|
||||
return overrides
|
||||
return copy.deepcopy(overrides)
|
||||
|
||||
def get_path_parameters(self, path, view_cls):
|
||||
"""Return a list of Parameter instances corresponding to any templated path variables.
|
||||
@@ -405,12 +406,12 @@ class OpenAPISchemaGenerator(object):
|
||||
for variable in uritemplate.variables(path):
|
||||
model, model_field = get_queryset_field(queryset, variable)
|
||||
attrs = get_basic_type_info(model_field) or {'type': openapi.TYPE_STRING}
|
||||
if hasattr(view_cls, 'lookup_value_regex') and getattr(view_cls, 'lookup_field', None) == variable:
|
||||
attrs['pattern'] = view_cls.lookup_value_regex
|
||||
if getattr(view_cls, 'lookup_field', None) == variable and attrs['type'] == openapi.TYPE_STRING:
|
||||
attrs['pattern'] = getattr(view_cls, 'lookup_value_regex', attrs.get('pattern', None))
|
||||
|
||||
if model_field and model_field.help_text:
|
||||
if model_field and getattr(model_field, 'help_text', False):
|
||||
description = force_text(model_field.help_text)
|
||||
elif model_field and model_field.primary_key:
|
||||
elif model_field and getattr(model_field, 'primary_key', False):
|
||||
description = get_pk_description(model, model_field)
|
||||
else:
|
||||
description = None
|
||||
|
||||
@@ -3,8 +3,9 @@ from .base import (
|
||||
BaseInspector, FieldInspector, FilterInspector, NotHandled, PaginatorInspector, SerializerInspector, ViewInspector
|
||||
)
|
||||
from .field import (
|
||||
CamelCaseJSONFilter, ChoiceFieldInspector, DictFieldInspector, FileFieldInspector, InlineSerializerInspector,
|
||||
ReferencingSerializerInspector, RelatedFieldInspector, SimpleFieldInspector, StringDefaultFieldInspector
|
||||
CamelCaseJSONFilter, ChoiceFieldInspector, DictFieldInspector, FileFieldInspector, HiddenFieldInspector,
|
||||
InlineSerializerInspector, ReferencingSerializerInspector, RelatedFieldInspector, SimpleFieldInspector,
|
||||
StringDefaultFieldInspector
|
||||
)
|
||||
from .query import CoreAPICompatInspector, DjangoRestResponsePagination
|
||||
from .view import SwaggerAutoSchema
|
||||
@@ -24,7 +25,7 @@ __all__ = [
|
||||
# field inspectors
|
||||
'InlineSerializerInspector', 'ReferencingSerializerInspector', 'RelatedFieldInspector', 'SimpleFieldInspector',
|
||||
'FileFieldInspector', 'ChoiceFieldInspector', 'DictFieldInspector', 'StringDefaultFieldInspector',
|
||||
'CamelCaseJSONFilter',
|
||||
'CamelCaseJSONFilter', 'HiddenFieldInspector',
|
||||
|
||||
# view inspectors
|
||||
'SwaggerAutoSchema',
|
||||
|
||||
@@ -6,7 +6,7 @@ from rest_framework import serializers
|
||||
from rest_framework.utils import encoders, json
|
||||
|
||||
from .. import openapi
|
||||
from ..utils import is_list_view
|
||||
from ..utils import decimal_as_float, is_list_view
|
||||
|
||||
#: Sentinel value that inspectors must return to signal that they do not know how to handle an object
|
||||
NotHandled = object()
|
||||
@@ -224,6 +224,8 @@ class FieldInspector(BaseInspector):
|
||||
# JSON roundtrip ensures that the value is valid JSON;
|
||||
# for example, sets and tuples get transformed into lists
|
||||
default = json.loads(json.dumps(default, cls=encoders.JSONEncoder))
|
||||
if decimal_as_float(field):
|
||||
default = float(default)
|
||||
except Exception: # pragma: no cover
|
||||
logger.warning("'default' on schema for %s will not be set because "
|
||||
"to_representation raised an exception", field, exc_info=True)
|
||||
@@ -232,7 +234,8 @@ class FieldInspector(BaseInspector):
|
||||
if default is not None:
|
||||
instance_kwargs['default'] = default
|
||||
|
||||
instance_kwargs.setdefault('title', title)
|
||||
if instance_kwargs.get('type', None) != openapi.TYPE_ARRAY:
|
||||
instance_kwargs.setdefault('title', title)
|
||||
instance_kwargs.setdefault('description', description)
|
||||
instance_kwargs.update(kwargs)
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import logging
|
||||
import operator
|
||||
from collections import OrderedDict
|
||||
from decimal import Decimal
|
||||
|
||||
from django.core import validators
|
||||
from django.db import models
|
||||
@@ -8,9 +10,11 @@ from rest_framework.settings import api_settings as rest_framework_settings
|
||||
|
||||
from .. import openapi
|
||||
from ..errors import SwaggerGenerationError
|
||||
from ..utils import filter_none
|
||||
from ..utils import decimal_as_float, filter_none
|
||||
from .base import FieldInspector, NotHandled, SerializerInspector
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class InlineSerializerInspector(SerializerInspector):
|
||||
"""Provides serializer conversions using :meth:`.FieldInspector.field_to_swagger_object`."""
|
||||
@@ -53,10 +57,14 @@ class InlineSerializerInspector(SerializerInspector):
|
||||
|
||||
serializer = field
|
||||
serializer_meta = getattr(serializer, 'Meta', None)
|
||||
serializer_name = type(serializer).__name__
|
||||
if hasattr(serializer_meta, 'ref_name'):
|
||||
ref_name = serializer_meta.ref_name
|
||||
elif serializer_name == 'NestedSerializer' and isinstance(serializer, serializers.ModelSerializer):
|
||||
logger.debug("Forcing inline output for ModelSerializer named 'NestedSerializer': " + str(serializer))
|
||||
ref_name = None
|
||||
else:
|
||||
ref_name = type(serializer).__name__
|
||||
ref_name = serializer_name
|
||||
if ref_name.endswith('Serializer'):
|
||||
ref_name = ref_name[:-len('Serializer')]
|
||||
|
||||
@@ -76,11 +84,17 @@ class InlineSerializerInspector(SerializerInspector):
|
||||
if child.required:
|
||||
required.append(property_name)
|
||||
|
||||
return SwaggerType(
|
||||
result = SwaggerType(
|
||||
type=openapi.TYPE_OBJECT,
|
||||
properties=properties,
|
||||
required=required or None,
|
||||
)
|
||||
if not ref_name and 'title' in result:
|
||||
# on an inline model, the title is derived from the field name
|
||||
# but is visually displayed like the model name, which is confusing
|
||||
# it is better to just remove title from inline models
|
||||
del result.title
|
||||
return result
|
||||
|
||||
if not ref_name or not use_references:
|
||||
return make_schema_definition()
|
||||
@@ -147,7 +161,11 @@ def get_related_model(model, source):
|
||||
:return: related model or ``None``
|
||||
"""
|
||||
try:
|
||||
return getattr(model, source).rel.related_model
|
||||
descriptor = getattr(model, source)
|
||||
try:
|
||||
return descriptor.rel.related_model
|
||||
except Exception:
|
||||
return descriptor.field.remote_field.model
|
||||
except Exception: # pragma: no cover
|
||||
return None
|
||||
|
||||
@@ -258,18 +276,29 @@ def find_limits(field):
|
||||
if isinstance(field, field_class)
|
||||
]
|
||||
|
||||
if isinstance(field, serializers.DecimalField) and not decimal_as_float(field):
|
||||
return limits
|
||||
|
||||
for validator in field.validators:
|
||||
if not hasattr(validator, 'limit_value'):
|
||||
continue
|
||||
|
||||
limit_value = validator.limit_value
|
||||
if isinstance(limit_value, Decimal) and decimal_as_float(field):
|
||||
limit_value = float(limit_value)
|
||||
|
||||
for validator_class, attr, improves in applicable_limits:
|
||||
if isinstance(validator, validator_class):
|
||||
if attr not in limits or improves(validator.limit_value, limits[attr]):
|
||||
limits[attr] = validator.limit_value
|
||||
if attr not in limits or improves(limit_value, limits[attr]):
|
||||
limits[attr] = limit_value
|
||||
|
||||
return OrderedDict(sorted(limits.items()))
|
||||
|
||||
|
||||
def decimal_field_type(field):
|
||||
return openapi.TYPE_NUMBER if decimal_as_float(field) else openapi.TYPE_STRING
|
||||
|
||||
|
||||
model_field_to_basic_type = [
|
||||
(models.AutoField, (openapi.TYPE_INTEGER, None)),
|
||||
(models.BinaryField, (openapi.TYPE_STRING, openapi.FORMAT_BINARY)),
|
||||
@@ -277,7 +306,7 @@ model_field_to_basic_type = [
|
||||
(models.NullBooleanField, (openapi.TYPE_BOOLEAN, None)),
|
||||
(models.DateTimeField, (openapi.TYPE_STRING, openapi.FORMAT_DATETIME)),
|
||||
(models.DateField, (openapi.TYPE_STRING, openapi.FORMAT_DATE)),
|
||||
(models.DecimalField, (openapi.TYPE_NUMBER, None)),
|
||||
(models.DecimalField, (decimal_field_type, openapi.FORMAT_DECIMAL)),
|
||||
(models.DurationField, (openapi.TYPE_INTEGER, None)),
|
||||
(models.FloatField, (openapi.TYPE_NUMBER, None)),
|
||||
(models.IntegerField, (openapi.TYPE_INTEGER, None)),
|
||||
@@ -300,9 +329,11 @@ serializer_field_to_basic_type = [
|
||||
(serializers.UUIDField, (openapi.TYPE_STRING, openapi.FORMAT_UUID)),
|
||||
(serializers.RegexField, (openapi.TYPE_STRING, None)),
|
||||
(serializers.CharField, (openapi.TYPE_STRING, None)),
|
||||
((serializers.BooleanField, serializers.NullBooleanField), (openapi.TYPE_BOOLEAN, None)),
|
||||
(serializers.BooleanField, (openapi.TYPE_BOOLEAN, None)),
|
||||
(serializers.NullBooleanField, (openapi.TYPE_BOOLEAN, None)),
|
||||
(serializers.IntegerField, (openapi.TYPE_INTEGER, None)),
|
||||
((serializers.FloatField, serializers.DecimalField), (openapi.TYPE_NUMBER, None)),
|
||||
(serializers.FloatField, (openapi.TYPE_NUMBER, None)),
|
||||
(serializers.DecimalField, (decimal_field_type, openapi.FORMAT_DECIMAL)),
|
||||
(serializers.DurationField, (openapi.TYPE_NUMBER, None)), # ?
|
||||
(serializers.DateField, (openapi.TYPE_STRING, openapi.FORMAT_DATE)),
|
||||
(serializers.DateTimeField, (openapi.TYPE_STRING, openapi.FORMAT_DATETIME)),
|
||||
@@ -326,13 +357,18 @@ def get_basic_type_info(field):
|
||||
for field_class, type_format in basic_type_info:
|
||||
if isinstance(field, field_class):
|
||||
swagger_type, format = type_format
|
||||
if callable(swagger_type):
|
||||
swagger_type = swagger_type(field)
|
||||
if callable(format):
|
||||
format = format(field)
|
||||
break
|
||||
else: # pragma: no cover
|
||||
return None
|
||||
|
||||
pattern = find_regex(field) if format in (None, openapi.FORMAT_SLUG) else None
|
||||
pattern = None
|
||||
if swagger_type == openapi.TYPE_STRING and format in (None, openapi.FORMAT_SLUG):
|
||||
pattern = find_regex(field)
|
||||
|
||||
limits = find_limits(field)
|
||||
|
||||
result = OrderedDict([
|
||||
@@ -365,16 +401,27 @@ class ChoiceFieldInspector(FieldInspector):
|
||||
def field_to_swagger_object(self, field, swagger_object_type, use_references, **kwargs):
|
||||
SwaggerType, ChildSwaggerType = self._get_partial_types(field, swagger_object_type, use_references, **kwargs)
|
||||
|
||||
if isinstance(field, serializers.MultipleChoiceField):
|
||||
return SwaggerType(
|
||||
type=openapi.TYPE_ARRAY,
|
||||
items=ChildSwaggerType(
|
||||
type=openapi.TYPE_STRING,
|
||||
enum=list(field.choices.keys())
|
||||
if isinstance(field, serializers.ChoiceField):
|
||||
enum_type = openapi.TYPE_STRING
|
||||
|
||||
# for ModelSerializer, try to infer the type from the associated model field
|
||||
serializer = get_parent_serializer(field)
|
||||
if isinstance(serializer, serializers.ModelSerializer):
|
||||
model = getattr(getattr(serializer, 'Meta'), 'model')
|
||||
model_field = get_model_field(model, field.source)
|
||||
if model_field:
|
||||
enum_type = get_basic_type_info(model_field).get('type', enum_type)
|
||||
|
||||
if isinstance(field, serializers.MultipleChoiceField):
|
||||
return SwaggerType(
|
||||
type=openapi.TYPE_ARRAY,
|
||||
items=ChildSwaggerType(
|
||||
type=enum_type,
|
||||
enum=list(field.choices.keys())
|
||||
)
|
||||
)
|
||||
)
|
||||
elif isinstance(field, serializers.ChoiceField):
|
||||
return SwaggerType(type=openapi.TYPE_STRING, enum=list(field.choices.keys()))
|
||||
|
||||
return SwaggerType(type=enum_type, enum=list(field.choices.keys()))
|
||||
|
||||
return NotHandled
|
||||
|
||||
@@ -422,11 +469,21 @@ class DictFieldInspector(FieldInspector):
|
||||
return NotHandled
|
||||
|
||||
|
||||
class HiddenFieldInspector(FieldInspector):
|
||||
"""Hide ``HiddenField``."""
|
||||
|
||||
def field_to_swagger_object(self, field, swagger_object_type, use_references, **kwargs):
|
||||
if isinstance(field, serializers.HiddenField):
|
||||
return None
|
||||
|
||||
return NotHandled
|
||||
|
||||
|
||||
class StringDefaultFieldInspector(FieldInspector):
|
||||
"""For otherwise unhandled fields, return them as plain :data:`.TYPE_STRING` objects."""
|
||||
|
||||
def field_to_swagger_object(self, field, swagger_object_type, use_references, **kwargs): # pragma: no cover
|
||||
# TODO unhandled fields: TimeField HiddenField JSONField
|
||||
# TODO unhandled fields: TimeField JSONField
|
||||
SwaggerType, ChildSwaggerType = self._get_partial_types(field, swagger_object_type, use_references, **kwargs)
|
||||
return SwaggerType(type=openapi.TYPE_STRING)
|
||||
|
||||
|
||||
@@ -221,7 +221,7 @@ class SwaggerAutoSchema(ViewInspector):
|
||||
)
|
||||
elif isinstance(serializer, openapi.Response):
|
||||
response = serializer
|
||||
if not isinstance(response.schema, openapi.Schema.OR_REF):
|
||||
if hasattr(response, 'schema') and not isinstance(response.schema, openapi.Schema.OR_REF):
|
||||
serializer = force_serializer_instance(response.schema)
|
||||
response.schema = self.serializer_to_schema(serializer)
|
||||
elif isinstance(serializer, openapi.Schema.OR_REF):
|
||||
|
||||
@@ -35,6 +35,7 @@ FORMAT_URI = "uri" #:
|
||||
# pulled out of my ass
|
||||
FORMAT_UUID = "uuid" #:
|
||||
FORMAT_SLUG = "slug" #:
|
||||
FORMAT_DECIMAL = "decimal"
|
||||
|
||||
IN_BODY = 'body' #:
|
||||
IN_PATH = 'path' #:
|
||||
@@ -395,6 +396,7 @@ class Parameter(SwaggerDict):
|
||||
self.enum = enum
|
||||
self.pattern = pattern
|
||||
self.items = items
|
||||
self.default = default
|
||||
self._insert_extras__()
|
||||
if self['in'] == IN_PATH:
|
||||
# path parameters must always be required
|
||||
@@ -423,7 +425,7 @@ class Schema(SwaggerDict):
|
||||
:param str format: value format, see OpenAPI spec
|
||||
:param list enum: restrict possible values
|
||||
:param str pattern: pattern if type is ``string``
|
||||
:param list[.Schema,.SchemaRef] properties: object properties; required if `type` is ``object``
|
||||
:param dict[str,(.Schema,.SchemaRef)] properties: object properties; required if `type` is ``object``
|
||||
:param bool,.Schema,.SchemaRef additional_properties: allow wildcard properties not listed in `properties`
|
||||
:param list[str] required: list of requried property names
|
||||
:param .Schema,.SchemaRef items: type of array items, only valid if `type` is ``array``
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
from django.shortcuts import render, resolve_url
|
||||
from rest_framework.renderers import BaseRenderer
|
||||
from rest_framework.renderers import BaseRenderer, TemplateHTMLRenderer
|
||||
from rest_framework.utils import json
|
||||
|
||||
from drf_yasg.openapi import Swagger
|
||||
|
||||
from .app_settings import redoc_settings, swagger_settings
|
||||
from .codecs import VALIDATORS, OpenAPICodecJson, OpenAPICodecYaml
|
||||
|
||||
@@ -51,6 +53,11 @@ class _UIRenderer(BaseRenderer):
|
||||
template = ''
|
||||
|
||||
def render(self, swagger, accepted_media_type=None, renderer_context=None):
|
||||
if not isinstance(swagger, Swagger):
|
||||
# if `swagger` is not a ``Swagger`` object, it means we somehow got a non-success ``Response``
|
||||
# in that case, it's probably better to let the default ``TemplateHTMLRenderer`` render it
|
||||
# see https://github.com/axnsan12/drf-yasg/issues/58
|
||||
return TemplateHTMLRenderer().render(swagger, accepted_media_type, renderer_context)
|
||||
self.set_context(renderer_context, swagger)
|
||||
return render(
|
||||
renderer_context['request'],
|
||||
@@ -124,11 +131,3 @@ class ReDocRenderer(_UIRenderer):
|
||||
"""
|
||||
template = 'drf-yasg/redoc.html'
|
||||
format = 'redoc'
|
||||
|
||||
|
||||
class ReDocAlphaRenderer(_UIRenderer):
|
||||
"""Renders a ReDoc web interface for schema browisng.
|
||||
Also requires :class:`.OpenAPIRenderer` as an available renderer on the same view.
|
||||
"""
|
||||
template = 'drf-yasg/redoc-alpha.html'
|
||||
format = 'redoc'
|
||||
|
||||
File diff suppressed because one or more lines are too long
+2
-2
File diff suppressed because one or more lines are too long
@@ -45,11 +45,18 @@
|
||||
oauth2.auth.code = qp.code;
|
||||
oauth2.callback({auth: oauth2.auth, redirectUrl: redirectUrl});
|
||||
} else {
|
||||
let oauthErrorMsg
|
||||
if (qp.error) {
|
||||
oauthErrorMsg = "["+qp.error+"]: " +
|
||||
(qp.error_description ? qp.error_description+ ". " : "no accessCode received from the server. ") +
|
||||
(qp.error_uri ? "More info: "+qp.error_uri : "");
|
||||
}
|
||||
|
||||
oauth2.errCb({
|
||||
authId: oauth2.auth.name,
|
||||
source: "auth",
|
||||
level: "error",
|
||||
message: "Authorization failed: no accessCode received from the server"
|
||||
message: oauthErrorMsg || "[Authorization failed]: no accessCode received from the server"
|
||||
});
|
||||
}
|
||||
} else {
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -38,7 +38,7 @@ function initSwaggerUi() {
|
||||
],
|
||||
layout: "StandaloneLayout",
|
||||
filter: true,
|
||||
requestInterceptor: function(request) {
|
||||
requestInterceptor: function (request) {
|
||||
var headers = request.headers || {};
|
||||
var csrftoken = document.querySelector("[name=csrfmiddlewaretoken]");
|
||||
if (csrftoken) {
|
||||
@@ -49,8 +49,15 @@ function initSwaggerUi() {
|
||||
};
|
||||
|
||||
var swaggerSettings = JSON.parse(document.getElementById('swagger-settings').innerHTML);
|
||||
console.log(swaggerSettings);
|
||||
if (!('oauth2RedirectUrl' in swaggerSettings)) {
|
||||
var oauth2RedirectUrl = document.getElementById('oauth2-redirect-url');
|
||||
if (oauth2RedirectUrl) {
|
||||
swaggerSettings['oauth2RedirectUrl'] = oauth2RedirectUrl.href;
|
||||
oauth2RedirectUrl.parentNode.removeChild(oauth2RedirectUrl);
|
||||
}
|
||||
}
|
||||
|
||||
console.log(swaggerSettings);
|
||||
for (var p in swaggerSettings) {
|
||||
if (swaggerSettings.hasOwnProperty(p)) {
|
||||
swaggerConfig[p] = swaggerSettings[p];
|
||||
|
||||
@@ -67,6 +67,8 @@
|
||||
<script src="{% static 'drf-yasg/insQ.min.js' %}"></script>
|
||||
<script src="{% static 'drf-yasg/swagger-ui-init.js' %}"></script>
|
||||
|
||||
<a id="oauth2-redirect-url" href="{% static 'drf-yasg/swagger-ui-dist/oauth2-redirect.html' %}" class="hidden"></a>
|
||||
|
||||
<div id="django-session-auth" class="hidden">
|
||||
{% if USE_SESSION_AUTH %}
|
||||
{% csrf_token %}
|
||||
|
||||
+25
-4
@@ -2,17 +2,24 @@ import inspect
|
||||
import logging
|
||||
from collections import OrderedDict
|
||||
|
||||
from django.db import models
|
||||
from rest_framework import serializers, status
|
||||
from rest_framework.mixins import DestroyModelMixin, RetrieveModelMixin, UpdateModelMixin
|
||||
from rest_framework.request import is_form_media_type
|
||||
from rest_framework.settings import api_settings as rest_framework_settings
|
||||
from rest_framework.views import APIView
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
#: used to forcibly remove the body of a request via :func:`.swagger_auto_schema`
|
||||
no_body = object()
|
||||
|
||||
unset = object()
|
||||
class no_body(object):
|
||||
"""Used as a sentinel value to forcibly remove the body of a request via :func:`.swagger_auto_schema`."""
|
||||
pass
|
||||
|
||||
|
||||
class unset(object):
|
||||
"""Used as a sentinel value for function parameters not set by the caller where ``None`` would be a valid value."""
|
||||
pass
|
||||
|
||||
|
||||
def swagger_auto_schema(method=None, methods=None, auto_schema=unset, request_body=None, query_serializer=None,
|
||||
@@ -31,7 +38,7 @@ def swagger_auto_schema(method=None, methods=None, auto_schema=unset, request_bo
|
||||
:param .inspectors.SwaggerAutoSchema auto_schema: custom class to use for generating the Operation object;
|
||||
this overrides both the class-level ``swagger_schema`` attribute and the ``DEFAULT_AUTO_SCHEMA_CLASS``
|
||||
setting, and can be set to ``None`` to prevent this operation from being generated
|
||||
:param .Schema,.SchemaRef,.Serializer request_body: custom request body, or :data:`.no_body`. The value given here
|
||||
:param .Schema,.SchemaRef,.Serializer request_body: custom request body, or :class:`.no_body`. The value given here
|
||||
will be used as the ``schema`` property of a :class:`.Parameter` with ``in: 'body'``.
|
||||
|
||||
A Schema or SchemaRef is not valid if this request consumes form-data, because ``form`` and ``body`` parameters
|
||||
@@ -118,6 +125,8 @@ def swagger_auto_schema(method=None, methods=None, auto_schema=unset, request_bo
|
||||
|
||||
_methods = methods
|
||||
if methods or method:
|
||||
assert available_methods or http_method_names, "`method` or `methods` can only be specified " \
|
||||
"on @detail_route or @api_view views"
|
||||
assert bool(methods) != bool(method), "specify either method or methods"
|
||||
assert not isinstance(methods, str), "`methods` expects to receive a list of methods;" \
|
||||
" use `method` for a single argument"
|
||||
@@ -273,3 +282,15 @@ def get_produces(renderer_classes):
|
||||
media_types = [renderer.media_type for renderer in renderer_classes or []]
|
||||
media_types = [encoding for encoding in media_types if 'html' not in encoding]
|
||||
return media_types
|
||||
|
||||
|
||||
def decimal_as_float(field):
|
||||
"""
|
||||
Returns true if ``field`` is a django-rest-framework DecimalField and its ``coerce_to_string`` attribute or the
|
||||
``COERCE_DECIMAL_TO_STRING`` setting is set to ``False``.
|
||||
|
||||
:rtype: bool
|
||||
"""
|
||||
if isinstance(field, serializers.DecimalField) or isinstance(field, models.DecimalField):
|
||||
return not getattr(field, 'coerce_to_string', rest_framework_settings.COERCE_DECIMAL_TO_STRING)
|
||||
return False
|
||||
|
||||
@@ -12,15 +12,12 @@ from rest_framework.views import APIView
|
||||
|
||||
from .app_settings import swagger_settings
|
||||
from .generators import OpenAPISchemaGenerator
|
||||
from .renderers import (
|
||||
OpenAPIRenderer, ReDocAlphaRenderer, ReDocRenderer, SwaggerJSONRenderer, SwaggerUIRenderer, SwaggerYAMLRenderer
|
||||
)
|
||||
from .renderers import OpenAPIRenderer, ReDocRenderer, SwaggerJSONRenderer, SwaggerUIRenderer, SwaggerYAMLRenderer
|
||||
|
||||
SPEC_RENDERERS = (SwaggerYAMLRenderer, SwaggerJSONRenderer, OpenAPIRenderer)
|
||||
UI_RENDERERS = {
|
||||
'swagger': (SwaggerUIRenderer, ReDocRenderer),
|
||||
'redoc': (ReDocRenderer, SwaggerUIRenderer),
|
||||
'redoc-alpha': (ReDocAlphaRenderer, ReDocRenderer, SwaggerUIRenderer)
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
# Generated by Django 2.0 on 2017-12-23 09:07
|
||||
# Generated by Django 2.0.1 on 2018-03-18 18:32
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
import uuid
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
@@ -23,8 +24,28 @@ class Migration(migrations.Migration):
|
||||
('slug', models.SlugField(blank=True, help_text='slug model help_text', unique=True)),
|
||||
('date_created', models.DateTimeField(auto_now_add=True)),
|
||||
('date_modified', models.DateTimeField(auto_now=True)),
|
||||
('article_type', models.PositiveSmallIntegerField(choices=[(1, 'first'), (2, 'second'), (3, 'third'), (7, 'seven'), (8, 'eight')], help_text='IntegerField declared on model with choices=(...) and exposed via ModelSerializer', null=True)),
|
||||
('cover', models.ImageField(blank=True, upload_to='article/original/')),
|
||||
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='articles', to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='ArticleGroup',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('uuid', models.UUIDField(default=uuid.uuid4, editable=False, unique=True)),
|
||||
('title', models.CharField(help_text='title model help_text', max_length=255, unique=True)),
|
||||
('slug', models.SlugField(blank=True, help_text='slug model help_text', unique=True)),
|
||||
],
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='article',
|
||||
name='group',
|
||||
field=models.ForeignKey(blank=True, default=None, on_delete=django.db.models.deletion.PROTECT, related_name='articles_as_main', to='articles.ArticleGroup'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='article',
|
||||
name='original_group',
|
||||
field=models.ForeignKey(blank=True, default=None, on_delete=django.db.models.deletion.PROTECT, related_name='articles_as_original', to='articles.ArticleGroup'),
|
||||
),
|
||||
]
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import uuid
|
||||
|
||||
from django.db import models
|
||||
|
||||
|
||||
@@ -8,5 +10,20 @@ class Article(models.Model):
|
||||
date_created = models.DateTimeField(auto_now_add=True)
|
||||
date_modified = models.DateTimeField(auto_now=True)
|
||||
author = models.ForeignKey('auth.User', related_name='articles', on_delete=models.CASCADE)
|
||||
article_type = models.PositiveSmallIntegerField(
|
||||
help_text="IntegerField declared on model with choices=(...) and exposed via ModelSerializer",
|
||||
choices=((1, "first"), (2, "second"), (3, "third"), (7, "seven"), (8, "eight")), null=True
|
||||
)
|
||||
|
||||
cover = models.ImageField(upload_to='article/original/', blank=True)
|
||||
group = models.ForeignKey('ArticleGroup', related_name='articles_as_main', blank=True, default=None,
|
||||
on_delete=models.PROTECT)
|
||||
original_group = models.ForeignKey('ArticleGroup', related_name='articles_as_original', blank=True, default=None,
|
||||
on_delete=models.PROTECT)
|
||||
|
||||
|
||||
class ArticleGroup(models.Model):
|
||||
uuid = models.UUIDField(default=uuid.uuid4, editable=False, unique=True)
|
||||
|
||||
title = models.CharField(help_text="title model help_text", max_length=255, blank=False, unique=True)
|
||||
slug = models.SlugField(help_text="slug model help_text", unique=True, blank=True)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from rest_framework import serializers
|
||||
|
||||
from articles.models import Article
|
||||
from articles.models import Article, ArticleGroup
|
||||
|
||||
|
||||
class ArticleSerializer(serializers.ModelSerializer):
|
||||
@@ -12,11 +12,13 @@ class ArticleSerializer(serializers.ModelSerializer):
|
||||
)
|
||||
uuid = serializers.UUIDField(help_text="should articles have UUIDs?", read_only=True)
|
||||
cover_name = serializers.FileField(use_url=False, source='cover', read_only=True)
|
||||
group = serializers.SlugRelatedField(slug_field='uuid', queryset=ArticleGroup.objects.all())
|
||||
original_group = serializers.SlugRelatedField(slug_field='uuid', read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = Article
|
||||
fields = ('title', 'author', 'body', 'slug', 'date_created', 'date_modified',
|
||||
'references', 'uuid', 'cover', 'cover_name')
|
||||
'references', 'uuid', 'cover', 'cover_name', 'article_type', 'group', 'original_group', )
|
||||
read_only_fields = ('date_created', 'date_modified',
|
||||
'references', 'uuid', 'cover_name')
|
||||
lookup_field = 'slug'
|
||||
@@ -31,7 +33,7 @@ class ArticleSerializer(serializers.ModelSerializer):
|
||||
|
||||
|
||||
class ImageUploadSerializer(serializers.Serializer):
|
||||
what_am_i_doing = serializers.RegexField(regex=r"^69$", help_text="test")
|
||||
what_am_i_doing = serializers.RegexField(regex=r"^69$", help_text="test", default="69")
|
||||
image_styles = serializers.ListSerializer(
|
||||
child=serializers.ChoiceField(choices=['wide', 'tall', 'thumb', 'social']),
|
||||
help_text="Parameter with Items"
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class PeopleConfig(AppConfig):
|
||||
name = 'people'
|
||||
@@ -0,0 +1,30 @@
|
||||
# Generated by Django 2.0.1 on 2018-03-18 18:32
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Identity',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('firstName', models.CharField(max_length=30, null=True)),
|
||||
('lastName', models.CharField(max_length=30, null=True)),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Person',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('identity', models.OneToOneField(on_delete=django.db.models.deletion.PROTECT, related_name='person', to='people.Identity')),
|
||||
],
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,10 @@
|
||||
from django.db import models
|
||||
|
||||
|
||||
class Identity(models.Model):
|
||||
firstName = models.CharField(max_length=30, null=True)
|
||||
lastName = models.CharField(max_length=30, null=True)
|
||||
|
||||
|
||||
class Person(models.Model):
|
||||
identity = models.OneToOneField(Identity, related_name='person', on_delete=models.PROTECT)
|
||||
@@ -0,0 +1,23 @@
|
||||
from rest_framework import serializers
|
||||
|
||||
from .models import Identity, Person
|
||||
|
||||
|
||||
class IdentitySerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Identity
|
||||
fields = '__all__'
|
||||
|
||||
|
||||
class PersonSerializer(serializers.ModelSerializer):
|
||||
identity = IdentitySerializer()
|
||||
|
||||
class Meta:
|
||||
model = Person
|
||||
fields = '__all__'
|
||||
|
||||
def create(self, validated_data):
|
||||
identity = Identity(**validated_data['identity'])
|
||||
identity.save()
|
||||
validated_data['identity'] = identity
|
||||
return super().create(validated_data)
|
||||
@@ -0,0 +1,26 @@
|
||||
from django.conf.urls import url
|
||||
|
||||
from .views import IdentityViewSet, PersonViewSet
|
||||
|
||||
person_list = PersonViewSet.as_view({
|
||||
'get': 'list',
|
||||
'post': 'create'
|
||||
})
|
||||
person_detail = PersonViewSet.as_view({
|
||||
'get': 'retrieve',
|
||||
'patch': 'partial_update',
|
||||
'delete': 'destroy'
|
||||
})
|
||||
|
||||
identity_detail = IdentityViewSet.as_view({
|
||||
'get': 'retrieve',
|
||||
'patch': 'partial_update',
|
||||
})
|
||||
|
||||
urlpatterns = (
|
||||
url(r'^$', person_list, name='people-list'),
|
||||
url(r'^(?P<pk>[0-9]+)$', person_detail, name='person-detail'),
|
||||
|
||||
url(r'^(?P<person>[0-9]+)/identity$', identity_detail,
|
||||
name='person-identity'),
|
||||
)
|
||||
@@ -0,0 +1,16 @@
|
||||
from rest_framework import viewsets
|
||||
|
||||
from .models import Identity, Person
|
||||
from .serializers import IdentitySerializer, PersonSerializer
|
||||
|
||||
|
||||
class PersonViewSet(viewsets.ModelViewSet):
|
||||
model = Person
|
||||
queryset = Person.objects
|
||||
serializer_class = PersonSerializer
|
||||
|
||||
|
||||
class IdentityViewSet(viewsets.ModelViewSet):
|
||||
model = Identity
|
||||
queryset = Identity.objects
|
||||
serializer_class = IdentitySerializer
|
||||
@@ -1,4 +1,4 @@
|
||||
# Generated by Django 2.0 on 2017-12-23 09:07
|
||||
# Generated by Django 2.0.1 on 2018-03-18 18:32
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
from decimal import Decimal
|
||||
|
||||
from django.contrib.auth import get_user_model
|
||||
from rest_framework import serializers
|
||||
from rest_framework.compat import MinValueValidator
|
||||
|
||||
from snippets.models import LANGUAGE_CHOICES, STYLE_CHOICES, Snippet
|
||||
|
||||
|
||||
class LanguageSerializer(serializers.Serializer):
|
||||
|
||||
name = serializers.ChoiceField(
|
||||
choices=LANGUAGE_CHOICES, default='python', help_text='The name of the programming language')
|
||||
|
||||
@@ -14,7 +16,6 @@ class LanguageSerializer(serializers.Serializer):
|
||||
|
||||
|
||||
class ExampleProjectSerializer(serializers.Serializer):
|
||||
|
||||
project_name = serializers.CharField(help_text='Name of the project')
|
||||
github_repo = serializers.CharField(required=True, help_text='Github repository of the project')
|
||||
|
||||
@@ -49,6 +50,10 @@ class SnippetSerializer(serializers.Serializer):
|
||||
example_projects = serializers.ListSerializer(child=ExampleProjectSerializer(), read_only=True)
|
||||
difficulty_factor = serializers.FloatField(help_text="this is here just to test FloatField",
|
||||
read_only=True, default=lambda: 6.9)
|
||||
rate_as_string = serializers.DecimalField(max_digits=6, decimal_places=3, default=Decimal('0.0'),
|
||||
validators=[MinValueValidator(Decimal('0.0'))])
|
||||
rate = serializers.DecimalField(max_digits=6, decimal_places=3, default=Decimal('0.0'), coerce_to_string=False,
|
||||
validators=[MinValueValidator(Decimal('0.0'))])
|
||||
|
||||
def create(self, validated_data):
|
||||
"""
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from djangorestframework_camel_case.parser import CamelCaseJSONParser
|
||||
from djangorestframework_camel_case.render import CamelCaseJSONRenderer
|
||||
from inflection import camelize
|
||||
from rest_framework import generics
|
||||
from rest_framework import generics, status
|
||||
from rest_framework.parsers import FormParser
|
||||
|
||||
from drf_yasg import openapi
|
||||
@@ -62,8 +62,12 @@ class SnippetDetail(generics.RetrieveUpdateDestroyAPIView):
|
||||
type=openapi.TYPE_INTEGER,
|
||||
description="path parameter override",
|
||||
required=True
|
||||
),
|
||||
], responses={
|
||||
status.HTTP_204_NO_CONTENT: openapi.Response(
|
||||
description="This should not crash"
|
||||
)
|
||||
])
|
||||
})
|
||||
def delete(self, request, *args, **kwargs):
|
||||
"""delete method docstring"""
|
||||
return super(SnippetDetail, self).patch(request, *args, **kwargs)
|
||||
|
||||
@@ -26,6 +26,8 @@ INSTALLED_APPS = [
|
||||
'snippets',
|
||||
'users',
|
||||
'articles',
|
||||
'todo',
|
||||
'people'
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
|
||||
@@ -51,7 +51,7 @@ urlpatterns = [
|
||||
url(r'^swagger(?P<format>.json|.yaml)$', SchemaView.without_ui(cache_timeout=0), name='schema-json'),
|
||||
url(r'^swagger/$', SchemaView.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
|
||||
url(r'^redoc/$', SchemaView.with_ui('redoc', cache_timeout=0), name='schema-redoc'),
|
||||
url(r'^redoc-alpha/$', SchemaView.with_ui('redoc-alpha', cache_timeout=0), name='schema-redoc-alpha'),
|
||||
|
||||
url(r'^cached/swagger(?P<format>.json|.yaml)$', SchemaView.without_ui(cache_timeout=None), name='cschema-json'),
|
||||
url(r'^cached/swagger/$', SchemaView.with_ui('swagger', cache_timeout=None), name='cschema-swagger-ui'),
|
||||
url(r'^cached/redoc/$', SchemaView.with_ui('redoc', cache_timeout=None), name='cschema-redoc'),
|
||||
@@ -62,5 +62,7 @@ urlpatterns = [
|
||||
url(r'^snippets/', include('snippets.urls')),
|
||||
url(r'^articles/', include('articles.urls')),
|
||||
url(r'^users/', include('users.urls')),
|
||||
url(r'^todo/', include('todo.urls')),
|
||||
url(r'^people/', include('people.urls')),
|
||||
url(r'^plain/', plain_view),
|
||||
]
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
# Generated by Django 2.0.1 on 2018-03-18 18:32
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Todo',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('title', models.CharField(max_length=50)),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='TodoAnother',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('title', models.CharField(max_length=50)),
|
||||
('todo', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='todo.Todo')),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='TodoYetAnother',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('title', models.CharField(max_length=50)),
|
||||
('todo', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='todo.TodoAnother')),
|
||||
],
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,15 @@
|
||||
from django.db import models
|
||||
|
||||
|
||||
class Todo(models.Model):
|
||||
title = models.CharField(max_length=50)
|
||||
|
||||
|
||||
class TodoAnother(models.Model):
|
||||
todo = models.ForeignKey(Todo, on_delete=models.CASCADE)
|
||||
title = models.CharField(max_length=50)
|
||||
|
||||
|
||||
class TodoYetAnother(models.Model):
|
||||
todo = models.ForeignKey(TodoAnother, on_delete=models.CASCADE)
|
||||
title = models.CharField(max_length=50)
|
||||
@@ -0,0 +1,27 @@
|
||||
from django.utils import timezone
|
||||
from rest_framework import serializers
|
||||
|
||||
from .models import Todo, TodoAnother, TodoYetAnother
|
||||
|
||||
|
||||
class TodoSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Todo
|
||||
fields = ('title', 'a_hidden_field',)
|
||||
|
||||
a_hidden_field = serializers.HiddenField(default=timezone.now)
|
||||
|
||||
|
||||
class TodoAnotherSerializer(serializers.ModelSerializer):
|
||||
todo = TodoSerializer()
|
||||
|
||||
class Meta:
|
||||
model = TodoAnother
|
||||
fields = ('title', 'todo')
|
||||
|
||||
|
||||
class TodoYetAnotherSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = TodoYetAnother
|
||||
fields = ('title', 'todo')
|
||||
depth = 2
|
||||
@@ -0,0 +1,10 @@
|
||||
from rest_framework import routers
|
||||
|
||||
from todo import views
|
||||
|
||||
router = routers.DefaultRouter()
|
||||
router.register(r'', views.TodoViewSet)
|
||||
router.register(r'another', views.TodoAnotherViewSet)
|
||||
router.register(r'yetanother', views.TodoYetAnotherViewSet)
|
||||
|
||||
urlpatterns = router.urls
|
||||
@@ -0,0 +1,22 @@
|
||||
from rest_framework import viewsets
|
||||
|
||||
from .models import Todo, TodoAnother, TodoYetAnother
|
||||
from .serializer import TodoAnotherSerializer, TodoSerializer, TodoYetAnotherSerializer
|
||||
|
||||
|
||||
class TodoViewSet(viewsets.ReadOnlyModelViewSet):
|
||||
queryset = Todo.objects.all()
|
||||
serializer_class = TodoSerializer
|
||||
|
||||
lookup_field = 'id'
|
||||
lookup_value_regex = '[0-9]+'
|
||||
|
||||
|
||||
class TodoAnotherViewSet(viewsets.ReadOnlyModelViewSet):
|
||||
queryset = TodoAnother.objects.all()
|
||||
serializer_class = TodoAnotherSerializer
|
||||
|
||||
|
||||
class TodoYetAnotherViewSet(viewsets.ReadOnlyModelViewSet):
|
||||
queryset = TodoYetAnother.objects.all()
|
||||
serializer_class = TodoYetAnotherSerializer
|
||||
+323
-9
@@ -198,9 +198,10 @@ paths:
|
||||
- name: what_am_i_doing
|
||||
in: formData
|
||||
description: test
|
||||
required: true
|
||||
required: false
|
||||
type: string
|
||||
pattern: ^69$
|
||||
default: '69'
|
||||
- name: image_styles
|
||||
in: formData
|
||||
description: Parameter with Items
|
||||
@@ -233,6 +234,113 @@ paths:
|
||||
type: string
|
||||
format: slug
|
||||
pattern: '[a-z0-9]+(?:-[a-z0-9]+)'
|
||||
/people/:
|
||||
get:
|
||||
operationId: people_list
|
||||
description: ''
|
||||
parameters: []
|
||||
responses:
|
||||
'200':
|
||||
description: ''
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/definitions/Person'
|
||||
tags:
|
||||
- people
|
||||
post:
|
||||
operationId: people_create
|
||||
description: ''
|
||||
parameters:
|
||||
- name: data
|
||||
in: body
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/Person'
|
||||
responses:
|
||||
'201':
|
||||
description: ''
|
||||
schema:
|
||||
$ref: '#/definitions/Person'
|
||||
tags:
|
||||
- people
|
||||
parameters: []
|
||||
/people/{id}:
|
||||
get:
|
||||
operationId: people_read
|
||||
description: ''
|
||||
parameters: []
|
||||
responses:
|
||||
'200':
|
||||
description: ''
|
||||
schema:
|
||||
$ref: '#/definitions/Person'
|
||||
tags:
|
||||
- people
|
||||
patch:
|
||||
operationId: people_partial_update
|
||||
description: ''
|
||||
parameters:
|
||||
- name: data
|
||||
in: body
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/Person'
|
||||
responses:
|
||||
'200':
|
||||
description: ''
|
||||
schema:
|
||||
$ref: '#/definitions/Person'
|
||||
tags:
|
||||
- people
|
||||
delete:
|
||||
operationId: people_delete
|
||||
description: ''
|
||||
parameters: []
|
||||
responses:
|
||||
'204':
|
||||
description: ''
|
||||
tags:
|
||||
- people
|
||||
parameters:
|
||||
- name: id
|
||||
in: path
|
||||
description: A unique integer value identifying this person.
|
||||
required: true
|
||||
type: integer
|
||||
/people/{person}/identity:
|
||||
get:
|
||||
operationId: people_identity_read
|
||||
description: ''
|
||||
parameters: []
|
||||
responses:
|
||||
'200':
|
||||
description: ''
|
||||
schema:
|
||||
$ref: '#/definitions/Identity'
|
||||
tags:
|
||||
- people
|
||||
patch:
|
||||
operationId: people_identity_partial_update
|
||||
description: ''
|
||||
parameters:
|
||||
- name: data
|
||||
in: body
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/Identity'
|
||||
responses:
|
||||
'200':
|
||||
description: ''
|
||||
schema:
|
||||
$ref: '#/definitions/Identity'
|
||||
tags:
|
||||
- people
|
||||
parameters:
|
||||
- name: person
|
||||
in: path
|
||||
required: true
|
||||
type: string
|
||||
/plain/:
|
||||
get:
|
||||
operationId: plain_list
|
||||
@@ -330,7 +438,7 @@ paths:
|
||||
type: integer
|
||||
responses:
|
||||
'204':
|
||||
description: ''
|
||||
description: This should not crash
|
||||
tags:
|
||||
- snippets
|
||||
parameters:
|
||||
@@ -339,6 +447,105 @@ paths:
|
||||
description: A unique integer value identifying this snippet.
|
||||
required: true
|
||||
type: integer
|
||||
/todo/:
|
||||
get:
|
||||
operationId: todo_list
|
||||
description: ''
|
||||
parameters: []
|
||||
responses:
|
||||
'200':
|
||||
description: ''
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/definitions/Todo'
|
||||
tags:
|
||||
- todo
|
||||
parameters: []
|
||||
/todo/another/:
|
||||
get:
|
||||
operationId: todo_another_list
|
||||
description: ''
|
||||
parameters: []
|
||||
responses:
|
||||
'200':
|
||||
description: ''
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/definitions/TodoAnother'
|
||||
tags:
|
||||
- todo
|
||||
parameters: []
|
||||
/todo/another/{id}/:
|
||||
get:
|
||||
operationId: todo_another_read
|
||||
description: ''
|
||||
parameters: []
|
||||
responses:
|
||||
'200':
|
||||
description: ''
|
||||
schema:
|
||||
$ref: '#/definitions/TodoAnother'
|
||||
tags:
|
||||
- todo
|
||||
parameters:
|
||||
- name: id
|
||||
in: path
|
||||
description: A unique integer value identifying this todo another.
|
||||
required: true
|
||||
type: integer
|
||||
/todo/yetanother/:
|
||||
get:
|
||||
operationId: todo_yetanother_list
|
||||
description: ''
|
||||
parameters: []
|
||||
responses:
|
||||
'200':
|
||||
description: ''
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/definitions/TodoYetAnother'
|
||||
tags:
|
||||
- todo
|
||||
parameters: []
|
||||
/todo/yetanother/{id}/:
|
||||
get:
|
||||
operationId: todo_yetanother_read
|
||||
description: ''
|
||||
parameters: []
|
||||
responses:
|
||||
'200':
|
||||
description: ''
|
||||
schema:
|
||||
$ref: '#/definitions/TodoYetAnother'
|
||||
tags:
|
||||
- todo
|
||||
parameters:
|
||||
- name: id
|
||||
in: path
|
||||
description: A unique integer value identifying this todo yet another.
|
||||
required: true
|
||||
type: integer
|
||||
/todo/{id}/:
|
||||
get:
|
||||
operationId: todo_read
|
||||
description: ''
|
||||
parameters: []
|
||||
responses:
|
||||
'200':
|
||||
description: ''
|
||||
schema:
|
||||
$ref: '#/definitions/Todo'
|
||||
tags:
|
||||
- todo
|
||||
parameters:
|
||||
- name: id
|
||||
in: path
|
||||
description: A unique integer value identifying this todo.
|
||||
required: true
|
||||
type: integer
|
||||
/users/:
|
||||
get:
|
||||
operationId: users_list
|
||||
@@ -442,6 +649,7 @@ definitions:
|
||||
required:
|
||||
- title
|
||||
- body
|
||||
- group
|
||||
type: object
|
||||
properties:
|
||||
title:
|
||||
@@ -491,6 +699,50 @@ definitions:
|
||||
cover_name:
|
||||
type: string
|
||||
readOnly: true
|
||||
article_type:
|
||||
description: IntegerField declared on model with choices=(...) and exposed
|
||||
via ModelSerializer
|
||||
type: integer
|
||||
enum:
|
||||
- 1
|
||||
- 2
|
||||
- 3
|
||||
- 7
|
||||
- 8
|
||||
group:
|
||||
type: string
|
||||
format: uuid
|
||||
original_group:
|
||||
type: string
|
||||
format: uuid
|
||||
readOnly: true
|
||||
Identity:
|
||||
title: Identity
|
||||
type: object
|
||||
properties:
|
||||
id:
|
||||
title: ID
|
||||
type: integer
|
||||
readOnly: true
|
||||
firstName:
|
||||
title: FirstName
|
||||
type: string
|
||||
maxLength: 30
|
||||
lastName:
|
||||
title: LastName
|
||||
type: string
|
||||
maxLength: 30
|
||||
Person:
|
||||
required:
|
||||
- identity
|
||||
type: object
|
||||
properties:
|
||||
id:
|
||||
title: ID
|
||||
type: integer
|
||||
readOnly: true
|
||||
identity:
|
||||
$ref: '#/definitions/Identity'
|
||||
Project:
|
||||
required:
|
||||
- projectName
|
||||
@@ -538,7 +790,6 @@ definitions:
|
||||
title: Linenos
|
||||
type: boolean
|
||||
language:
|
||||
title: Language
|
||||
description: Sample help text for language
|
||||
type: object
|
||||
properties:
|
||||
@@ -983,7 +1234,6 @@ definitions:
|
||||
- zephir
|
||||
default: python
|
||||
styles:
|
||||
title: Styles
|
||||
type: array
|
||||
items:
|
||||
type: string
|
||||
@@ -1020,12 +1270,10 @@ definitions:
|
||||
default:
|
||||
- friendly
|
||||
lines:
|
||||
title: Lines
|
||||
type: array
|
||||
items:
|
||||
type: integer
|
||||
exampleProjects:
|
||||
title: Example projects
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/definitions/Project'
|
||||
@@ -1036,6 +1284,75 @@ definitions:
|
||||
type: number
|
||||
readOnly: true
|
||||
default: 6.9
|
||||
rateAsString:
|
||||
title: Rate as string
|
||||
type: string
|
||||
format: decimal
|
||||
default: '0.000'
|
||||
rate:
|
||||
title: Rate
|
||||
type: number
|
||||
format: decimal
|
||||
default: 0.0
|
||||
minimum: 0.0
|
||||
Todo:
|
||||
required:
|
||||
- title
|
||||
type: object
|
||||
properties:
|
||||
title:
|
||||
title: Title
|
||||
type: string
|
||||
maxLength: 50
|
||||
TodoAnother:
|
||||
required:
|
||||
- title
|
||||
- todo
|
||||
type: object
|
||||
properties:
|
||||
title:
|
||||
title: Title
|
||||
type: string
|
||||
maxLength: 50
|
||||
todo:
|
||||
$ref: '#/definitions/Todo'
|
||||
TodoYetAnother:
|
||||
required:
|
||||
- title
|
||||
type: object
|
||||
properties:
|
||||
title:
|
||||
title: Title
|
||||
type: string
|
||||
maxLength: 50
|
||||
todo:
|
||||
required:
|
||||
- title
|
||||
type: object
|
||||
properties:
|
||||
id:
|
||||
title: ID
|
||||
type: integer
|
||||
readOnly: true
|
||||
title:
|
||||
title: Title
|
||||
type: string
|
||||
maxLength: 50
|
||||
todo:
|
||||
required:
|
||||
- title
|
||||
type: object
|
||||
properties:
|
||||
id:
|
||||
title: ID
|
||||
type: integer
|
||||
readOnly: true
|
||||
title:
|
||||
title: Title
|
||||
type: string
|
||||
maxLength: 50
|
||||
readOnly: true
|
||||
readOnly: true
|
||||
UserSerializerrr:
|
||||
required:
|
||||
- username
|
||||
@@ -1060,13 +1377,11 @@ definitions:
|
||||
format: email
|
||||
maxLength: 254
|
||||
articles:
|
||||
title: Articles
|
||||
type: array
|
||||
items:
|
||||
type: integer
|
||||
uniqueItems: true
|
||||
snippets:
|
||||
title: Snippets
|
||||
type: array
|
||||
items:
|
||||
type: integer
|
||||
@@ -1084,7 +1399,6 @@ definitions:
|
||||
format: date
|
||||
readOnly: true
|
||||
article_slugs:
|
||||
title: Article slugs
|
||||
type: array
|
||||
items:
|
||||
type: string
|
||||
|
||||
@@ -46,3 +46,9 @@ def test_noop_inspectors(swagger_settings, mock_schema_request, codec_json, refe
|
||||
json_bytes = codec_json.encode(swagger)
|
||||
swagger_dict = json.loads(json_bytes.decode('utf-8'), object_pairs_hook=OrderedDict)
|
||||
compare_schemas(swagger_dict, reference_schema)
|
||||
|
||||
|
||||
def test_no_nested_model(swagger_dict):
|
||||
# ForeignKey models in deep ModelViewSets might wrongly be labeled as 'Nested' in the definitions section
|
||||
# see https://github.com/axnsan12/drf-yasg/issues/59
|
||||
assert 'Nested' not in swagger_dict['definitions']
|
||||
|
||||
@@ -2,11 +2,14 @@ import json
|
||||
from collections import OrderedDict
|
||||
|
||||
import pytest
|
||||
from rest_framework import routers, serializers, viewsets
|
||||
from rest_framework.response import Response
|
||||
|
||||
from drf_yasg import codecs, openapi
|
||||
from drf_yasg.codecs import yaml_sane_load
|
||||
from drf_yasg.errors import SwaggerGenerationError
|
||||
from drf_yasg.generators import OpenAPISchemaGenerator
|
||||
from drf_yasg.utils import swagger_auto_schema
|
||||
|
||||
|
||||
def test_schema_is_valid(swagger, codec_yaml):
|
||||
@@ -79,3 +82,34 @@ def test_securiy_requirements(swagger_settings, mock_schema_request):
|
||||
|
||||
swagger = generator.get_schema(mock_schema_request, public=True)
|
||||
assert swagger['security'] == []
|
||||
|
||||
|
||||
def test_replaced_serializer():
|
||||
class DetailSerializer(serializers.Serializer):
|
||||
detail = serializers.CharField()
|
||||
|
||||
class DetailViewSet(viewsets.ViewSet):
|
||||
serializer_class = DetailSerializer
|
||||
|
||||
@swagger_auto_schema(responses={404: openapi.Response("Not found or Not accessible", DetailSerializer)})
|
||||
def retrieve(self, request, pk=None):
|
||||
serializer = DetailSerializer({'detail': None})
|
||||
return Response(serializer.data)
|
||||
|
||||
router = routers.DefaultRouter()
|
||||
router.register(r'details', DetailViewSet, base_name='details')
|
||||
|
||||
generator = OpenAPISchemaGenerator(
|
||||
info=openapi.Info(title="Test generator", default_version="v1"),
|
||||
version="v2",
|
||||
url='',
|
||||
patterns=router.urls
|
||||
)
|
||||
|
||||
for _ in range(3):
|
||||
swagger = generator.get_schema(None, True)
|
||||
assert 'Detail' in swagger['definitions']
|
||||
assert 'detail' in swagger['definitions']['Detail']['properties']
|
||||
responses = swagger['paths']['/details/{id}/']['get']['responses']
|
||||
assert '404' in responses
|
||||
assert responses['404']['schema']['$ref'] == "#/definitions/Detail"
|
||||
|
||||
@@ -66,4 +66,4 @@ known_third_party =
|
||||
coreapi,coreschema,datadiff,dj_database_url,django,django_filters,djangorestframework_camel_case,flex,gunicorn,
|
||||
inflection,pygments,pytest,rest_framework,ruamel,setuptools_scm,swagger_spec_validator,uritemplate,user_agents,
|
||||
whitenoise
|
||||
known_first_party = drf_yasg,testproj,articles,snippets,users,urlconfs
|
||||
known_first_party = drf_yasg,testproj,articles,people,snippets,todo,users,urlconfs
|
||||
|
||||
Reference in New Issue
Block a user