Compare commits
105 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d2bd838325 | |||
| bacab20f0b | |||
| df82fe59d7 | |||
| 7c5a0b7176 | |||
| 69a1e62ed3 | |||
| 3806d6efd5 | |||
| 58e6dae548 | |||
| 8e2228fe5f | |||
| 762467285c | |||
| 0e62fd6f2b | |||
| e266eeda60 | |||
| 4b1098369c | |||
| bda545e85f | |||
| c1d3d4fe3c | |||
| 7f3ffe80a9 | |||
| 1fe8c2c03c | |||
| b8512bda8e | |||
| 2bc9addc99 | |||
| 6df2362156 | |||
| e5a569ebf7 | |||
| 470c993b98 | |||
| a5e4386f38 | |||
| 6bd91faa5d | |||
| 667c9c1002 | |||
| 8b0da2607f | |||
| d2cc0a348c | |||
| f020cbd99e | |||
| 68400386d3 | |||
| 7ce62616d2 | |||
| bebcc982e6 | |||
| 04d61b9d97 | |||
| b15535995f | |||
| dd5965fa92 | |||
| bfd13668cc | |||
| 01391ca9eb | |||
| 86ac276449 | |||
| 66026d3483 | |||
| db61c39ab1 | |||
| f77672875d | |||
| 8057ce7a4a | |||
| 3b31c54b9e | |||
| de950461c7 | |||
| 9d933a9745 | |||
| a9ec14620c | |||
| 5418415300 | |||
| 494d422bf4 | |||
| 85db6c9d79 | |||
| b385228f7d | |||
| bbed2acf06 | |||
| 0c38c30020 | |||
| a7d3066677 | |||
| e98876bb38 | |||
| 8974aa5734 | |||
| 5652d2a04d | |||
| cf4106f8f7 | |||
| a24070446a | |||
| 1fc454fcfa | |||
| 789f118532 | |||
| 1946a1204d | |||
| 930f3825d7 | |||
| dfd2bcabf2 | |||
| 4e4cd75fc4 | |||
| 7548a42a9b | |||
| e182ab65ea | |||
| f8e9fd6327 | |||
| f66c8e83e6 | |||
| c5d4e6ca53 | |||
| eeb1bba9e7 | |||
| 852742baa9 | |||
| 5b07b9dd40 | |||
| 306e53461d | |||
| 1d9387d8e5 | |||
| 1f95f4098b | |||
| acfb0c5442 | |||
| 543a1ade5e | |||
| f415a96aa6 | |||
| c52daaea8c | |||
| f6544654ab | |||
| f587785eb4 | |||
| 161a2e1b89 | |||
| a2bf515cc9 | |||
| 10a32f977c | |||
| 6b5022cd7d | |||
| 708e70a526 | |||
| 9f60dc191a | |||
| a2b35f3363 | |||
| 754ec8a779 | |||
| 3cd93bd572 | |||
| c5f6a79cc8 | |||
| 1ac85f6eba | |||
| c2e4d7767b | |||
| baaa79a29d | |||
| 8dfab883a5 | |||
| dfe06b5c95 | |||
| 18ff51a025 | |||
| e1aedab73f | |||
| 060fe1881a | |||
| 5d8c936956 | |||
| 25dea81bc6 | |||
| a419eec071 | |||
| d41f0c5ac4 | |||
| c510de13d7 | |||
| 207a7e2b2d | |||
| cbae10c434 | |||
| 81fa4b44c8 |
Generated
+7
@@ -0,0 +1,7 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<code_scheme name="Project" version="173">
|
||||
<codeStyleSettings language="Python">
|
||||
<option name="SOFT_MARGINS" value="120" />
|
||||
</codeStyleSettings>
|
||||
</code_scheme>
|
||||
</component>
|
||||
Generated
+5
@@ -0,0 +1,5 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<state>
|
||||
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
|
||||
</state>
|
||||
</component>
|
||||
Generated
+6
-1
@@ -16,7 +16,10 @@
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/testproj" isTestSource="false" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/.cache" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/.eggs" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/.pytest_cache" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/dist" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/docs/.doctrees" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/docs/_build" />
|
||||
@@ -26,12 +29,14 @@
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="Python 3 (drf-yasg)" jdkType="Python SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="immutable" level="application" />
|
||||
</component>
|
||||
<component name="TemplatesService">
|
||||
<option name="TEMPLATE_CONFIGURATION" value="Django" />
|
||||
<option name="TEMPLATE_FOLDERS">
|
||||
<list>
|
||||
<option value="$MODULE_DIR$/src/drf_yasg/templates" />
|
||||
<option value="$MODULE_DIR$/testproj/testproj/templates" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
@@ -39,4 +44,4 @@
|
||||
<option name="projectConfiguration" value="pytest" />
|
||||
<option name="PROJECT_TEST_RUNNER" value="pytest" />
|
||||
</component>
|
||||
</module>
|
||||
</module>
|
||||
|
||||
Generated
+4
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding" addBOMForNewFiles="with NO BOM" />
|
||||
</project>
|
||||
-5
@@ -55,11 +55,6 @@
|
||||
</option>
|
||||
</inspection_tool>
|
||||
<inspection_tool class="PyShadowingNamesInspection" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="PyUnusedLocalInspection" enabled="false" level="WEAK WARNING" enabled_by_default="false">
|
||||
<option name="ignoreTupleUnpacking" value="true" />
|
||||
<option name="ignoreLambdaParameters" value="true" />
|
||||
<option name="ignoreLoopIterationVariables" value="true" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="SpellCheckingInspection" enabled="false" level="TYPO" enabled_by_default="false">
|
||||
<option name="processCode" value="true" />
|
||||
<option name="processLiterals" value="true" />
|
||||
|
||||
Generated
+6
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="JavaScriptLibraryMappings">
|
||||
<file url="file://$PROJECT_DIR$" libraries="{immutable}" />
|
||||
</component>
|
||||
</project>
|
||||
Generated
+1
-1
@@ -73,4 +73,4 @@
|
||||
<component name="PythonCompatibilityInspectionAdvertiser">
|
||||
<option name="version" value="3" />
|
||||
</component>
|
||||
</project>
|
||||
</project>
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
requirements_file: requirements/docs.txt
|
||||
|
||||
build:
|
||||
image: latest
|
||||
|
||||
python:
|
||||
version: 3.6
|
||||
setup_py_install: false
|
||||
pip_install: true # need this for correct pyproject.toml handling
|
||||
extra_requirements:
|
||||
- validation
|
||||
|
||||
# extra formats in addition to the default HTML web docs
|
||||
formats:
|
||||
- pdf
|
||||
+15
-12
@@ -15,18 +15,19 @@ jobs:
|
||||
python: '3.7'
|
||||
dist: xenial
|
||||
sudo: required
|
||||
-
|
||||
python: '3.6'
|
||||
env: TOXENV=djmaster
|
||||
- # readthedocs uses python 3.5 for building
|
||||
python: '3.5'
|
||||
- python: '3.6'
|
||||
env: TOXENV=docs
|
||||
-
|
||||
python: '3.6'
|
||||
- python: '3.6'
|
||||
env: TOXENV=djmaster
|
||||
- python: '3.6'
|
||||
env: TOXENV=lint
|
||||
|
||||
- stage: publish
|
||||
python: '3.6'
|
||||
before_script:
|
||||
# workaround for Travis' inability to build PEP517 projects; anything added to build-system.requires
|
||||
# will also have to be added here until Travis implements this
|
||||
- pip install setuptools-scm
|
||||
script: skip
|
||||
env: PYPI_DEPLOY=true
|
||||
deploy: &pypi
|
||||
@@ -45,19 +46,21 @@ jobs:
|
||||
fast_finish: true
|
||||
|
||||
install:
|
||||
- pip install -r requirements/ci.txt
|
||||
- python -m pip install -U pip setuptools
|
||||
- pip install -r requirements/ci.txt
|
||||
|
||||
before_script:
|
||||
- coverage erase
|
||||
- coverage erase
|
||||
|
||||
script:
|
||||
- tox
|
||||
- tox
|
||||
|
||||
after_success:
|
||||
- |
|
||||
if [[ -z "$TOXENV" && -z "$PYPI_DEPLOY" ]]; then
|
||||
chmod +x coverage.sh
|
||||
./coverage.sh
|
||||
coverage combine || true
|
||||
coverage report
|
||||
codecov
|
||||
fi
|
||||
|
||||
branches:
|
||||
|
||||
+6
-5
@@ -35,6 +35,7 @@ You want to contribute some code? Great! Here are a few steps to get you started
|
||||
|
||||
$ virtualenv venv
|
||||
$ source venv/bin/activate
|
||||
(venv) $ python -m pip install -U pip setuptools
|
||||
(venv) $ pip install -U -e .[validation]
|
||||
(venv) $ pip install -U -r requirements/dev.txt
|
||||
|
||||
@@ -44,7 +45,6 @@ You want to contribute some code? Great! Here are a few steps to get you started
|
||||
|
||||
(venv) $ cd testproj
|
||||
(venv) $ python manage.py migrate
|
||||
(venv) $ python manage.py shell -c "import createsuperuser"
|
||||
(venv) $ python manage.py runserver
|
||||
(venv) $ firefox localhost:8000/swagger/
|
||||
|
||||
@@ -57,8 +57,7 @@ You want to contribute some code? Great! Here are a few steps to get you started
|
||||
|
||||
.. code:: console
|
||||
|
||||
(venv) $ cd testproj
|
||||
(venv) $ python manage.py generate_swagger ../tests/reference.yaml --overwrite --user admin --url http://test.local:8002/
|
||||
(venv) $ python testproj/manage.py generate_swagger ../tests/reference.yaml --overwrite --user admin --url http://test.local:8002/
|
||||
|
||||
After checking the git diff to verify that no unexpected changes appeared, you should commit the new
|
||||
``reference.yaml`` together with your changes.
|
||||
@@ -67,11 +66,13 @@ You want to contribute some code? Great! Here are a few steps to get you started
|
||||
|
||||
.. code:: console
|
||||
|
||||
# install test dependencies
|
||||
(venv) $ pip install -U -r requirements/test.txt
|
||||
# run tests in the current environment, faster than tox
|
||||
(venv) $ pytest -n auto --cov
|
||||
# (optional) sort imports with isort and check flake8 linting
|
||||
(venv) $ isort --apply
|
||||
(venv) $ flake8 src/drf_yasg testproj tests setup.py
|
||||
# run tests in the current environment, faster than tox
|
||||
(venv) $ pytest --cov
|
||||
# (optional) run tests for other python versions in separate environments
|
||||
(venv) $ tox
|
||||
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ License
|
||||
BSD 3-Clause License
|
||||
********************
|
||||
|
||||
Copyright (c) 2018, Cristian V. <cristi@cvjd.me> |br|\ All rights reserved.
|
||||
Copyright (c) 2017 - 2019, Cristian V. <cristi@cvjd.me> |br|\ All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
include README.rst
|
||||
include LICENSE.rst
|
||||
include pyproject.toml
|
||||
recursive-include requirements *
|
||||
recursive-include src/drf_yasg/static *
|
||||
recursive-include src/drf_yasg/templates *
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
release: python testproj/manage.py migrate && python testproj/manage.py shell -c "import createsuperuser"
|
||||
release: python testproj/manage.py migrate
|
||||
web: gunicorn --chdir testproj testproj.wsgi --log-file -
|
||||
|
||||
+15
-9
@@ -11,10 +11,17 @@ Generate **real** Swagger/OpenAPI 2.0 specifications from a Django Rest Framewor
|
||||
|
||||
Compatible with
|
||||
|
||||
- **Django Rest Framework**: 3.7.7, 3.8
|
||||
- **Django Rest Framework**: 3.7.7, 3.8, 3.9
|
||||
- **Django**: 1.11, 2.0, 2.1
|
||||
- **Python**: 2.7, 3.4, 3.5, 3.6, 3.7
|
||||
|
||||
Only the latest patch version of each ``major.minor`` series of Python, Django and Django REST Framework is supported.
|
||||
|
||||
**Only the latest version of drf-yasg is supported.** Support of old versions is dropped immediately with the release
|
||||
of a new version. Please do not create issues before upgrading to the latest release available at the time. Regression
|
||||
reports are accepted and will be resolved with a new release as quickly as possible. Removed features will usually go
|
||||
through a deprecation cycle of a few minor releases.
|
||||
|
||||
Resources:
|
||||
|
||||
* **Source**: https://github.com/axnsan12/drf-yasg/
|
||||
@@ -40,8 +47,7 @@ Features
|
||||
`redoc <https://github.com/Rebilly/ReDoc>`_ for viewing the generated documentation
|
||||
- schema view is cacheable out of the box
|
||||
- generated Swagger schema can be automatically validated by
|
||||
`swagger-spec-validator <https://github.com/Yelp/swagger_spec_validator>`_ or
|
||||
`flex <https://github.com/pipermerriam/flex>`_
|
||||
`swagger-spec-validator <https://github.com/Yelp/swagger_spec_validator>`_
|
||||
- supports Django REST Framework API versioning with ``URLPathVersioning`` and ``NamespaceVersioning``; other DRF
|
||||
or custom versioning schemes are not currently supported
|
||||
|
||||
@@ -114,6 +120,7 @@ In ``urls.py``:
|
||||
.. code:: python
|
||||
|
||||
...
|
||||
from rest_framework import permissions
|
||||
from drf_yasg.views import get_schema_view
|
||||
from drf_yasg import openapi
|
||||
|
||||
@@ -128,7 +135,6 @@ In ``urls.py``:
|
||||
contact=openapi.Contact(email="contact@snippets.local"),
|
||||
license=openapi.License(name="BSD License"),
|
||||
),
|
||||
validators=['flex', 'ssv'],
|
||||
public=True,
|
||||
permission_classes=(permissions.AllowAny,),
|
||||
)
|
||||
@@ -140,7 +146,7 @@ In ``urls.py``:
|
||||
...
|
||||
]
|
||||
|
||||
This exposes 4 cached, validated and publicly available endpoints:
|
||||
This exposes 4 endpoints:
|
||||
|
||||
* A JSON view of your API specification at ``/swagger.json``
|
||||
* A YAML view of your API specification at ``/swagger.yaml``
|
||||
@@ -159,7 +165,7 @@ a. ``get_schema_view`` parameters
|
||||
- ``patterns`` - passed to SchemaGenerator
|
||||
- ``urlconf`` - passed to SchemaGenerator
|
||||
- ``public`` - if False, includes only endpoints the current user has access to
|
||||
- ``validators`` - a list of validator names to apply on the generated schema; allowed values are ``flex``, ``ssv``
|
||||
- ``validators`` - a list of validator names to apply on the generated schema; only ``ssv`` is currently supported
|
||||
- ``generator_class`` - schema generator class to use; should be a subclass of ``OpenAPISchemaGenerator``
|
||||
- ``authentication_classes`` - authentication classes for the schema view itself
|
||||
- ``permission_classes`` - permission classes for the schema view itself
|
||||
@@ -204,9 +210,9 @@ caching the schema view in-memory, with some sane defaults:
|
||||
4. Validation
|
||||
=============
|
||||
|
||||
Given the numerous methods to manually customzie the generated schema, it makes sense to validate the result to ensure
|
||||
Given the numerous methods to manually customize the generated schema, it makes sense to validate the result to ensure
|
||||
it still conforms to OpenAPI 2.0. To this end, validation is provided at the generation point using python swagger
|
||||
libraries, and can be activated by passing :python:`validators=['flex', 'ssv']` to ``get_schema_view``; if the generated
|
||||
libraries, and can be activated by passing :python:`validators=['ssv']` to ``get_schema_view``; if the generated
|
||||
schema is not valid, a :python:`SwaggerValidationError` is raised by the handling codec.
|
||||
|
||||
**Warning:** This internal validation can slow down your server.
|
||||
@@ -294,9 +300,9 @@ For additional usage examples, you can take a look at the test project in the ``
|
||||
$ virtualenv venv
|
||||
$ source venv/bin/activate
|
||||
(venv) $ cd testproj
|
||||
(venv) $ python -m pip install -U pip setuptools
|
||||
(venv) $ pip install -U -r requirements.txt
|
||||
(venv) $ python manage.py migrate
|
||||
(venv) $ python manage.py shell -c "import createsuperuser"
|
||||
(venv) $ python manage.py runserver
|
||||
(venv) $ firefox localhost:8000/swagger/
|
||||
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -ex
|
||||
|
||||
coverage combine
|
||||
coverage report
|
||||
codecov
|
||||
+87
-1
@@ -3,13 +3,99 @@ Changelog
|
||||
#########
|
||||
|
||||
|
||||
**********
|
||||
**1.13.0**
|
||||
**********
|
||||
|
||||
*Release date: Jan 29, 2019*
|
||||
|
||||
- **IMPROVED:** type hint inspection is now supported for collections and``Optional`` (:pr:`272`)
|
||||
- **IMPROVED:** updated ``swagger-ui`` to version 3.20.5
|
||||
- **IMPROVED:** updated ``ReDoc`` to version 2.0.0-rc.2
|
||||
- **DEPRECATED:** quietly dropped support for the ``flex`` validator; it will still work if the library is installed,
|
||||
but the setup.py requirement was removed and the validator will be silently skipped if not installed (:issue:`285`)
|
||||
|
||||
**********
|
||||
**1.12.1**
|
||||
**********
|
||||
|
||||
*Release date: Dec 28, 2018*
|
||||
|
||||
- **IMPROVED:** updated ``ReDoc`` to version 2.0.0-rc.0
|
||||
- **FIXED:** management command will now correctly fall back to ``DEFAULT_VERSION`` for mock request
|
||||
- **FIXED:** fixed bad "raised exception during schema generation" warnings caused by missing ``self`` parameter
|
||||
|
||||
**********
|
||||
**1.12.0**
|
||||
**********
|
||||
|
||||
*Release date: Dec 23, 2018*
|
||||
|
||||
- **ADDED:** ``get_security_definitions`` and ``get_security_requirements`` hooks to ``OpenAPISchemaGenerator``
|
||||
- **ADDED:** added ``get_summary_and_description`` and ``split_summary_from_description`` extension points to
|
||||
``SwaggerAutoSchema`` to allow for better customisation
|
||||
- **IMPROVED:** updated ``swagger-ui`` to version 3.20.4
|
||||
- **IMPROVED:** paginator ``next`` and ``previous`` fields are now marked as ``x-nullable`` (:issue:`263`)
|
||||
- **IMPROVED:** added the ``tags`` argument to ``swagger_auto_schema`` (:pr:`259`)
|
||||
- **IMPROVED:** type of ``enum`` will now be automatically detected from ``ChoiceField`` if all ``choices`` values
|
||||
are objects of the same Python class (:pr:`264`)
|
||||
- **IMPROVED:** ``SwaggerValidationError`` details will now be logged and shown in the exception message
|
||||
- **FIXED:** user implementations of ``get_queryset``, ``get_parsers`` and ``get_renderers`` will no longer be bypassed
|
||||
- **FIXED:** fixed handling of lazy objects in user-supplied values
|
||||
- **FIXED:** ``read_only`` serializer fields will be correctly ignored when generating form parameters (:issue:`261`)
|
||||
- **FIXED:** fixed incorrect return type from ``UIRenderer`` (:pr:`268`)
|
||||
- **FIXED:** fixed incosistent ordering of global ``securityDefinitions`` and ``security`` objects
|
||||
- **DEPRECATED:** the ``get_summary`` and ``get_description`` extension points have been deprecated in favor of the
|
||||
new ``get_summary_and_description``, and will be removed in a future release
|
||||
|
||||
**IMPORTANT PACKAGING NOTE**
|
||||
|
||||
Starting with this version, the ``setup_requires`` argument was dropped from ``setup.py`` in favor of
|
||||
``build-system.requires`` in ``pyproject.toml`` . This means that for correctly building or installing from sdist,
|
||||
you will need to use a PEP517/PEP518 compliant tool (tox>=3.3.0, setuptools>=40, pip>=10.0, pep517.build) or manually
|
||||
install the build requirements yourself (just ``setuptools`` and ``setuptools-scm``, for now).
|
||||
|
||||
Additionally, for correct package version detection, a full git checkout is required when building (this was always the
|
||||
case). Building without ``.git`` or without ``setuptools-scm`` will result in a distribution with a version like
|
||||
``drf-yasg-1!0.0.0.dev0+noscm.00000167d19bd859``.
|
||||
|
||||
**********
|
||||
**1.11.1**
|
||||
**********
|
||||
|
||||
*Release date: Nov 29, 2018*
|
||||
|
||||
- **IMPROVED:** updated ``swagger-ui`` to version 3.20.1
|
||||
- **IMPROVED:** updated ``ReDoc`` to version 2.0.0-alpha.41
|
||||
- **FIXED:** ``minLength`` and ``maxLength`` will now also work for ``ListSerializer`` in addition to ``ListField``
|
||||
- **FIXED:** ``MultipleChoiceField`` will now use the ``multi`` ``collectionFormat`` where appropriate (:issue:`257`)
|
||||
- **FIXED:** the ``format``, ``pattern``, ``enum``, ``min_length`` and ``max_length`` attributes of
|
||||
``coreschema.Schema`` will now be persited into the converted ``openapi.Parameter`` (:issue:`212`, :pr:`233`)
|
||||
|
||||
**********
|
||||
**1.11.0**
|
||||
**********
|
||||
|
||||
*Release date: Oct 14, 2018*
|
||||
|
||||
- **ADDED:** ``PERSIST_AUTH``, ``REFETCH_SCHEMA_WITH_AUTH``, ``REFETCH_SCHEMA_ON_LOGOUT``
|
||||
settings and related javascript implementation for persisting authentication data to swagger-ui localStorage
|
||||
- **IMPROVED:** UI-enabled views will now no longer generate the full specification document twice; the HTML part
|
||||
of the view will only generate a barebones ``Swagger`` object with no ``paths`` and ``definitions``
|
||||
- **IMPROVED:** added the ``FETCH_SCHEMA_WITH_QUERY`` setting to enable fetching of the schema document using
|
||||
query parameters passed to the UI view (:issue:`208`)
|
||||
- **IMPROVED:** added support for the very common ``x-nullable`` extension (:issue:`217`)
|
||||
- **IMPROVED:** extensibility of some classes was improved by adding more extension points, together with more blocks
|
||||
for ``swagger-ui.html``/``redoc.html`` and some JavaScript hooks in ``swagger-ui-init.js``
|
||||
- **FIXED:** removed usage of ``inspect.signature`` on python 2.7 (:issue:`222`)
|
||||
|
||||
**********
|
||||
**1.10.2**
|
||||
**********
|
||||
|
||||
*Release date: Sep 13, 2018*
|
||||
|
||||
- **ADDED:** added the ``DISPLAY_OPERATION_ID `` ``swagger-ui`` setting
|
||||
- **ADDED:** added the ``DISPLAY_OPERATION_ID`` ``swagger-ui`` setting
|
||||
- **IMPROVED:** updated ``ReDoc`` to version 2.0.0-alpha.38
|
||||
- **IMPROVED:** Operation summary will now be parsed from multi-line view method docstrings (:issue:`205`)
|
||||
- **IMPROVED:** ``pattern`` will now work on any field with a ``RegexValidator``
|
||||
|
||||
+9
-1
@@ -48,6 +48,11 @@ author = 'Cristi V.'
|
||||
|
||||
# The full version, including alpha/beta/rc tags.
|
||||
release = get_distribution('drf_yasg').version
|
||||
if 'noscm' in release:
|
||||
raise AssertionError('Invalid package version string: %s. \n'
|
||||
'The documentation must be built with drf_yasg installed from a distribution package, '
|
||||
'which must have been built with a proper version number (i.e. from a full source checkout).'
|
||||
% (release,))
|
||||
|
||||
# The short X.Y.Z version.
|
||||
version = '.'.join(release.split('.')[:3])
|
||||
@@ -171,16 +176,19 @@ nitpick_ignore = [
|
||||
('py:class', 'int'),
|
||||
('py:class', 'bytes'),
|
||||
('py:class', 'tuple'),
|
||||
('py:class', 'callable'),
|
||||
('py:class', 'function'),
|
||||
('py:class', 'type'),
|
||||
('py:class', 'OrderedDict'),
|
||||
('py:class', 'None'),
|
||||
('py:obj', 'None'),
|
||||
|
||||
('py:class', 'Exception'),
|
||||
('py:class', 'collections.OrderedDict'),
|
||||
|
||||
('py:class', 'ruamel.yaml.dumper.SafeDumper'),
|
||||
('py:class', 'rest_framework.serializers.Serializer'),
|
||||
('py:class', 'rest_framework.renderers.BaseRenderer'),
|
||||
('py:class', 'rest_framework.parsers.BaseParser'),
|
||||
('py:class', 'rest_framework.schemas.generators.EndpointEnumerator'),
|
||||
('py:class', 'rest_framework.views.APIView'),
|
||||
|
||||
|
||||
@@ -314,7 +314,7 @@ implemented like so:
|
||||
))
|
||||
class ArticleViewSet(viewsets.ModelViewSet):
|
||||
filter_backends = (DjangoFilterBackend,)
|
||||
filter_fields = ('title',)
|
||||
filterset_fields = ('title',)
|
||||
...
|
||||
|
||||
|
||||
|
||||
+7
-10
@@ -4,15 +4,12 @@ Customizing the web UI
|
||||
|
||||
The web UI can be customized using the settings available in :ref:`swagger-ui-settings` and :ref:`redoc-ui-settings`.
|
||||
|
||||
You can also extend one of the ``drf-yasg/swagger-ui.html`` or ``drf-yasg/redoc.html`` templates that are used for
|
||||
rendering. The customizable blocks are currently limited to:
|
||||
You can also extend one of the `drf-yasg/swagger-ui.html`_ or `drf-yasg/redoc.html`_ templates that are used for
|
||||
rendering. See the template source code (linked above) for a complete list of customizable blocks.
|
||||
|
||||
{% block extra_styles %}
|
||||
additional stylesheets
|
||||
The ``swagger-ui`` view has some quite involed JavaScript hooks used for some functionality, which you might also
|
||||
want to review at `drf-yasg/swagger-ui-init.js`_.
|
||||
|
||||
{% block extra_scripts %}
|
||||
additional scripts
|
||||
|
||||
{% block user_context_message %}
|
||||
*(swagger-ui session auth only)*
|
||||
logged in user message
|
||||
.. _drf-yasg/swagger-ui.html: https://github.com/axnsan12/drf-yasg/blob/master/src/drf_yasg/templates/drf-yasg/swagger-ui.html
|
||||
.. _drf-yasg/swagger-ui-init.js: https://github.com/axnsan12/drf-yasg/blob/master/src/drf_yasg/static/drf-yasg/swagger-ui-init.js
|
||||
.. _drf-yasg/redoc.html: https://github.com/axnsan12/drf-yasg/blob/master/src/drf_yasg/templates/drf-yasg/redoc.html
|
||||
|
||||
+1
-1
@@ -81,7 +81,7 @@ A very simple working configuration was provided by :ghuser:`Vigrond`, originall
|
||||
'type': 'oauth2',
|
||||
'authorizationUrl': '/yourapp/o/authorize',
|
||||
'tokenUrl': '/yourapp/o/token/',
|
||||
'flow": "accessCode',
|
||||
'flow': 'accessCode',
|
||||
'scopes': {
|
||||
'read:groups': 'read groups',
|
||||
}
|
||||
|
||||
@@ -222,6 +222,40 @@ set to ``None`` to remove the badge.
|
||||
**Default**: :python:`'http://online.swagger.io/validator/'` |br|
|
||||
*Maps to parameter*: ``validatorUrl``
|
||||
|
||||
PERSIST_AUTH
|
||||
------------
|
||||
|
||||
Persist swagger-ui authorization data to local storage. |br|
|
||||
**WARNING:** This may be a security risk as the credentials are stored unencrypted and can be accessed
|
||||
by all javascript code running on the same domain.
|
||||
|
||||
**Default**: :python:`False` |br|
|
||||
*Maps to parameter*: -
|
||||
|
||||
REFETCH_SCHEMA_WITH_AUTH
|
||||
------------------------
|
||||
|
||||
Re-fetch the OpenAPI document with the new credentials after authorization is performed through swagger-ui.
|
||||
|
||||
**Default**: :python:`False` |br|
|
||||
*Maps to parameter*: -
|
||||
|
||||
REFETCH_SCHEMA_ON_LOGOUT
|
||||
------------------------
|
||||
|
||||
Re-fetch the OpenAPI document without credentials after authorization is removed through swagger-ui.
|
||||
|
||||
**Default**: :python:`False` |br|
|
||||
*Maps to parameter*: -
|
||||
|
||||
FETCH_SCHEMA_WITH_QUERY
|
||||
-----------------------
|
||||
|
||||
Fetch the OpenAPI document using the query parameters passed to the swagger-ui page request.
|
||||
|
||||
**Default**: :python:`True` |br|
|
||||
*Maps to parameter*: -
|
||||
|
||||
OPERATIONS_SORTER
|
||||
-----------------
|
||||
|
||||
@@ -415,5 +449,13 @@ Show required properties first ordered in the same order as in required array.
|
||||
**Default**: :python:`False` |br|
|
||||
*Maps to attribute*: ``requiredPropsFirst``
|
||||
|
||||
FETCH_SCHEMA_WITH_QUERY
|
||||
-----------------------
|
||||
|
||||
Fetch the OpenAPI document using the query parameters passed to the ReDoc page request.
|
||||
|
||||
**Default**: :python:`'True` |br|
|
||||
*Maps to parameter*: -
|
||||
|
||||
|
||||
.. _FORCE_SCRIPT_NAME: https://docs.djangoproject.com/en/2.0/ref/settings/#force-script-name
|
||||
|
||||
Generated
+124
-236
@@ -3,6 +3,14 @@
|
||||
"requires": true,
|
||||
"lockfileVersion": 1,
|
||||
"dependencies": {
|
||||
"@babel/runtime": {
|
||||
"version": "7.3.1",
|
||||
"resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.3.1.tgz",
|
||||
"integrity": "sha512-7jGW8ppV0ant637pIqAcFfQDDH1orEPGJb8aXfUozuCU3QqX7rX4DA8iwrbPrR1hcH0FTTHz47yQnk+bl5xHQA==",
|
||||
"requires": {
|
||||
"regenerator-runtime": "^0.12.0"
|
||||
}
|
||||
},
|
||||
"argparse": {
|
||||
"version": "1.0.10",
|
||||
"resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz",
|
||||
@@ -11,24 +19,10 @@
|
||||
"sprintf-js": "~1.0.2"
|
||||
}
|
||||
},
|
||||
"asap": {
|
||||
"version": "2.0.6",
|
||||
"resolved": "https://registry.npmjs.org/asap/-/asap-2.0.6.tgz",
|
||||
"integrity": "sha1-5QNHYR1+aQlDIIu9r+vLwvuGbUY="
|
||||
},
|
||||
"base64-js": {
|
||||
"version": "1.3.0",
|
||||
"resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.3.0.tgz",
|
||||
"integrity": "sha512-ccav/yGvoa80BQDljCxsmmQ3Xvx60/UpBIij5QN21W3wBi/hhIC9OoO+KLpu9IJTS9j4DRVJ3aDDF9cMSoa2lw=="
|
||||
},
|
||||
"buffer": {
|
||||
"version": "5.2.1",
|
||||
"resolved": "https://registry.npmjs.org/buffer/-/buffer-5.2.1.tgz",
|
||||
"integrity": "sha512-c+Ko0loDaFfuPWiL02ls9Xd3GO3cPVmUobQ6t3rXNUk304u6hGq+8N/kFi+QEIKhzK3uwolVhLzszmfLmMLnqg==",
|
||||
"requires": {
|
||||
"base64-js": "^1.0.2",
|
||||
"ieee754": "^1.1.4"
|
||||
}
|
||||
"big.js": {
|
||||
"version": "5.2.2",
|
||||
"resolved": "https://registry.npmjs.org/big.js/-/big.js-5.2.2.tgz",
|
||||
"integrity": "sha512-vyL2OymJxmarO8gxMr0mhChsO9QGwhynfuu4+MHTAW6czfq9humCB7rKpUjDd9YUiDPU4mzpyupFSvOClAwbmQ=="
|
||||
},
|
||||
"call-me-maybe": {
|
||||
"version": "1.0.1",
|
||||
@@ -41,9 +35,9 @@
|
||||
"integrity": "sha512-JR/iSQOSt+LQIWwrwEzJ9uk0xfN3mTVYMwt1Ir5mUcSN6pU+V4zQFFaJsclJbPuAUQH+yfWef6tm7l1quW3C8Q=="
|
||||
},
|
||||
"clipboard": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/clipboard/-/clipboard-2.0.1.tgz",
|
||||
"integrity": "sha512-7yhQBmtN+uYZmfRjjVjKa0dZdWuabzpSKGtyQZN+9C8xlC788SSJjOHWh7tzurfwTqTD5UDYAhIv5fRJg3sHjQ==",
|
||||
"version": "2.0.4",
|
||||
"resolved": "https://registry.npmjs.org/clipboard/-/clipboard-2.0.4.tgz",
|
||||
"integrity": "sha512-Vw26VSLRpJfBofiVaFb/I8PVfdI1OxKcYShe6fm0sP/DtmiWQNCjhM/okTvdCo0G+lMMm1rMYbk4IK4x1X+kgQ==",
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"good-listener": "^1.2.2",
|
||||
@@ -51,34 +45,6 @@
|
||||
"tiny-emitter": "^2.0.0"
|
||||
}
|
||||
},
|
||||
"core-js": {
|
||||
"version": "1.2.7",
|
||||
"resolved": "https://registry.npmjs.org/core-js/-/core-js-1.2.7.tgz",
|
||||
"integrity": "sha1-ZSKUwUZR2yj6k70tX/KYOk8IxjY="
|
||||
},
|
||||
"css-color-keywords": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/css-color-keywords/-/css-color-keywords-1.0.0.tgz",
|
||||
"integrity": "sha1-/qJhbcZ2spYmhrOvjb2+GAskTgU="
|
||||
},
|
||||
"css-to-react-native": {
|
||||
"version": "2.2.1",
|
||||
"resolved": "https://registry.npmjs.org/css-to-react-native/-/css-to-react-native-2.2.1.tgz",
|
||||
"integrity": "sha512-v++LRcf633phJiYZBDqtmGPj3+BVof0isd2jgwYLWZJ5YSuhCkrfYtDsNhM6oJthiEco0f9tDVJ1vUkDJNgGEA==",
|
||||
"requires": {
|
||||
"css-color-keywords": "^1.0.0",
|
||||
"fbjs": "^0.8.5",
|
||||
"postcss-value-parser": "^3.3.0"
|
||||
}
|
||||
},
|
||||
"debug": {
|
||||
"version": "3.2.5",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-3.2.5.tgz",
|
||||
"integrity": "sha512-D61LaDQPQkxJ5AUM2mbSJRbPkNs/TmdmOeLAi1hgDkpDfIfetSrjmWhccwtuResSwMbACjx/xXQofvM9CE/aeg==",
|
||||
"requires": {
|
||||
"ms": "^2.1.1"
|
||||
}
|
||||
},
|
||||
"decko": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/decko/-/decko-1.2.0.tgz",
|
||||
@@ -96,17 +62,14 @@
|
||||
"integrity": "sha1-ZyIm3HTI95mtNTB9+TaroRrNYBg="
|
||||
},
|
||||
"dompurify": {
|
||||
"version": "1.0.8",
|
||||
"resolved": "https://registry.npmjs.org/dompurify/-/dompurify-1.0.8.tgz",
|
||||
"integrity": "sha512-vetRFbN1SXSPfP3ClIiYnxTrXquSqakBEOoB5JESn0SVcSYzpu6ougjakpKnskGctYdlNpwf+riUHSkG7d4XUw=="
|
||||
"version": "1.0.9",
|
||||
"resolved": "https://registry.npmjs.org/dompurify/-/dompurify-1.0.9.tgz",
|
||||
"integrity": "sha512-lt9f3A3RO1OCNaWdA+s/k7YVn0Typ5MbAKmX94PLCZbs8wLNccX3Bj4xXA7GLKOoDb/MeVoAoeIJarZD1JUnjg=="
|
||||
},
|
||||
"encoding": {
|
||||
"version": "0.1.12",
|
||||
"resolved": "https://registry.npmjs.org/encoding/-/encoding-0.1.12.tgz",
|
||||
"integrity": "sha1-U4tm8+5izRq1HsMjgp0flIDHS+s=",
|
||||
"requires": {
|
||||
"iconv-lite": "~0.4.13"
|
||||
}
|
||||
"emojis-list": {
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/emojis-list/-/emojis-list-2.1.0.tgz",
|
||||
"integrity": "sha1-TapNnbAPmBmIDHn6RXrlsJof04k="
|
||||
},
|
||||
"esprima": {
|
||||
"version": "4.0.1",
|
||||
@@ -123,20 +86,6 @@
|
||||
"resolved": "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz",
|
||||
"integrity": "sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc="
|
||||
},
|
||||
"fbjs": {
|
||||
"version": "0.8.17",
|
||||
"resolved": "https://registry.npmjs.org/fbjs/-/fbjs-0.8.17.tgz",
|
||||
"integrity": "sha1-xNWY6taUkRJlPWWIsBpc3Nn5D90=",
|
||||
"requires": {
|
||||
"core-js": "^1.0.0",
|
||||
"isomorphic-fetch": "^2.1.1",
|
||||
"loose-envify": "^1.0.0",
|
||||
"object-assign": "^4.1.0",
|
||||
"promise": "^7.1.1",
|
||||
"setimmediate": "^1.0.5",
|
||||
"ua-parser-js": "^0.7.18"
|
||||
}
|
||||
},
|
||||
"foreach": {
|
||||
"version": "2.0.5",
|
||||
"resolved": "https://registry.npmjs.org/foreach/-/foreach-2.0.5.tgz",
|
||||
@@ -165,41 +114,12 @@
|
||||
"delegate": "^3.1.2"
|
||||
}
|
||||
},
|
||||
"has-flag": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-1.0.0.tgz",
|
||||
"integrity": "sha1-nZ55MWXOAXoA8AQYxD+UKnsdEfo="
|
||||
},
|
||||
"hoist-non-react-statics": {
|
||||
"version": "2.5.5",
|
||||
"resolved": "https://registry.npmjs.org/hoist-non-react-statics/-/hoist-non-react-statics-2.5.5.tgz",
|
||||
"integrity": "sha512-rqcy4pJo55FTTLWt+bU8ukscqHeE/e9KWvsOW2b/a3afxQZhwkQdT1rPPCJ0rYXdj4vNcasY8zHTH+jF/qStxw=="
|
||||
},
|
||||
"iconv-lite": {
|
||||
"version": "0.4.24",
|
||||
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz",
|
||||
"integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==",
|
||||
"version": "3.3.0",
|
||||
"resolved": "https://registry.npmjs.org/hoist-non-react-statics/-/hoist-non-react-statics-3.3.0.tgz",
|
||||
"integrity": "sha512-0XsbTXxgiaCDYDIWFcwkmerZPSwywfUqYmwT4jzewKTQSWoE6FCMoUVOeBJWK3E/CrWbxRG3m5GzY4lnIwGRBA==",
|
||||
"requires": {
|
||||
"safer-buffer": ">= 2.1.2 < 3"
|
||||
}
|
||||
},
|
||||
"ieee754": {
|
||||
"version": "1.1.12",
|
||||
"resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.1.12.tgz",
|
||||
"integrity": "sha512-GguP+DRY+pJ3soyIiGPTvdiVXjZ+DbXOxGpXn3eMvNW4x4irjqXm4wHKscC+TfxSJ0yw/S1F24tqdMNsMZTiLA=="
|
||||
},
|
||||
"is-stream": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz",
|
||||
"integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ="
|
||||
},
|
||||
"isomorphic-fetch": {
|
||||
"version": "2.2.1",
|
||||
"resolved": "https://registry.npmjs.org/isomorphic-fetch/-/isomorphic-fetch-2.2.1.tgz",
|
||||
"integrity": "sha1-YRrhrPFPXoH3KVB0coGf6XM1WKk=",
|
||||
"requires": {
|
||||
"node-fetch": "^1.0.1",
|
||||
"whatwg-fetch": ">=0.10.0"
|
||||
"react-is": "^16.7.0"
|
||||
}
|
||||
},
|
||||
"js-tokens": {
|
||||
@@ -208,9 +128,9 @@
|
||||
"integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ=="
|
||||
},
|
||||
"js-yaml": {
|
||||
"version": "3.12.0",
|
||||
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.12.0.tgz",
|
||||
"integrity": "sha512-PIt2cnwmPfL4hKNwqeiuz4bKfnzHTBv6HyVgjahA6mPLwPDzjDWrplJBMjHUFxku/N3FlmrbyPclad+I+4mJ3A==",
|
||||
"version": "3.12.1",
|
||||
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.12.1.tgz",
|
||||
"integrity": "sha512-um46hB9wNOKlwkHgiuyEVAybXBjwFUV0Z/RaHJblRd9DXltue9FTYvzCr9ErQrK9Adz5MU4gHWVaNUfdmrC8qA==",
|
||||
"requires": {
|
||||
"argparse": "^1.0.7",
|
||||
"esprima": "^4.0.0"
|
||||
@@ -225,16 +145,38 @@
|
||||
}
|
||||
},
|
||||
"json-schema-ref-parser": {
|
||||
"version": "5.1.3",
|
||||
"resolved": "https://registry.npmjs.org/json-schema-ref-parser/-/json-schema-ref-parser-5.1.3.tgz",
|
||||
"integrity": "sha512-CpDFlBwz/6la78hZxyB9FECVKGYjIIl3Ms3KLqFj99W7IIb7D00/RDgc++IGB4BBALl0QRhh5m4q5WNSopvLtQ==",
|
||||
"version": "6.0.3",
|
||||
"resolved": "https://registry.npmjs.org/json-schema-ref-parser/-/json-schema-ref-parser-6.0.3.tgz",
|
||||
"integrity": "sha512-Ds/0541IPed88JSiMb3CBeUsxfL5Eosc0r97z0QMSXiBJTYKZLhOAGZd8zFVfpkKaRb4zDAnumyFYxnHLmbQmw==",
|
||||
"requires": {
|
||||
"call-me-maybe": "^1.0.1",
|
||||
"debug": "^3.1.0",
|
||||
"js-yaml": "^3.12.0",
|
||||
"ono": "^4.0.6"
|
||||
"js-yaml": "^3.12.1",
|
||||
"ono": "^4.0.11"
|
||||
}
|
||||
},
|
||||
"json5": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/json5/-/json5-1.0.1.tgz",
|
||||
"integrity": "sha512-aKS4WQjPenRxiQsC93MNfjx+nbF4PAdYzmd/1JIj8HYzqfbu86beTuNgXDzPknWk0n0uARlyewZo4s++ES36Ow==",
|
||||
"requires": {
|
||||
"minimist": "^1.2.0"
|
||||
}
|
||||
},
|
||||
"loader-utils": {
|
||||
"version": "1.2.3",
|
||||
"resolved": "https://registry.npmjs.org/loader-utils/-/loader-utils-1.2.3.tgz",
|
||||
"integrity": "sha512-fkpz8ejdnEMG3s37wGL07iSBDg99O9D5yflE9RGNH3hRdx9SOwYfnGYdZOUIZitN8E+E2vkq3MUMYMvPYl5ZZA==",
|
||||
"requires": {
|
||||
"big.js": "^5.2.2",
|
||||
"emojis-list": "^2.0.0",
|
||||
"json5": "^1.0.1"
|
||||
}
|
||||
},
|
||||
"lodash.merge": {
|
||||
"version": "4.6.1",
|
||||
"resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.1.tgz",
|
||||
"integrity": "sha512-AOYza4+Hf5z1/0Hztxpm2/xiPZgi/cjMqdnKTUWTBSKchJlxXXuUSxCCl8rJlf4g6yww/j6mA8nC8Hw/EZWxKQ=="
|
||||
},
|
||||
"loose-envify": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz",
|
||||
@@ -244,9 +186,9 @@
|
||||
}
|
||||
},
|
||||
"lunr": {
|
||||
"version": "2.3.3",
|
||||
"resolved": "https://registry.npmjs.org/lunr/-/lunr-2.3.3.tgz",
|
||||
"integrity": "sha512-rlAEsgU9Bnavca2w1WJ6+6cdeHMXNyadcersyk3ZpuhgWb5HBNj8l4WwJz9PjksAhYDlpQffCVXPctOn+wCIVA=="
|
||||
"version": "2.3.5",
|
||||
"resolved": "https://registry.npmjs.org/lunr/-/lunr-2.3.5.tgz",
|
||||
"integrity": "sha512-EtnfmHsHJTr3u24sito9JctSxej5Ds0SgUD2Lm+qRHyLgM7BGesFlW14eNh1mil0fV5Muh8gf3dBBXzADlUlzQ=="
|
||||
},
|
||||
"mark.js": {
|
||||
"version": "8.11.1",
|
||||
@@ -254,14 +196,14 @@
|
||||
"integrity": "sha1-GA8fnr74sOY45BZq1S24eb6y/8U="
|
||||
},
|
||||
"marked": {
|
||||
"version": "0.3.18",
|
||||
"resolved": "https://registry.npmjs.org/marked/-/marked-0.3.18.tgz",
|
||||
"integrity": "sha512-49i2QYhfULqaXzNZpxC808PisuCTGT2fgG0zrzdCI9N3rIfAWfW0nggvbXr6zvpynZdOG5+9xNxdzP0kwZnERw=="
|
||||
"version": "0.6.0",
|
||||
"resolved": "https://registry.npmjs.org/marked/-/marked-0.6.0.tgz",
|
||||
"integrity": "sha512-HduzIW2xApSXKXJSpCipSxKyvMbwRRa/TwMbepmlZziKdH8548WSoDP4SxzulEKjlo8BE39l+2fwJZuRKOln6g=="
|
||||
},
|
||||
"memoize-one": {
|
||||
"version": "4.0.2",
|
||||
"resolved": "https://registry.npmjs.org/memoize-one/-/memoize-one-4.0.2.tgz",
|
||||
"integrity": "sha512-ucx2DmXTeZTsS4GPPUZCbULAN7kdPT1G+H49Y34JjbQ5ESc6OGhVxKvb1iKhr9v19ZB9OtnHwNnhUnNR/7Wteg=="
|
||||
"version": "4.0.3",
|
||||
"resolved": "https://registry.npmjs.org/memoize-one/-/memoize-one-4.0.3.tgz",
|
||||
"integrity": "sha512-QmpUu4KqDmX0plH4u+tf0riMc1KHE1+lw95cMrLlXQAFOx/xnBtwhZ52XJxd9X2O6kwKBqX32kmhbhlobD0cuw=="
|
||||
},
|
||||
"min-document": {
|
||||
"version": "2.19.0",
|
||||
@@ -271,38 +213,29 @@
|
||||
"dom-walk": "^0.1.0"
|
||||
}
|
||||
},
|
||||
"minimist": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz",
|
||||
"integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ="
|
||||
},
|
||||
"mobx-react": {
|
||||
"version": "5.2.8",
|
||||
"resolved": "https://registry.npmjs.org/mobx-react/-/mobx-react-5.2.8.tgz",
|
||||
"integrity": "sha512-VAkeqkrIpdoy3VPPoqvxjdQmcTT6hi7i3TsZSwcKbSrPbSTuWc7cp1EOiX/zV1wPWEuoNAQ22bCrskQwvdYTJA==",
|
||||
"version": "5.4.3",
|
||||
"resolved": "https://registry.npmjs.org/mobx-react/-/mobx-react-5.4.3.tgz",
|
||||
"integrity": "sha512-WC8yFlwvJ91hy8j6CrydAuFteUafcuvdITFQeHl3LRIf5ayfT/4W3M/byhEYD2BcJWejeXr8y4Rh2H26RunCRQ==",
|
||||
"requires": {
|
||||
"hoist-non-react-statics": "^2.5.0",
|
||||
"hoist-non-react-statics": "^3.0.0",
|
||||
"react-lifecycles-compat": "^3.0.2"
|
||||
}
|
||||
},
|
||||
"ms": {
|
||||
"version": "2.1.1",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz",
|
||||
"integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg=="
|
||||
},
|
||||
"node-fetch": {
|
||||
"version": "1.7.3",
|
||||
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-1.7.3.tgz",
|
||||
"integrity": "sha512-NhZ4CsKx7cYm2vSrBAr2PvFOe6sWDf0UYLRqA6svUYg7+/TSfVAu49jYC4BvQ4Sms9SZgdqGBgroqfDhJdTyKQ==",
|
||||
"requires": {
|
||||
"encoding": "^0.1.11",
|
||||
"is-stream": "^1.0.1"
|
||||
}
|
||||
},
|
||||
"object-assign": {
|
||||
"version": "4.1.1",
|
||||
"resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
|
||||
"integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM="
|
||||
},
|
||||
"ono": {
|
||||
"version": "4.0.7",
|
||||
"resolved": "https://registry.npmjs.org/ono/-/ono-4.0.7.tgz",
|
||||
"integrity": "sha512-FJiGEETwfSVyOwVTwQZD7XN69FRekvgtlobtvPwtilc7PxIHg3gKUykdNP7E9mC/VTF2cxqKZxUZfNKA3MuQLA==",
|
||||
"version": "4.0.11",
|
||||
"resolved": "https://registry.npmjs.org/ono/-/ono-4.0.11.tgz",
|
||||
"integrity": "sha512-jQ31cORBFE6td25deYeD80wxKBMj+zBmHTrVxnc6CKhx8gho6ipmWM5zj/oeoqioZ99yqBls9Z/9Nss7J26G2g==",
|
||||
"requires": {
|
||||
"format-util": "^1.0.3"
|
||||
}
|
||||
@@ -321,14 +254,12 @@
|
||||
"integrity": "sha512-/2Sk/khljhdrsamjJYS5NjrH+GKEHEwh7zFSiYyxROyYKagkE4kSn2zDQDRTOMo8mpT2jikxx6yI1dG7lNP/hw=="
|
||||
},
|
||||
"polished": {
|
||||
"version": "2.0.3",
|
||||
"resolved": "https://registry.npmjs.org/polished/-/polished-2.0.3.tgz",
|
||||
"integrity": "sha512-MMwthxXsmZZlZY/x79KX/8kXpSU0lq3ntnDmAdhpQGk9pU9EM/rQmUbsgIuuk2Cvl6zYSWjyBsDEU8sa1598xg=="
|
||||
},
|
||||
"postcss-value-parser": {
|
||||
"version": "3.3.0",
|
||||
"resolved": "https://registry.npmjs.org/postcss-value-parser/-/postcss-value-parser-3.3.0.tgz",
|
||||
"integrity": "sha1-h/OPnxj3dKSrTIojL1xc6IcqnRU="
|
||||
"version": "2.3.3",
|
||||
"resolved": "https://registry.npmjs.org/polished/-/polished-2.3.3.tgz",
|
||||
"integrity": "sha512-59V4fDbdxtH4I1m9TWxFsoGJbC8nnOpUYo5uFmvMfKp9Qh+6suo4VMUle1TGIIUZIGxfkW+Rs485zPk0wcwR2Q==",
|
||||
"requires": {
|
||||
"@babel/runtime": "^7.2.0"
|
||||
}
|
||||
},
|
||||
"prismjs": {
|
||||
"version": "1.15.0",
|
||||
@@ -343,14 +274,6 @@
|
||||
"resolved": "https://registry.npmjs.org/process/-/process-0.5.2.tgz",
|
||||
"integrity": "sha1-FjjYqONML0QKkduVq5rrZ3/Bhc8="
|
||||
},
|
||||
"promise": {
|
||||
"version": "7.3.1",
|
||||
"resolved": "https://registry.npmjs.org/promise/-/promise-7.3.1.tgz",
|
||||
"integrity": "sha512-nolQXZ/4L+bP/UGlkfaIujX9BKxGwmQ9OT4mOt5yvy8iK1h3wqTEJCijzGANTCCl9nWjY41juyAn2K3Q1hLLTg==",
|
||||
"requires": {
|
||||
"asap": "~2.0.3"
|
||||
}
|
||||
},
|
||||
"prop-types": {
|
||||
"version": "15.6.2",
|
||||
"resolved": "https://registry.npmjs.org/prop-types/-/prop-types-15.6.2.tgz",
|
||||
@@ -361,30 +284,40 @@
|
||||
}
|
||||
},
|
||||
"react-dropdown": {
|
||||
"version": "1.6.2",
|
||||
"resolved": "https://registry.npmjs.org/react-dropdown/-/react-dropdown-1.6.2.tgz",
|
||||
"integrity": "sha512-6RpKAFEVZLr53y91qnxC9rAWcoDvq8A9YstmeSV2AQgJxNFRcsreN1mJNRUctSvIwm0Hph07ouMvDc2GvfQBsA==",
|
||||
"version": "1.6.4",
|
||||
"resolved": "https://registry.npmjs.org/react-dropdown/-/react-dropdown-1.6.4.tgz",
|
||||
"integrity": "sha512-zTlNRZ6vzjEPsodBNgh6Xjp9IempEx9sReH3crT2Jw4S6KW2wS/BRIH3d/grYf/iXARadDRD91//uUCs9yjoLg==",
|
||||
"requires": {
|
||||
"classnames": "^2.2.3"
|
||||
}
|
||||
},
|
||||
"react-hot-loader": {
|
||||
"version": "4.3.6",
|
||||
"resolved": "https://registry.npmjs.org/react-hot-loader/-/react-hot-loader-4.3.6.tgz",
|
||||
"integrity": "sha512-iuBeBkLz7tdkKmKduNww9o5JY4ZH1XI0TWwkWToHIqfOSh1xMCqLMSYXUasWfgZWykWWa9IkueYab+cDq2jyWg==",
|
||||
"version": "4.6.3",
|
||||
"resolved": "https://registry.npmjs.org/react-hot-loader/-/react-hot-loader-4.6.3.tgz",
|
||||
"integrity": "sha512-FUvRO8dwbeLnc3mgLn8ARuSh8NnLBYJyiRjFn+grY/5GupSyPqv0U7ixgwXro77hwDplhm8z9wU7FlJ8kZqiAQ==",
|
||||
"requires": {
|
||||
"fast-levenshtein": "^2.0.6",
|
||||
"global": "^4.3.0",
|
||||
"hoist-non-react-statics": "^2.5.0",
|
||||
"loader-utils": "^1.1.0",
|
||||
"lodash.merge": "^4.6.1",
|
||||
"prop-types": "^15.6.1",
|
||||
"react-lifecycles-compat": "^3.0.4",
|
||||
"shallowequal": "^1.0.2"
|
||||
"shallowequal": "^1.0.2",
|
||||
"source-map": "^0.7.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"hoist-non-react-statics": {
|
||||
"version": "2.5.5",
|
||||
"resolved": "https://registry.npmjs.org/hoist-non-react-statics/-/hoist-non-react-statics-2.5.5.tgz",
|
||||
"integrity": "sha512-rqcy4pJo55FTTLWt+bU8ukscqHeE/e9KWvsOW2b/a3afxQZhwkQdT1rPPCJ0rYXdj4vNcasY8zHTH+jF/qStxw=="
|
||||
}
|
||||
}
|
||||
},
|
||||
"react-is": {
|
||||
"version": "16.5.0",
|
||||
"resolved": "https://registry.npmjs.org/react-is/-/react-is-16.5.0.tgz",
|
||||
"integrity": "sha512-kpkCGLsChXTEQJVmowQqHpCjHKJFwB4SIChYaaaiAkq8OtE2aBg5pQe8/xnFlGmz9KmMx1H4oQRUyxP7qC9v5A=="
|
||||
"version": "16.7.0",
|
||||
"resolved": "https://registry.npmjs.org/react-is/-/react-is-16.7.0.tgz",
|
||||
"integrity": "sha512-Z0VRQdF4NPDoI0tsXVMLkJLiwEBa+RP66g0xDHxgxysxSoCUccSten4RTF/UFvZF1dZvZ9Zu1sx+MDXwcOR34g=="
|
||||
},
|
||||
"react-lifecycles-compat": {
|
||||
"version": "3.0.4",
|
||||
@@ -401,19 +334,19 @@
|
||||
}
|
||||
},
|
||||
"redoc": {
|
||||
"version": "2.0.0-alpha.38",
|
||||
"resolved": "https://registry.npmjs.org/redoc/-/redoc-2.0.0-alpha.38.tgz",
|
||||
"integrity": "sha512-4pT/cRJ/aKdLlCxjFOSWvkA9ZVG5b9dUfxIM+H5698hlRaF6rcu4qh29eGwEikSDw0unH0iNd6MHy9u0fAjRGw==",
|
||||
"version": "2.0.0-rc.2",
|
||||
"resolved": "https://registry.npmjs.org/redoc/-/redoc-2.0.0-rc.2.tgz",
|
||||
"integrity": "sha512-KsacFfNeBSBwGbWD8zzckYZ9V5TQB33xCl0I2pNQrWEEyhOZyfpp4Sf7qmOVYxj8DzdqHTP/HJiCtH84o68+mg==",
|
||||
"requires": {
|
||||
"classnames": "^2.2.6",
|
||||
"decko": "^1.2.0",
|
||||
"dompurify": "^1.0.7",
|
||||
"eventemitter3": "^3.0.0",
|
||||
"json-pointer": "^0.6.0",
|
||||
"json-schema-ref-parser": "^5.1.2",
|
||||
"json-schema-ref-parser": "^6.0.1",
|
||||
"lunr": "^2.3.2",
|
||||
"mark.js": "^8.11.1",
|
||||
"marked": "0.3.18",
|
||||
"marked": "^0.6.0",
|
||||
"memoize-one": "^4.0.0",
|
||||
"mobx-react": "^5.2.5",
|
||||
"openapi-sampler": "1.0.0-beta.14",
|
||||
@@ -426,14 +359,13 @@
|
||||
"react-tabs": "^2.0.0",
|
||||
"slugify": "^1.3.1",
|
||||
"stickyfill": "^1.1.1",
|
||||
"styled-components": "^3.4.5",
|
||||
"tslib": "^1.9.3"
|
||||
}
|
||||
},
|
||||
"safer-buffer": {
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
|
||||
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="
|
||||
"regenerator-runtime": {
|
||||
"version": "0.12.1",
|
||||
"resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.12.1.tgz",
|
||||
"integrity": "sha512-odxIc1/vDlo4iZcfXqRYFj0vpXFNoGdKMAUieAlFYO6m/nl5e9KR/beGf41z4a1FI+aQgtjhuaSlDxQ0hmkrHg=="
|
||||
},
|
||||
"select": {
|
||||
"version": "1.1.2",
|
||||
@@ -441,20 +373,20 @@
|
||||
"integrity": "sha1-DnNQrN7ICxEIUoeG7B1EGNEbOW0=",
|
||||
"optional": true
|
||||
},
|
||||
"setimmediate": {
|
||||
"version": "1.0.5",
|
||||
"resolved": "https://registry.npmjs.org/setimmediate/-/setimmediate-1.0.5.tgz",
|
||||
"integrity": "sha1-KQy7Iy4waULX1+qbg3Mqt4VvgoU="
|
||||
},
|
||||
"shallowequal": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/shallowequal/-/shallowequal-1.1.0.tgz",
|
||||
"integrity": "sha512-y0m1JoUZSlPAjXVtPPW70aZWfIL/dSP7AFkRnniLCrK/8MDKog3TySTBmckD+RObVxH0v4Tox67+F14PdED2oQ=="
|
||||
},
|
||||
"slugify": {
|
||||
"version": "1.3.1",
|
||||
"resolved": "https://registry.npmjs.org/slugify/-/slugify-1.3.1.tgz",
|
||||
"integrity": "sha512-6BwyhjF5tG5P8s+0DPNyJmBSBePG6iMyhjvIW5zGdA3tFik9PtK+yNkZgTeiroCRGZYgkHftFA62tGVK1EI9Kw=="
|
||||
"version": "1.3.4",
|
||||
"resolved": "https://registry.npmjs.org/slugify/-/slugify-1.3.4.tgz",
|
||||
"integrity": "sha512-KP0ZYk5hJNBS8/eIjGkFDCzGQIoZ1mnfQRYS5WM3273z+fxGWXeN0fkwf2ebEweydv9tioZIHGZKoF21U07/nw=="
|
||||
},
|
||||
"source-map": {
|
||||
"version": "0.7.3",
|
||||
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.7.3.tgz",
|
||||
"integrity": "sha512-CkCj6giN3S+n9qrYiBTX5gystlENnRW5jZeNLHpe6aue+SrHcG5VYwujhW9s4dY31mEGsxBDrHR6oI69fTXsaQ=="
|
||||
},
|
||||
"sprintf-js": {
|
||||
"version": "1.0.3",
|
||||
@@ -466,44 +398,10 @@
|
||||
"resolved": "https://registry.npmjs.org/stickyfill/-/stickyfill-1.1.1.tgz",
|
||||
"integrity": "sha1-OUE/7p0CXHSn5ZzuyyN4TMDxfwI="
|
||||
},
|
||||
"styled-components": {
|
||||
"version": "3.4.6",
|
||||
"resolved": "https://registry.npmjs.org/styled-components/-/styled-components-3.4.6.tgz",
|
||||
"integrity": "sha512-HiEVVY93oH/PuekPuIE7ownn2wmO708rS8MM1yS20i0TCyFgPs3mbop8fJqKLRtC2/npVn2fO5Je6azaL6T2tg==",
|
||||
"requires": {
|
||||
"buffer": "^5.0.3",
|
||||
"css-to-react-native": "^2.0.3",
|
||||
"fbjs": "^0.8.16",
|
||||
"hoist-non-react-statics": "^2.5.0",
|
||||
"prop-types": "^15.5.4",
|
||||
"react-is": "^16.3.1",
|
||||
"stylis": "^3.5.0",
|
||||
"stylis-rule-sheet": "^0.0.10",
|
||||
"supports-color": "^3.2.3"
|
||||
}
|
||||
},
|
||||
"stylis": {
|
||||
"version": "3.5.3",
|
||||
"resolved": "https://registry.npmjs.org/stylis/-/stylis-3.5.3.tgz",
|
||||
"integrity": "sha512-TxU0aAscJghF9I3V9q601xcK3Uw1JbXvpsBGj/HULqexKOKlOEzzlIpLFRbKkCK990ccuxfXUqmPbIIo7Fq/cQ=="
|
||||
},
|
||||
"stylis-rule-sheet": {
|
||||
"version": "0.0.10",
|
||||
"resolved": "https://registry.npmjs.org/stylis-rule-sheet/-/stylis-rule-sheet-0.0.10.tgz",
|
||||
"integrity": "sha512-nTbZoaqoBnmK+ptANthb10ZRZOGC+EmTLLUxeYIuHNkEKcmKgXX1XWKkUBT2Ac4es3NybooPe0SmvKdhKJZAuw=="
|
||||
},
|
||||
"supports-color": {
|
||||
"version": "3.2.3",
|
||||
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-3.2.3.tgz",
|
||||
"integrity": "sha1-ZawFBLOVQXHYpklGsq48u4pfVPY=",
|
||||
"requires": {
|
||||
"has-flag": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"swagger-ui-dist": {
|
||||
"version": "3.18.2",
|
||||
"resolved": "https://registry.npmjs.org/swagger-ui-dist/-/swagger-ui-dist-3.18.2.tgz",
|
||||
"integrity": "sha512-pWAEiKkgWUJvjmLW9AojudnutJ+NTn5g6OdNLj1iIJWwCkoy40K3Upwa24DqFbmIE4vLX4XplND61hp2L+s5vg=="
|
||||
"version": "3.20.5",
|
||||
"resolved": "https://registry.npmjs.org/swagger-ui-dist/-/swagger-ui-dist-3.20.5.tgz",
|
||||
"integrity": "sha512-DNmJQ1qVkW8xk3wI2VfupOS7IYTHNjYaYX+L4s8B8ksdtoHOx3RsRqJUMIQByojHgb3PwEt+zGdIUwxJ4N5pwg=="
|
||||
},
|
||||
"tiny-emitter": {
|
||||
"version": "2.0.2",
|
||||
@@ -515,16 +413,6 @@
|
||||
"version": "1.9.3",
|
||||
"resolved": "https://registry.npmjs.org/tslib/-/tslib-1.9.3.tgz",
|
||||
"integrity": "sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ=="
|
||||
},
|
||||
"ua-parser-js": {
|
||||
"version": "0.7.18",
|
||||
"resolved": "https://registry.npmjs.org/ua-parser-js/-/ua-parser-js-0.7.18.tgz",
|
||||
"integrity": "sha512-LtzwHlVHwFGTptfNSgezHp7WUlwiqb0gA9AALRbKaERfxwJoiX0A73QbTToxteIAuIaFshhgIZfqK8s7clqgnA=="
|
||||
},
|
||||
"whatwg-fetch": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-3.0.0.tgz",
|
||||
"integrity": "sha512-9GSJUgz1D4MfyKU7KRqwOjXCXTqWdFNvEr7eUBYchQiVc744mqK/MzXPNR2WsPkmkOa4ywfg8C2n8h+13Bey1Q=="
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
{
|
||||
"name": "drf-yasg",
|
||||
"dependencies": {
|
||||
"redoc": "^2.0.0-alpha.38",
|
||||
"swagger-ui-dist": "^3.18.2"
|
||||
"redoc": "^2.0.0-rc.2",
|
||||
"swagger-ui-dist": "^3.20.5"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
[build-system]
|
||||
requires = ["setuptools >= 40.6.3", "wheel", "setuptools-scm >= 3.0.3"]
|
||||
build-backend = "setuptools.build_meta"
|
||||
+2
-1
@@ -1,3 +1,4 @@
|
||||
-r requirements/setup.txt
|
||||
# this file is only used when deploying to heroku, because heroku insists on having a root-level requirements.txt
|
||||
# for normal usage see the requirements/ directory
|
||||
.[validation]
|
||||
-r requirements/heroku.txt
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
Sphinx>=1.7.0
|
||||
sphinx_rtd_theme>=0.2.4
|
||||
Pillow>=4.3.0
|
||||
readme_renderer>=17.2
|
||||
readme_renderer[md]>=24.0
|
||||
twine>=1.12.1
|
||||
|
||||
Django>=2.0
|
||||
djangorestframework_camel_case>=0.2.0
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
# needed to build the package setup_requires in setup.py
|
||||
|
||||
setuptools-scm>=3.0.6
|
||||
@@ -1,9 +1,9 @@
|
||||
# requirements for running the tests via pytest
|
||||
pytest>=2.9,<3.7 # <3.7 because of incompatible pluggy requirement
|
||||
pytest>=4.0
|
||||
pytest-pythonpath>=0.7.1
|
||||
pytest-cov>=2.5.1
|
||||
pytest-xdist>=1.22.0
|
||||
pytest-django>=3.2.0
|
||||
pytest-cov>=2.6.0
|
||||
pytest-xdist>=1.25.0
|
||||
pytest-django>=3.4.4
|
||||
datadiff==2.0.0
|
||||
|
||||
-r testproj.txt
|
||||
|
||||
@@ -8,3 +8,5 @@ djangorestframework-camel-case>=0.2.0
|
||||
djangorestframework-recursive>=0.1.2
|
||||
dj-database-url>=0.4.2
|
||||
user_agents>=1.1.0
|
||||
# django-oauth-toolkit 1.2 does not support Django 1.11
|
||||
django-oauth-toolkit>=1.1.0,<1.2.0
|
||||
|
||||
@@ -1,4 +1,2 @@
|
||||
# requirements for building and running tox
|
||||
tox>=3.1.2
|
||||
|
||||
-r setup.txt
|
||||
tox>=3.3.0
|
||||
|
||||
@@ -1,3 +1,2 @@
|
||||
# requirements for the validation feature
|
||||
flex>=6.11.1
|
||||
swagger-spec-validator>=2.1.0
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
python-3.6.6
|
||||
python-3.7.1
|
||||
|
||||
@@ -17,7 +17,6 @@ with io.open('README.rst', encoding='utf-8') as readme:
|
||||
description = readme.read()
|
||||
|
||||
requirements = read_req('base.txt')
|
||||
requirements_setup = read_req('setup.txt')
|
||||
requirements_validation = read_req('validation.txt')
|
||||
|
||||
|
||||
@@ -28,7 +27,6 @@ def drf_yasg_setup(**kwargs):
|
||||
package_dir={'': 'src'},
|
||||
include_package_data=True,
|
||||
install_requires=requirements,
|
||||
setup_requires=requirements_setup,
|
||||
extras_require={
|
||||
'validation': requirements_validation,
|
||||
},
|
||||
@@ -67,21 +65,27 @@ def drf_yasg_setup(**kwargs):
|
||||
|
||||
|
||||
try:
|
||||
# noinspection PyUnresolvedReferences
|
||||
import setuptools_scm # noqa: F401
|
||||
|
||||
drf_yasg_setup(use_scm_version=True)
|
||||
except LookupError as e:
|
||||
except (ImportError, LookupError) as e:
|
||||
if os.getenv('CI', 'false') == 'true' or os.getenv('TRAVIS', 'false') == 'true':
|
||||
# don't silently fail on travis - we don't want to accidentally push a dummy version to PyPI
|
||||
raise
|
||||
|
||||
if 'setuptools-scm' in str(e):
|
||||
err_msg = str(e)
|
||||
if 'setuptools-scm' in err_msg or 'setuptools_scm' in err_msg:
|
||||
import time
|
||||
import traceback
|
||||
|
||||
timestamp_ms = int(time.time() * 1000)
|
||||
timestamp_str = hex(timestamp_ms)[2:].zfill(16)
|
||||
dummy_version = '0.0.0rc0+noscm' + timestamp_str
|
||||
dummy_version = '1!0.0.0.dev0+noscm.' + timestamp_str
|
||||
|
||||
drf_yasg_setup(version=dummy_version)
|
||||
print(str(e), file=sys.stderr)
|
||||
print("failed to detect version, build was done using dummy version " + dummy_version, file=sys.stderr)
|
||||
|
||||
traceback.print_exc(file=sys.stderr)
|
||||
print("failed to detect version, package was built with dummy version " + dummy_version, file=sys.stderr)
|
||||
else:
|
||||
raise
|
||||
|
||||
@@ -33,7 +33,7 @@ SWAGGER_DEFAULTS = {
|
||||
|
||||
'USE_SESSION_AUTH': True,
|
||||
'SECURITY_DEFINITIONS': {
|
||||
'basic': {
|
||||
'Basic': {
|
||||
'type': 'basic'
|
||||
}
|
||||
},
|
||||
@@ -42,6 +42,10 @@ SWAGGER_DEFAULTS = {
|
||||
'LOGOUT_URL': getattr(settings, 'LOGOUT_URL', None),
|
||||
'SPEC_URL': None,
|
||||
'VALIDATOR_URL': '',
|
||||
'PERSIST_AUTH': False,
|
||||
'REFETCH_SCHEMA_WITH_AUTH': False,
|
||||
'REFETCH_SCHEMA_ON_LOGOUT': False,
|
||||
'FETCH_SCHEMA_WITH_QUERY': True,
|
||||
|
||||
'OPERATIONS_SORTER': None,
|
||||
'TAGS_SORTER': None,
|
||||
@@ -74,6 +78,7 @@ REDOC_DEFAULTS = {
|
||||
'PATH_IN_MIDDLE': False,
|
||||
'NATIVE_SCROLLBARS': False,
|
||||
'REQUIRED_PROPS_FIRST': False,
|
||||
'FETCH_SCHEMA_WITH_QUERY': True,
|
||||
}
|
||||
|
||||
IMPORT_STRINGS = [
|
||||
|
||||
+44
-16
@@ -2,6 +2,7 @@ from six import raise_from
|
||||
|
||||
import copy
|
||||
import json
|
||||
import logging
|
||||
from collections import OrderedDict
|
||||
|
||||
from coreapi.compat import force_bytes
|
||||
@@ -10,10 +11,16 @@ from ruamel import yaml
|
||||
from . import openapi
|
||||
from .errors import SwaggerValidationError
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def _validate_flex(spec):
|
||||
from flex.core import parse as validate_flex
|
||||
from flex.exceptions import ValidationError
|
||||
try:
|
||||
from flex.core import parse as validate_flex
|
||||
from flex.exceptions import ValidationError
|
||||
except ImportError:
|
||||
return
|
||||
|
||||
try:
|
||||
validate_flex(spec)
|
||||
except ValidationError as ex:
|
||||
@@ -70,7 +77,10 @@ class _OpenAPICodec(object):
|
||||
errors[validator] = str(e)
|
||||
|
||||
if errors:
|
||||
raise SwaggerValidationError("spec validation failed", errors, spec, self)
|
||||
exc = SwaggerValidationError("spec validation failed: {}".format(errors), errors, spec, self)
|
||||
logger.warning(str(exc))
|
||||
raise exc
|
||||
|
||||
return force_bytes(self._dump_dict(spec))
|
||||
|
||||
def encode_error(self, err):
|
||||
@@ -82,7 +92,7 @@ class _OpenAPICodec(object):
|
||||
|
||||
:param dict spec: a python dict
|
||||
:return: string representation of ``spec``
|
||||
:rtype: str
|
||||
:rtype: str or bytes
|
||||
"""
|
||||
raise NotImplementedError("override this method")
|
||||
|
||||
@@ -99,9 +109,22 @@ class _OpenAPICodec(object):
|
||||
class OpenAPICodecJson(_OpenAPICodec):
|
||||
media_type = 'application/json'
|
||||
|
||||
def __init__(self, validators, pretty=False, media_type='application/json'):
|
||||
super(OpenAPICodecJson, self).__init__(validators)
|
||||
self.pretty = pretty
|
||||
self.media_type = media_type
|
||||
|
||||
def _dump_dict(self, spec):
|
||||
"""Dump ``spec`` into JSON."""
|
||||
return json.dumps(spec)
|
||||
"""Dump ``spec`` into JSON.
|
||||
|
||||
:rtype: str"""
|
||||
if self.pretty:
|
||||
out = json.dumps(spec, indent=4, separators=(',', ': '))
|
||||
if out[-1] != '\n':
|
||||
out += '\n'
|
||||
return out
|
||||
else:
|
||||
return json.dumps(spec)
|
||||
|
||||
|
||||
YAML_MAP_TAG = u'tag:yaml.org,2002:map'
|
||||
@@ -121,8 +144,7 @@ class SaneYamlDumper(yaml.SafeDumper):
|
||||
"""
|
||||
return super(SaneYamlDumper, self).increase_indent(flow=flow, indentless=False, **kwargs)
|
||||
|
||||
@staticmethod
|
||||
def represent_odict(dump, mapping, flow_style=None): # pragma: no cover
|
||||
def represent_odict(self, mapping, flow_style=None): # pragma: no cover
|
||||
"""https://gist.github.com/miracle2k/3184458
|
||||
|
||||
Make PyYAML output an OrderedDict.
|
||||
@@ -134,22 +156,22 @@ class SaneYamlDumper(yaml.SafeDumper):
|
||||
tag = YAML_MAP_TAG
|
||||
value = []
|
||||
node = yaml.MappingNode(tag, value, flow_style=flow_style)
|
||||
if dump.alias_key is not None:
|
||||
dump.represented_objects[dump.alias_key] = node
|
||||
if self.alias_key is not None:
|
||||
self.represented_objects[self.alias_key] = node
|
||||
best_style = True
|
||||
if hasattr(mapping, 'items'):
|
||||
mapping = mapping.items()
|
||||
for item_key, item_value in mapping:
|
||||
node_key = dump.represent_data(item_key)
|
||||
node_value = dump.represent_data(item_value)
|
||||
node_key = self.represent_data(item_key)
|
||||
node_value = self.represent_data(item_value)
|
||||
if not (isinstance(node_key, yaml.ScalarNode) and not node_key.style):
|
||||
best_style = False
|
||||
if not (isinstance(node_value, yaml.ScalarNode) and not node_value.style):
|
||||
best_style = False
|
||||
value.append((node_key, node_value))
|
||||
if flow_style is None:
|
||||
if dump.default_flow_style is not None:
|
||||
node.flow_style = dump.default_flow_style
|
||||
if self.default_flow_style is not None:
|
||||
node.flow_style = self.default_flow_style
|
||||
else:
|
||||
node.flow_style = best_style
|
||||
return node
|
||||
@@ -170,7 +192,7 @@ def yaml_sane_dump(data, binary):
|
||||
:param dict data: the data to be dumped
|
||||
:param bool binary: True to return a utf-8 encoded binary object, False to return a string
|
||||
:return: the serialized YAML
|
||||
:rtype: str,bytes
|
||||
:rtype: str or bytes
|
||||
"""
|
||||
return yaml.dump(data, Dumper=SaneYamlDumper, default_flow_style=False, encoding='utf-8' if binary else None)
|
||||
|
||||
@@ -196,6 +218,12 @@ def yaml_sane_load(stream):
|
||||
class OpenAPICodecYaml(_OpenAPICodec):
|
||||
media_type = 'application/yaml'
|
||||
|
||||
def __init__(self, validators, media_type='application/yaml'):
|
||||
super(OpenAPICodecYaml, self).__init__(validators)
|
||||
self.media_type = media_type
|
||||
|
||||
def _dump_dict(self, spec):
|
||||
"""Dump ``spec`` into YAML."""
|
||||
"""Dump ``spec`` into YAML.
|
||||
|
||||
:rtype: bytes"""
|
||||
return yaml_sane_dump(spec, binary=True)
|
||||
|
||||
+69
-25
@@ -8,15 +8,15 @@ from coreapi.compat import urlparse
|
||||
from rest_framework import versioning
|
||||
from rest_framework.compat import URLPattern, URLResolver, get_original_route
|
||||
from rest_framework.schemas.generators import EndpointEnumerator as _EndpointEnumerator
|
||||
from rest_framework.schemas.generators import SchemaGenerator, endpoint_ordering
|
||||
from rest_framework.schemas.generators import SchemaGenerator, endpoint_ordering, get_pk_name
|
||||
from rest_framework.schemas.inspectors import get_pk_description
|
||||
from rest_framework.settings import api_settings as rest_framework_settings
|
||||
from rest_framework.settings import api_settings
|
||||
|
||||
from . import openapi
|
||||
from .app_settings import swagger_settings
|
||||
from .errors import SwaggerGenerationError
|
||||
from .inspectors.field import get_basic_type_info, get_queryset_field, get_queryset_from_view
|
||||
from .openapi import ReferenceResolver
|
||||
from .openapi import ReferenceResolver, SwaggerDict
|
||||
from .utils import force_real_str, get_consumes, get_produces
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -132,7 +132,7 @@ class EndpointEnumerator(_EndpointEnumerator):
|
||||
|
||||
def unescape_path(self, path):
|
||||
"""Remove backslashe escapes from all path components outside {parameters}. This is needed because
|
||||
``simplify_regex`` does not handle this correctly - note however that this implementation is
|
||||
``simplify_regex`` does not handle this correctly.
|
||||
|
||||
**NOTE:** this might destructively affect some url regex patterns that contain metacharacters (e.g. \\w, \\d)
|
||||
outside path parameter groups; if you are in this category, God help you
|
||||
@@ -164,7 +164,7 @@ class OpenAPISchemaGenerator(object):
|
||||
def __init__(self, info, version='', url=None, patterns=None, urlconf=None):
|
||||
"""
|
||||
|
||||
:param .Info info: information about the API
|
||||
:param openapi.Info info: information about the API
|
||||
:param str version: API version string; if omitted, `info.default_version` will be used
|
||||
:param str url: API scheme, host and port; if ``None`` is passed and ``DEFAULT_API_URL`` is not set, the url
|
||||
will be inferred from the request made against the schema view, so you should generally not need to set
|
||||
@@ -198,11 +198,40 @@ class OpenAPISchemaGenerator(object):
|
||||
def url(self):
|
||||
return self._gen.url
|
||||
|
||||
def get_security_definitions(self):
|
||||
"""Get the security schemes for this API. This determines what is usable in security requirements,
|
||||
and helps clients configure their authorization credentials.
|
||||
|
||||
:return: the security schemes usable with this API
|
||||
:rtype: dict[str,dict] or None
|
||||
"""
|
||||
security_definitions = swagger_settings.SECURITY_DEFINITIONS
|
||||
if security_definitions is not None:
|
||||
security_definitions = SwaggerDict._as_odict(security_definitions, {})
|
||||
|
||||
return security_definitions
|
||||
|
||||
def get_security_requirements(self, security_definitions):
|
||||
"""Get the base (global) security requirements of the API. This is never called if
|
||||
:meth:`.get_security_definitions` returns `None`.
|
||||
|
||||
:param security_definitions: security definitions as returned by :meth:`.get_security_definitions`
|
||||
:return: the security schemes accepted by default
|
||||
:rtype: list[dict[str,list[str]]] or None
|
||||
"""
|
||||
security_requirements = swagger_settings.SECURITY_REQUIREMENTS
|
||||
if security_requirements is None:
|
||||
security_requirements = [{security_scheme: []} for security_scheme in security_definitions]
|
||||
|
||||
security_requirements = [SwaggerDict._as_odict(sr, {}) for sr in security_requirements]
|
||||
security_requirements = sorted(security_requirements, key=list)
|
||||
return security_requirements
|
||||
|
||||
def get_schema(self, request=None, public=False):
|
||||
"""Generate a :class:`.Swagger` object representing the API schema.
|
||||
|
||||
:param Request request: the request used for filtering
|
||||
accesible endpoints and finding the spec URI
|
||||
:param request: the request used for filtering accessible endpoints and finding the spec URI
|
||||
:type request: rest_framework.request.Request or None
|
||||
:param bool public: if True, all endpoints are included regardless of access through `request`
|
||||
|
||||
:return: the generated Swagger specification
|
||||
@@ -210,20 +239,15 @@ class OpenAPISchemaGenerator(object):
|
||||
"""
|
||||
endpoints = self.get_endpoints(request)
|
||||
components = ReferenceResolver(openapi.SCHEMA_DEFINITIONS)
|
||||
self.consumes = get_consumes(rest_framework_settings.DEFAULT_PARSER_CLASSES)
|
||||
self.produces = get_produces(rest_framework_settings.DEFAULT_RENDERER_CLASSES)
|
||||
self.consumes = get_consumes(api_settings.DEFAULT_PARSER_CLASSES)
|
||||
self.produces = get_produces(api_settings.DEFAULT_RENDERER_CLASSES)
|
||||
paths, prefix = self.get_paths(endpoints, components, request, public)
|
||||
|
||||
security_definitions = swagger_settings.SECURITY_DEFINITIONS
|
||||
if security_definitions is not None:
|
||||
security_definitions = OrderedDict(sorted([(key, OrderedDict(sorted(sd.items())))
|
||||
for key, sd in swagger_settings.SECURITY_DEFINITIONS.items()]))
|
||||
security_requirements = swagger_settings.SECURITY_REQUIREMENTS
|
||||
if security_requirements is None:
|
||||
security_requirements = [{security_scheme: []} for security_scheme in swagger_settings.SECURITY_DEFINITIONS]
|
||||
|
||||
security_requirements = sorted(security_requirements, key=lambda od: list(sorted(od)))
|
||||
security_requirements = [OrderedDict(sorted(sr.items())) for sr in security_requirements]
|
||||
security_definitions = self.get_security_definitions()
|
||||
if security_definitions:
|
||||
security_requirements = self.get_security_requirements(security_definitions)
|
||||
else:
|
||||
security_requirements = None
|
||||
|
||||
url = self.url
|
||||
if url is None and request is not None:
|
||||
@@ -238,9 +262,10 @@ class OpenAPISchemaGenerator(object):
|
||||
def create_view(self, callback, method, request=None):
|
||||
"""Create a view instance from a view callback as registered in urlpatterns.
|
||||
|
||||
:param callable callback: view callback registered in urlpatterns
|
||||
:param callback: view callback registered in urlpatterns
|
||||
:param str method: HTTP method
|
||||
:param rest_framework.request.Request request: request to bind to the view
|
||||
:param request: request to bind to the view
|
||||
:type request: rest_framework.request.Request or None
|
||||
:return: the view instance
|
||||
"""
|
||||
view = self._gen.create_view(callback, method, request)
|
||||
@@ -255,12 +280,31 @@ class OpenAPISchemaGenerator(object):
|
||||
setattr(view, 'swagger_fake_view', True)
|
||||
return view
|
||||
|
||||
def coerce_path(self, path, view):
|
||||
"""Coerce {pk} path arguments into the name of the model field, where possible. This is cleaner for an
|
||||
external representation (i.e. "this is an identifier", not "this is a database primary key").
|
||||
|
||||
:param str path: the path
|
||||
:param rest_framework.views.APIView view: associated view
|
||||
:rtype: str
|
||||
"""
|
||||
if '{pk}' not in path:
|
||||
return path
|
||||
|
||||
model = getattr(get_queryset_from_view(view), 'model', None)
|
||||
if model:
|
||||
field_name = get_pk_name(model)
|
||||
else:
|
||||
field_name = 'id'
|
||||
return path.replace('{pk}', '{%s}' % field_name)
|
||||
|
||||
def get_endpoints(self, request):
|
||||
"""Iterate over all the registered endpoints in the API and return a fake view with the right parameters.
|
||||
|
||||
:param rest_framework.request.Request request: request to bind to the endpoint views
|
||||
:param request: request to bind to the endpoint views
|
||||
:type request: rest_framework.request.Request or None
|
||||
:return: {path: (view_class, list[(http_method, view_instance)])
|
||||
:rtype: dict
|
||||
:rtype: dict[str,(type,list[(str,rest_framework.views.APIView)])]
|
||||
"""
|
||||
enumerator = self.endpoint_enumerator_class(self._gen.patterns, self._gen.urlconf, request=request)
|
||||
endpoints = enumerator.get_api_endpoints()
|
||||
@@ -269,7 +313,7 @@ class OpenAPISchemaGenerator(object):
|
||||
view_cls = {}
|
||||
for path, method, callback in endpoints:
|
||||
view = self.create_view(callback, method, request)
|
||||
path = self._gen.coerce_path(path, method, view)
|
||||
path = self.coerce_path(path, view)
|
||||
view_paths[path].append((method, view))
|
||||
view_cls[path] = callback.cls
|
||||
return {path: (view_cls[path], methods) for path, methods in view_paths.items()}
|
||||
@@ -287,7 +331,7 @@ class OpenAPISchemaGenerator(object):
|
||||
:param str subpath: path to the operation with any common prefix/base path removed
|
||||
:param str method: HTTP method
|
||||
:param view: the view associated with the operation
|
||||
:rtype: tuple
|
||||
:rtype: list[str]
|
||||
"""
|
||||
return self._gen.get_keys(subpath, method, view)
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import logging
|
||||
from rest_framework import serializers
|
||||
|
||||
from .. import openapi
|
||||
from ..utils import force_real_str, get_field_default, is_list_view
|
||||
from ..utils import force_real_str, get_field_default, get_object_classes, is_list_view
|
||||
|
||||
#: Sentinel value that inspectors must return to signal that they do not know how to handle an object
|
||||
NotHandled = object()
|
||||
@@ -12,14 +12,61 @@ NotHandled = object()
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def is_callable_method(cls_or_instance, method_name):
|
||||
method = getattr(cls_or_instance, method_name)
|
||||
if inspect.ismethod(method) and getattr(method, '__self__', None):
|
||||
# bound classmethod or instance method
|
||||
return method, True
|
||||
|
||||
try:
|
||||
# inspect.getattr_static was added in python 3.2
|
||||
from inspect import getattr_static
|
||||
|
||||
# on python 3, both unbound instance methods (i.e. getattr(cls, mth)) and static methods are plain functions
|
||||
# getattr_static allows us to check the type of the method descriptor; for `@staticmethod` this is staticmethod
|
||||
return method, isinstance(getattr_static(cls_or_instance, method_name, None), staticmethod)
|
||||
except ImportError:
|
||||
# python 2 still has unbound methods, so ismethod <=> !staticmethod TODO: remove when dropping python 2.7
|
||||
return method, not inspect.ismethod(method)
|
||||
|
||||
|
||||
def call_view_method(view, method_name, fallback_attr=None, default=None):
|
||||
"""Call a view method which might throw an exception. If an exception is thrown, log an informative error message
|
||||
and return the value of fallback_attr, or default if not present. The method must be callable without any arguments
|
||||
except cls or self.
|
||||
|
||||
:param view: view class or instance; if a class is passed, instance methods won't be called
|
||||
:type view: rest_framework.views.APIView or type[rest_framework.views.APIView]
|
||||
:param str method_name: name of a method on the view
|
||||
:param str fallback_attr: name of an attribute on the view to fall back on, if calling the method fails
|
||||
:param default: default value if all else fails
|
||||
:return: view method's return value, or value of view's fallback_attr, or default
|
||||
:rtype: any or None
|
||||
"""
|
||||
if hasattr(view, method_name):
|
||||
try:
|
||||
view_method, is_callabale = is_callable_method(view, method_name)
|
||||
if is_callabale:
|
||||
return view_method()
|
||||
except Exception: # pragma: no cover
|
||||
logger.warning("view's %s raised exception during schema generation; use "
|
||||
"`getattr(self, 'swagger_fake_view', False)` to detect and short-circuit this",
|
||||
type(view).__name__, exc_info=True)
|
||||
|
||||
if fallback_attr and hasattr(view, fallback_attr):
|
||||
return getattr(view, fallback_attr)
|
||||
|
||||
return default
|
||||
|
||||
|
||||
class BaseInspector(object):
|
||||
def __init__(self, view, path, method, components, request):
|
||||
"""
|
||||
:param view: the view associated with this endpoint
|
||||
:param rest_framework.views.APIView view: the view associated with this endpoint
|
||||
:param str path: the path component of the operation URL
|
||||
:param str method: the http method of the operation
|
||||
:param openapi.ReferenceResolver components: referenceable components
|
||||
:param Request request: the request made against the schema view; can be None
|
||||
:param rest_framework.request.Request request: the request made against the schema view; can be None
|
||||
"""
|
||||
self.view = view
|
||||
self.path = path
|
||||
@@ -81,6 +128,22 @@ class BaseInspector(object):
|
||||
|
||||
return result
|
||||
|
||||
def get_renderer_classes(self):
|
||||
"""Get the renderer classes of this view by calling `get_renderers`.
|
||||
|
||||
:return: renderer classes
|
||||
:rtype: list[type[rest_framework.renderers.BaseRenderer]]
|
||||
"""
|
||||
return get_object_classes(call_view_method(self.view, 'get_renderers', 'renderer_classes', []))
|
||||
|
||||
def get_parser_classes(self):
|
||||
"""Get the parser classes of this view by calling `get_parsers`.
|
||||
|
||||
:return: parser classes
|
||||
:rtype: list[type[rest_framework.parsers.BaseParser]]
|
||||
"""
|
||||
return get_object_classes(call_view_method(self.view, 'get_parsers', 'parser_classes', []))
|
||||
|
||||
|
||||
class PaginatorInspector(BaseInspector):
|
||||
"""Base inspector for paginators.
|
||||
@@ -159,7 +222,7 @@ class FieldInspector(BaseInspector):
|
||||
:param kwargs: extra attributes for constructing the object;
|
||||
if swagger_object_type is Parameter, ``name`` and ``in_`` should be provided
|
||||
:return: the swagger object
|
||||
:rtype: openapi.Parameter,openapi.Items,openapi.Schema,openapi.SchemaRef
|
||||
:rtype: openapi.Parameter or openapi.Items or openapi.Schema or openapi.SchemaRef
|
||||
"""
|
||||
return NotHandled
|
||||
|
||||
@@ -168,7 +231,7 @@ class FieldInspector(BaseInspector):
|
||||
|
||||
All arguments are the same as :meth:`.field_to_swagger_object`.
|
||||
|
||||
:rtype: openapi.Parameter,openapi.Items,openapi.Schema,openapi.SchemaRef
|
||||
:rtype: openapi.Parameter or openapi.Items or openapi.Schema or openapi.SchemaRef
|
||||
"""
|
||||
return self.probe_inspectors(
|
||||
self.field_inspectors, 'field_to_swagger_object', field, {'field_inspectors': self.field_inspectors},
|
||||
@@ -192,7 +255,7 @@ class FieldInspector(BaseInspector):
|
||||
|
||||
- arguments specified by the ``kwargs`` parameter of :meth:`._get_partial_types`
|
||||
- ``instance_kwargs`` passed to the constructor function
|
||||
- ``title``, ``description``, ``required`` and ``default`` inferred from the field,
|
||||
- ``title``, ``description``, ``required``, ``x-nullable`` and ``default`` inferred from the field,
|
||||
where appropriate
|
||||
|
||||
If ``existing_object`` is not ``None``, it is updated instead of creating a new object.
|
||||
@@ -203,7 +266,7 @@ class FieldInspector(BaseInspector):
|
||||
- :class:`.Schema` if `swagger_object_type` is :class:`.Schema`
|
||||
- :class:`.Items` if `swagger_object_type` is :class:`.Parameter` or :class:`.Items`
|
||||
|
||||
:rtype: tuple[callable,(type[openapi.Schema],type[openapi.Items])]
|
||||
:rtype: (function,type[openapi.Schema] or type[openapi.Items])
|
||||
"""
|
||||
assert swagger_object_type in (openapi.Schema, openapi.Parameter, openapi.Items)
|
||||
assert not isinstance(field, openapi.SwaggerDict), "passed field is already a SwaggerDict object"
|
||||
@@ -225,6 +288,9 @@ class FieldInspector(BaseInspector):
|
||||
instance_kwargs.setdefault('title', title)
|
||||
if description is not None:
|
||||
instance_kwargs.setdefault('description', description)
|
||||
if field.allow_null and not instance_kwargs.get('required', False) and not field.required:
|
||||
instance_kwargs['x_nullable'] = True
|
||||
|
||||
instance_kwargs.update(kwargs)
|
||||
|
||||
if existing_object is not None:
|
||||
@@ -332,7 +398,7 @@ class ViewInspector(BaseInspector):
|
||||
return []
|
||||
|
||||
fields = []
|
||||
for filter_backend in self.view.filter_backends:
|
||||
for filter_backend in getattr(self.view, 'filter_backends'):
|
||||
fields += self.probe_inspectors(self.filter_inspectors, 'get_filter_parameters', filter_backend()) or []
|
||||
|
||||
return fields
|
||||
@@ -358,14 +424,15 @@ class ViewInspector(BaseInspector):
|
||||
if not self.should_page():
|
||||
return []
|
||||
|
||||
return self.probe_inspectors(self.paginator_inspectors, 'get_paginator_parameters', self.view.paginator) or []
|
||||
return self.probe_inspectors(self.paginator_inspectors, 'get_paginator_parameters',
|
||||
getattr(self.view, 'paginator')) or []
|
||||
|
||||
def serializer_to_schema(self, serializer):
|
||||
"""Convert a serializer to an OpenAPI :class:`.Schema`.
|
||||
|
||||
:param serializers.BaseSerializer serializer: the ``Serializer`` instance
|
||||
:returns: the converted :class:`.Schema`, or ``None`` in case of an unknown serializer
|
||||
:rtype: openapi.Schema,openapi.SchemaRef
|
||||
:rtype: openapi.Schema or openapi.SchemaRef
|
||||
"""
|
||||
return self.probe_inspectors(
|
||||
self.field_inspectors, 'get_schema', serializer, {'field_inspectors': self.field_inspectors}
|
||||
@@ -391,4 +458,4 @@ class ViewInspector(BaseInspector):
|
||||
:rtype: openapi.Schema
|
||||
"""
|
||||
return self.probe_inspectors(self.paginator_inspectors, 'get_paginated_response',
|
||||
self.view.paginator, response_schema=response_schema)
|
||||
getattr(self.view, 'paginator'), response_schema=response_schema)
|
||||
|
||||
@@ -5,7 +5,6 @@ import operator
|
||||
import uuid
|
||||
from collections import OrderedDict
|
||||
from decimal import Decimal
|
||||
from inspect import isclass
|
||||
|
||||
from django.core import validators
|
||||
from django.db import models
|
||||
@@ -15,14 +14,18 @@ from rest_framework.settings import api_settings as rest_framework_settings
|
||||
from .. import openapi
|
||||
from ..errors import SwaggerGenerationError
|
||||
from ..utils import decimal_as_float, filter_none, get_serializer_class, get_serializer_ref_name
|
||||
from .base import FieldInspector, NotHandled, SerializerInspector
|
||||
from .base import FieldInspector, NotHandled, SerializerInspector, call_view_method
|
||||
|
||||
try:
|
||||
# Python>=3.5
|
||||
import typing
|
||||
except ImportError:
|
||||
typing = None
|
||||
|
||||
try:
|
||||
from inspect import signature as inspect_signature
|
||||
except ImportError:
|
||||
inspect_signature = None
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -55,6 +58,7 @@ class InlineSerializerInspector(SerializerInspector):
|
||||
)
|
||||
for key, value
|
||||
in fields.items()
|
||||
if not getattr(value, 'read_only', False)
|
||||
]
|
||||
|
||||
return self.add_manual_parameters(serializer, parameters)
|
||||
@@ -83,10 +87,10 @@ class InlineSerializerInspector(SerializerInspector):
|
||||
|
||||
ref_name = self.get_serializer_ref_name(field)
|
||||
|
||||
def make_schema_definition():
|
||||
def make_schema_definition(serializer=field):
|
||||
properties = OrderedDict()
|
||||
required = []
|
||||
for property_name, child in field.fields.items():
|
||||
for property_name, child in serializer.fields.items():
|
||||
property_name = self.get_property_name(property_name)
|
||||
prop_kwargs = {
|
||||
'read_only': bool(child.read_only) or None
|
||||
@@ -173,11 +177,11 @@ def get_queryset_from_view(view, serializer=None):
|
||||
:return: queryset or ``None``
|
||||
"""
|
||||
try:
|
||||
queryset = getattr(view, 'queryset', None)
|
||||
queryset = call_view_method(view, 'get_queryset', 'queryset')
|
||||
|
||||
if queryset is not None and serializer is not None:
|
||||
# make sure the view is actually using *this* serializer
|
||||
assert type(serializer) == view.get_serializer_class()
|
||||
assert type(serializer) == call_view_method(view, 'get_serializer_class', 'serializer_class')
|
||||
|
||||
return queryset
|
||||
except Exception: # pragma: no cover
|
||||
@@ -319,8 +323,8 @@ limit_validators = [
|
||||
(validators.MaxLengthValidator, serializers.CharField, 'max_length', operator.__lt__),
|
||||
|
||||
# minItems and maxItems apply to lists
|
||||
(validators.MinLengthValidator, serializers.ListField, 'min_items', operator.__gt__),
|
||||
(validators.MaxLengthValidator, serializers.ListField, 'max_items', operator.__lt__),
|
||||
(validators.MinLengthValidator, (serializers.ListField, serializers.ListSerializer), 'min_items', operator.__gt__),
|
||||
(validators.MaxLengthValidator, (serializers.ListField, serializers.ListSerializer), 'max_items', operator.__lt__),
|
||||
]
|
||||
|
||||
|
||||
@@ -451,18 +455,39 @@ def decimal_return_type():
|
||||
return openapi.TYPE_STRING if rest_framework_settings.COERCE_DECIMAL_TO_STRING else openapi.TYPE_NUMBER
|
||||
|
||||
|
||||
raw_type_info = [
|
||||
def get_origin_type(hint_class):
|
||||
return getattr(hint_class, '__origin__', None) or hint_class
|
||||
|
||||
|
||||
def hint_class_issubclass(hint_class, check_class):
|
||||
origin_type = get_origin_type(hint_class)
|
||||
return inspect.isclass(origin_type) and issubclass(origin_type, check_class)
|
||||
|
||||
|
||||
hinting_type_info = [
|
||||
(bool, (openapi.TYPE_BOOLEAN, None)),
|
||||
(int, (openapi.TYPE_INTEGER, None)),
|
||||
(str, (openapi.TYPE_STRING, None)),
|
||||
(float, (openapi.TYPE_NUMBER, None)),
|
||||
(dict, (openapi.TYPE_OBJECT, None)),
|
||||
(Decimal, (decimal_return_type, openapi.FORMAT_DECIMAL)),
|
||||
(uuid.UUID, (openapi.TYPE_STRING, openapi.FORMAT_UUID)),
|
||||
(datetime.datetime, (openapi.TYPE_STRING, openapi.FORMAT_DATETIME)),
|
||||
(datetime.date, (openapi.TYPE_STRING, openapi.FORMAT_DATE)),
|
||||
# TODO - support typing.List etc
|
||||
]
|
||||
|
||||
hinting_type_info = raw_type_info
|
||||
if typing:
|
||||
def inspect_collection_hint_class(hint_class):
|
||||
args = hint_class.__args__
|
||||
child_class = args[0] if args else str
|
||||
child_type_info = get_basic_type_info_from_hint(child_class) or {'type': openapi.TYPE_STRING}
|
||||
|
||||
return OrderedDict([
|
||||
('type', openapi.TYPE_ARRAY),
|
||||
('items', openapi.Items(**child_type_info)),
|
||||
])
|
||||
|
||||
hinting_type_info.append(((typing.Sequence, typing.AbstractSet), inspect_collection_hint_class))
|
||||
|
||||
|
||||
def get_basic_type_info_from_hint(hint_class):
|
||||
@@ -474,27 +499,31 @@ def get_basic_type_info_from_hint(hint_class):
|
||||
:return: the extracted attributes as a dictionary, or ``None`` if the field type is not known
|
||||
:rtype: OrderedDict
|
||||
"""
|
||||
if typing and get_origin_type(hint_class) == typing.Union:
|
||||
# Optional is implemented as Union[T, None]
|
||||
if len(hint_class.__args__) == 2 and hint_class.__args__[1] == type(None): # noqa: E721
|
||||
child_type = hint_class.__args__[0]
|
||||
result = get_basic_type_info_from_hint(child_type)
|
||||
result['x-nullable'] = True
|
||||
return result
|
||||
|
||||
for check_class, type_format in hinting_type_info:
|
||||
if issubclass(hint_class, check_class):
|
||||
swagger_type, format = type_format
|
||||
if callable(swagger_type):
|
||||
swagger_type = swagger_type()
|
||||
# if callable(format):
|
||||
# format = format(klass)
|
||||
break
|
||||
else: # pragma: no cover
|
||||
return None
|
||||
|
||||
pattern = None
|
||||
for check_class, info in hinting_type_info:
|
||||
if hint_class_issubclass(hint_class, check_class):
|
||||
if callable(info):
|
||||
return info(hint_class)
|
||||
|
||||
result = OrderedDict([
|
||||
('type', swagger_type),
|
||||
('format', format),
|
||||
('pattern', pattern)
|
||||
])
|
||||
swagger_type, format = info
|
||||
if callable(swagger_type):
|
||||
swagger_type = swagger_type()
|
||||
|
||||
return result
|
||||
return OrderedDict([
|
||||
('type', swagger_type),
|
||||
('format', format),
|
||||
])
|
||||
|
||||
return None
|
||||
|
||||
|
||||
class SerializerMethodFieldInspector(FieldInspector):
|
||||
@@ -510,12 +539,10 @@ class SerializerMethodFieldInspector(FieldInspector):
|
||||
if method is None:
|
||||
return NotHandled
|
||||
|
||||
# attribute added by the swagger_serializer_method decorator
|
||||
serializer = getattr(method, "_swagger_serializer", None)
|
||||
|
||||
if serializer:
|
||||
# attribute added by the swagger_serializer_method decorator
|
||||
serializer = getattr(method, '_swagger_serializer', None)
|
||||
|
||||
# in order of preference for description, use:
|
||||
# 1) field.help_text from SerializerMethodField(help_text)
|
||||
# 2) serializer.help_text from swagger_serializer_method(serializer)
|
||||
@@ -544,13 +571,13 @@ class SerializerMethodFieldInspector(FieldInspector):
|
||||
serializer.read_only = True
|
||||
|
||||
return self.probe_field_inspectors(serializer, swagger_object_type, use_references, read_only=True)
|
||||
elif typing:
|
||||
elif typing and inspect_signature:
|
||||
# look for Python 3.5+ style type hinting of the return value
|
||||
hint_class = inspect.signature(method).return_annotation
|
||||
hint_class = inspect_signature(method).return_annotation
|
||||
|
||||
if not isclass(hint_class) and hasattr(hint_class, '__args__'):
|
||||
if not inspect.isclass(hint_class) and hasattr(hint_class, '__args__'):
|
||||
hint_class = hint_class.__args__[0]
|
||||
if isclass(hint_class) and not issubclass(hint_class, inspect._empty):
|
||||
if inspect.isclass(hint_class) and not issubclass(hint_class, inspect._empty):
|
||||
type_info = get_basic_type_info_from_hint(hint_class)
|
||||
|
||||
if type_info is not None:
|
||||
@@ -583,6 +610,7 @@ class ChoiceFieldInspector(FieldInspector):
|
||||
|
||||
if isinstance(field, serializers.ChoiceField):
|
||||
enum_type = openapi.TYPE_STRING
|
||||
enum_values = list(field.choices.keys())
|
||||
|
||||
# for ModelSerializer, try to infer the type from the associated model field
|
||||
serializer = get_parent_serializer(field)
|
||||
@@ -593,17 +621,29 @@ class ChoiceFieldInspector(FieldInspector):
|
||||
model_type = get_basic_type_info(model_field)
|
||||
if model_type:
|
||||
enum_type = model_type.get('type', enum_type)
|
||||
else:
|
||||
# Try to infer field type based on enum values
|
||||
enum_value_types = {type(v) for v in enum_values}
|
||||
if len(enum_value_types) == 1:
|
||||
values_type = get_basic_type_info_from_hint(next(iter(enum_value_types)))
|
||||
if values_type:
|
||||
enum_type = values_type.get('type', enum_type)
|
||||
|
||||
if isinstance(field, serializers.MultipleChoiceField):
|
||||
return SwaggerType(
|
||||
result = SwaggerType(
|
||||
type=openapi.TYPE_ARRAY,
|
||||
items=ChildSwaggerType(
|
||||
type=enum_type,
|
||||
enum=list(field.choices.keys())
|
||||
enum=enum_values
|
||||
)
|
||||
)
|
||||
if swagger_object_type == openapi.Parameter:
|
||||
if result['in'] in (openapi.IN_FORM, openapi.IN_QUERY):
|
||||
result.collection_format = 'multi'
|
||||
else:
|
||||
result = SwaggerType(type=enum_type, enum=enum_values)
|
||||
|
||||
return SwaggerType(type=enum_type, enum=list(field.choices.keys()))
|
||||
return result
|
||||
|
||||
return NotHandled
|
||||
|
||||
@@ -675,42 +715,56 @@ try:
|
||||
from djangorestframework_camel_case.render import CamelCaseJSONRenderer
|
||||
from djangorestframework_camel_case.render import camelize
|
||||
except ImportError: # pragma: no cover
|
||||
class CamelCaseJSONFilter(FieldInspector):
|
||||
"""Converts property names to camelCase if ``djangorestframework_camel_case`` is used."""
|
||||
pass
|
||||
else:
|
||||
def camelize_string(s):
|
||||
"""Hack to force ``djangorestframework_camel_case`` to camelize a plain string."""
|
||||
CamelCaseJSONParser = CamelCaseJSONRenderer = None
|
||||
|
||||
def camelize(data):
|
||||
return data
|
||||
|
||||
|
||||
class CamelCaseJSONFilter(FieldInspector):
|
||||
"""Converts property names to camelCase if ``djangorestframework_camel_case`` is used."""
|
||||
|
||||
def camelize_string(self, s):
|
||||
"""Hack to force ``djangorestframework_camel_case`` to camelize a plain string.
|
||||
|
||||
:param str s: the string
|
||||
:return: camelized string
|
||||
:rtype: str
|
||||
"""
|
||||
return next(iter(camelize({s: ''})))
|
||||
|
||||
def camelize_schema(schema_or_ref, components):
|
||||
"""Recursively camelize property names for the given schema using ``djangorestframework_camel_case``."""
|
||||
schema = openapi.resolve_ref(schema_or_ref, components)
|
||||
def camelize_schema(self, schema):
|
||||
"""Recursively camelize property names for the given schema using ``djangorestframework_camel_case``.
|
||||
The target schema object must be modified in-place.
|
||||
|
||||
:param openapi.Schema schema: the :class:`.Schema` object
|
||||
"""
|
||||
if getattr(schema, 'properties', {}):
|
||||
schema.properties = OrderedDict(
|
||||
(camelize_string(key), camelize_schema(val, components))
|
||||
(self.camelize_string(key), self.camelize_schema(openapi.resolve_ref(val, self.components)) or val)
|
||||
for key, val in schema.properties.items()
|
||||
)
|
||||
|
||||
if getattr(schema, 'required', []):
|
||||
schema.required = [camelize_string(p) for p in schema.required]
|
||||
schema.required = [self.camelize_string(p) for p in schema.required]
|
||||
|
||||
return schema_or_ref
|
||||
def process_result(self, result, method_name, obj, **kwargs):
|
||||
if isinstance(result, openapi.Schema.OR_REF) and self.is_camel_case():
|
||||
schema = openapi.resolve_ref(result, self.components)
|
||||
self.camelize_schema(schema)
|
||||
|
||||
class CamelCaseJSONFilter(FieldInspector):
|
||||
"""Converts property names to camelCase if ``CamelCaseJSONParser`` or ``CamelCaseJSONRenderer`` are used."""
|
||||
return result
|
||||
|
||||
if CamelCaseJSONParser and CamelCaseJSONRenderer:
|
||||
def is_camel_case(self):
|
||||
return (
|
||||
any(issubclass(parser, CamelCaseJSONParser) for parser in self.view.parser_classes) or
|
||||
any(issubclass(renderer, CamelCaseJSONRenderer) for renderer in self.view.renderer_classes)
|
||||
any(issubclass(parser, CamelCaseJSONParser) for parser in self.get_parser_classes()) or
|
||||
any(issubclass(renderer, CamelCaseJSONRenderer) for renderer in self.get_renderer_classes())
|
||||
)
|
||||
else:
|
||||
def is_camel_case(self):
|
||||
return False
|
||||
|
||||
def process_result(self, result, method_name, obj, **kwargs):
|
||||
if isinstance(result, openapi.Schema.OR_REF) and self.is_camel_case():
|
||||
return camelize_schema(result, self.components)
|
||||
|
||||
return result
|
||||
|
||||
try:
|
||||
from rest_framework_recursive.fields import RecursiveField
|
||||
|
||||
@@ -44,12 +44,16 @@ class CoreAPICompatInspector(PaginatorInspector, FilterInspector):
|
||||
coreschema.String: openapi.TYPE_STRING,
|
||||
coreschema.Boolean: openapi.TYPE_BOOLEAN,
|
||||
}
|
||||
|
||||
coreschema_attrs = ['format', 'pattern', 'enum', 'min_length', 'max_length']
|
||||
schema = field.schema
|
||||
return openapi.Parameter(
|
||||
name=field.name,
|
||||
in_=location_to_in[field.location],
|
||||
type=coreapi_types.get(type(field.schema), openapi.TYPE_STRING),
|
||||
required=field.required,
|
||||
description=force_real_str(field.schema.description) if field.schema else None,
|
||||
description=force_real_str(schema.description) if schema else None,
|
||||
type=coreapi_types.get(type(schema), openapi.TYPE_STRING),
|
||||
**OrderedDict((attr, getattr(schema, attr, None)) for attr in coreschema_attrs)
|
||||
)
|
||||
|
||||
|
||||
@@ -67,8 +71,8 @@ class DjangoRestResponsePagination(PaginatorInspector):
|
||||
type=openapi.TYPE_OBJECT,
|
||||
properties=OrderedDict((
|
||||
('count', openapi.Schema(type=openapi.TYPE_INTEGER) if has_count else None),
|
||||
('next', openapi.Schema(type=openapi.TYPE_STRING, format=openapi.FORMAT_URI)),
|
||||
('previous', openapi.Schema(type=openapi.TYPE_STRING, format=openapi.FORMAT_URI)),
|
||||
('next', openapi.Schema(type=openapi.TYPE_STRING, format=openapi.FORMAT_URI, x_nullable=True)),
|
||||
('previous', openapi.Schema(type=openapi.TYPE_STRING, format=openapi.FORMAT_URI, x_nullable=True)),
|
||||
('results', response_schema),
|
||||
)),
|
||||
required=['results']
|
||||
|
||||
@@ -8,12 +8,12 @@ from rest_framework.status import is_success
|
||||
from .. import openapi
|
||||
from ..errors import SwaggerGenerationError
|
||||
from ..utils import (
|
||||
force_real_str, force_serializer_instance, get_consumes, get_produces, guess_response_status, is_list_view,
|
||||
merge_params, no_body, param_list_to_odict
|
||||
filter_none, force_real_str, force_serializer_instance, get_consumes, get_produces, guess_response_status,
|
||||
is_list_view, merge_params, no_body, param_list_to_odict
|
||||
)
|
||||
from .base import ViewInspector
|
||||
from .base import ViewInspector, call_view_method
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class SwaggerAutoSchema(ViewInspector):
|
||||
@@ -21,6 +21,17 @@ class SwaggerAutoSchema(ViewInspector):
|
||||
super(SwaggerAutoSchema, self).__init__(view, path, method, components, request, overrides)
|
||||
self._sch = AutoSchema()
|
||||
self._sch.view = view
|
||||
self._summary_and_description_compat()
|
||||
|
||||
def _summary_and_description_compat(self):
|
||||
# TODO: remove in 1.14
|
||||
base_methods = (SwaggerAutoSchema.get_summary, SwaggerAutoSchema.get_description)
|
||||
self_methods = (type(self).get_summary, type(self).get_description)
|
||||
if self_methods != base_methods:
|
||||
raise NotImplementedError(
|
||||
"`SwaggerAutoSchema` methods `get_summary` and `get_description` were removed in "
|
||||
"drf-yasg 1.13 and will have no effect. Override `get_summary_and_description` instead."
|
||||
)
|
||||
|
||||
def get_operation(self, operation_keys):
|
||||
consumes = self.get_consumes()
|
||||
@@ -29,14 +40,13 @@ class SwaggerAutoSchema(ViewInspector):
|
||||
body = self.get_request_body_parameters(consumes)
|
||||
query = self.get_query_parameters()
|
||||
parameters = body + query
|
||||
parameters = [param for param in parameters if param is not None]
|
||||
parameters = filter_none(parameters)
|
||||
parameters = self.add_manual_parameters(parameters)
|
||||
|
||||
operation_id = self.get_operation_id(operation_keys)
|
||||
description = self.get_description()
|
||||
summary = self.get_summary()
|
||||
summary, description = self.get_summary_and_description()
|
||||
security = self.get_security()
|
||||
assert security is None or isinstance(security, list), "security must be a list of securiy requirement objects"
|
||||
assert security is None or isinstance(security, list), "security must be a list of security requirement objects"
|
||||
deprecated = self.is_deprecated()
|
||||
tags = self.get_tags(operation_keys)
|
||||
|
||||
@@ -87,21 +97,12 @@ class SwaggerAutoSchema(ViewInspector):
|
||||
"""Return the serializer as defined by the view's ``get_serializer()`` method.
|
||||
|
||||
:return: the view's ``Serializer``
|
||||
:rtype: rest_framework.serializers.Serializer
|
||||
"""
|
||||
if not hasattr(self.view, 'get_serializer'):
|
||||
return None
|
||||
try:
|
||||
return self.view.get_serializer()
|
||||
except Exception:
|
||||
log.warning("view's get_serializer raised exception (%s %s %s)",
|
||||
self.method, self.path, type(self.view).__name__, exc_info=True)
|
||||
return None
|
||||
return call_view_method(self.view, 'get_serializer')
|
||||
|
||||
def _get_request_body_override(self):
|
||||
"""Parse the request_body key in the override dict. This method is not public API.
|
||||
|
||||
:return:
|
||||
"""
|
||||
"""Parse the request_body key in the override dict. This method is not public API."""
|
||||
body_override = self.overrides.get('request_body', None)
|
||||
|
||||
if body_override is not None:
|
||||
@@ -120,6 +121,7 @@ class SwaggerAutoSchema(ViewInspector):
|
||||
"""Return the request serializer (used for parsing the request payload) for this endpoint.
|
||||
|
||||
:return: the request serializer, or one of :class:`.Schema`, :class:`.SchemaRef`, ``None``
|
||||
:rtype: rest_framework.serializers.Serializer
|
||||
"""
|
||||
body_override = self._get_request_body_override()
|
||||
|
||||
@@ -167,12 +169,13 @@ class SwaggerAutoSchema(ViewInspector):
|
||||
if any(param.in_ == openapi.IN_BODY for param in manual_parameters): # pragma: no cover
|
||||
raise SwaggerGenerationError("specify the body parameter as a Schema or Serializer in request_body")
|
||||
if any(param.in_ == openapi.IN_FORM for param in manual_parameters): # pragma: no cover
|
||||
if any(param.in_ == openapi.IN_BODY for param in parameters):
|
||||
has_body_parameter = any(param.in_ == openapi.IN_BODY for param in parameters)
|
||||
if has_body_parameter or not any(is_form_media_type(encoding) for encoding in self.get_consumes()):
|
||||
raise SwaggerGenerationError("cannot add form parameters when the request has a request body; "
|
||||
"did you forget to set an appropriate parser class on the view?")
|
||||
if self.method not in self.body_methods:
|
||||
raise SwaggerGenerationError("form parameters can only be applied to (" + ','.join(self.body_methods) +
|
||||
") HTTP methods")
|
||||
raise SwaggerGenerationError("form parameters can only be applied to "
|
||||
"(" + ','.join(self.body_methods) + ") HTTP methods")
|
||||
|
||||
return merge_params(parameters, manual_parameters)
|
||||
|
||||
@@ -321,7 +324,32 @@ class SwaggerAutoSchema(ViewInspector):
|
||||
operation_id = '_'.join(operation_keys)
|
||||
return operation_id
|
||||
|
||||
def _extract_description_and_summary(self):
|
||||
def split_summary_from_description(self, description):
|
||||
"""Decide if and how to split a summary out of the given description. The default implementation
|
||||
uses the first paragraph of the description as a summary if it is less than 120 characters long.
|
||||
|
||||
:param description: the full description to be analyzed
|
||||
:return: summary and description
|
||||
:rtype: (str,str)
|
||||
"""
|
||||
# https://www.python.org/dev/peps/pep-0257/#multi-line-docstrings
|
||||
summary = None
|
||||
summary_max_len = 120 # OpenAPI 2.0 spec says summary should be under 120 characters
|
||||
sections = description.split('\n\n', 1)
|
||||
if len(sections) == 2:
|
||||
sections[0] = sections[0].strip()
|
||||
if len(sections[0]) < summary_max_len:
|
||||
summary, description = sections
|
||||
description = description.strip()
|
||||
|
||||
return summary, description
|
||||
|
||||
def get_summary_and_description(self):
|
||||
"""Return an operation summary and description determined from the view's docstring.
|
||||
|
||||
:return: summary and description
|
||||
:rtype: (str,str)
|
||||
"""
|
||||
description = self.overrides.get('operation_description', None)
|
||||
summary = self.overrides.get('operation_summary', None)
|
||||
if description is None:
|
||||
@@ -329,24 +357,10 @@ class SwaggerAutoSchema(ViewInspector):
|
||||
description = description.strip().replace('\r', '')
|
||||
|
||||
if description and (summary is None):
|
||||
# description from docstring ... do summary magic
|
||||
# https://www.python.org/dev/peps/pep-0257/#multi-line-docstrings
|
||||
summary_max_len = 120 # OpenAPI 2.0 spec says summary should be under 120 characters
|
||||
sections = description.split('\n\n', 1)
|
||||
if len(sections) == 2:
|
||||
sections[0] = sections[0].strip()
|
||||
if len(sections[0]) < summary_max_len:
|
||||
summary, description = sections
|
||||
# description from docstring... do summary magic
|
||||
summary, description = self.split_summary_from_description(description)
|
||||
|
||||
return description, summary
|
||||
|
||||
def get_description(self):
|
||||
"""Return an operation description determined as appropriate from the view's method and class docstrings.
|
||||
|
||||
:return: the operation description
|
||||
:rtype: str
|
||||
"""
|
||||
return self._extract_description_and_summary()[0]
|
||||
return summary, description
|
||||
|
||||
def get_summary(self):
|
||||
"""Return a summary description for this operation.
|
||||
@@ -354,7 +368,15 @@ class SwaggerAutoSchema(ViewInspector):
|
||||
:return: the summary
|
||||
:rtype: str
|
||||
"""
|
||||
return self._extract_description_and_summary()[1]
|
||||
return self.get_summary_and_description()[0]
|
||||
|
||||
def get_description(self):
|
||||
"""Return an operation description determined as appropriate from the view's method and class docstrings.
|
||||
|
||||
:return: the operation description
|
||||
:rtype: str
|
||||
"""
|
||||
return self.get_summary_and_description()[1]
|
||||
|
||||
def get_security(self):
|
||||
"""Return a list of security requirements for this operation.
|
||||
@@ -376,24 +398,29 @@ class SwaggerAutoSchema(ViewInspector):
|
||||
|
||||
def get_tags(self, operation_keys):
|
||||
"""Get a list of tags for this operation. Tags determine how operations relate with each other, and in the UI
|
||||
each tag will show as a group containing the operations that use it.
|
||||
each tag will show as a group containing the operations that use it. If not provided in overrides,
|
||||
tags will be inferred from the operation url.
|
||||
|
||||
:param tuple[str] operation_keys: an array of keys derived from the pathdescribing the hierarchical layout
|
||||
of this view in the API; e.g. ``('snippets', 'list')``, ``('snippets', 'retrieve')``, etc.
|
||||
:rtype: list[str]
|
||||
"""
|
||||
return [operation_keys[0]]
|
||||
tags = self.overrides.get('tags')
|
||||
if not tags:
|
||||
tags = [operation_keys[0]]
|
||||
|
||||
return tags
|
||||
|
||||
def get_consumes(self):
|
||||
"""Return the MIME types this endpoint can consume.
|
||||
|
||||
:rtype: list[str]
|
||||
"""
|
||||
return get_consumes(getattr(self.view, 'parser_classes', []))
|
||||
return get_consumes(self.get_parser_classes())
|
||||
|
||||
def get_produces(self):
|
||||
"""Return the MIME types this endpoint can produce.
|
||||
|
||||
:rtype: list[str]
|
||||
"""
|
||||
return get_produces(getattr(self.view, 'renderer_classes', []))
|
||||
return get_produces(self.get_renderer_classes())
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
from collections import OrderedDict
|
||||
from importlib import import_module
|
||||
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.utils.module_loading import import_string
|
||||
from rest_framework.settings import api_settings
|
||||
from rest_framework.test import APIRequestFactory, force_authenticate
|
||||
from rest_framework.views import APIView
|
||||
|
||||
@@ -15,15 +14,6 @@ from ...app_settings import swagger_settings
|
||||
from ...codecs import OpenAPICodecJson, OpenAPICodecYaml
|
||||
|
||||
|
||||
def import_class(import_string):
|
||||
if not import_string:
|
||||
return None
|
||||
|
||||
module_path, class_name = import_string.rsplit('.', 1)
|
||||
module = import_module(module_path)
|
||||
return getattr(module, class_name)
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'Write the Swagger schema to disk in JSON or YAML format.'
|
||||
|
||||
@@ -43,7 +33,7 @@ class Command(BaseCommand):
|
||||
)
|
||||
parser.add_argument(
|
||||
'-f', '--format', dest='format',
|
||||
default='', choices=('json', 'yaml'),
|
||||
default='', choices=['json', 'yaml'],
|
||||
type=str,
|
||||
help='Output format. If not given, it is guessed from the output file extension and defaults to json.'
|
||||
)
|
||||
@@ -56,7 +46,7 @@ class Command(BaseCommand):
|
||||
parser.add_argument(
|
||||
'-m', '--mock-request', dest='mock',
|
||||
default=False, action='store_true',
|
||||
help='Use a mock request when generating the swagger schema. This is useful if your views or serializers'
|
||||
help='Use a mock request when generating the swagger schema. This is useful if your views or serializers '
|
||||
'depend on context from a request in order to function.'
|
||||
)
|
||||
parser.add_argument(
|
||||
@@ -85,11 +75,9 @@ class Command(BaseCommand):
|
||||
|
||||
def write_schema(self, schema, stream, format):
|
||||
if format == 'json':
|
||||
codec = OpenAPICodecJson(validators=[])
|
||||
swagger_json = codec.encode(schema)
|
||||
swagger_json = json.loads(swagger_json.decode('utf-8'), object_pairs_hook=OrderedDict)
|
||||
pretty_json = json.dumps(swagger_json, indent=4, ensure_ascii=True)
|
||||
stream.write(pretty_json)
|
||||
codec = OpenAPICodecJson(validators=[], pretty=True)
|
||||
swagger_json = codec.encode(schema).decode('utf-8')
|
||||
stream.write(swagger_json)
|
||||
elif format == 'yaml':
|
||||
codec = OpenAPICodecYaml(validators=[])
|
||||
swagger_yaml = codec.encode(schema).decode('utf-8')
|
||||
@@ -107,6 +95,20 @@ class Command(BaseCommand):
|
||||
request = APIView().initialize_request(request)
|
||||
return request
|
||||
|
||||
def get_schema_generator(self, generator_class_name, api_info, api_version, api_url):
|
||||
generator_class = swagger_settings.DEFAULT_GENERATOR_CLASS
|
||||
if generator_class_name:
|
||||
generator_class = import_string(generator_class_name)
|
||||
|
||||
return generator_class(
|
||||
info=api_info,
|
||||
version=api_version,
|
||||
url=api_url,
|
||||
)
|
||||
|
||||
def get_schema(self, generator, request, public):
|
||||
return generator.get_schema(request=request, public=public)
|
||||
|
||||
def handle(self, output_file, overwrite, format, api_url, mock, api_version, user, private, generator_class_name,
|
||||
*args, **kwargs):
|
||||
# disable logs of WARNING and below
|
||||
@@ -142,22 +144,19 @@ class Command(BaseCommand):
|
||||
if mock:
|
||||
request = self.get_mock_request(api_url, format, user)
|
||||
|
||||
api_version = api_version or api_settings.DEFAULT_VERSION
|
||||
if request and api_version:
|
||||
request.version = api_version
|
||||
|
||||
generator_class = import_class(generator_class_name) or swagger_settings.DEFAULT_GENERATOR_CLASS
|
||||
generator = generator_class(
|
||||
info=info,
|
||||
version=api_version,
|
||||
url=api_url,
|
||||
)
|
||||
schema = generator.get_schema(request=request, public=not private)
|
||||
generator = self.get_schema_generator(generator_class_name, info, api_version, api_url)
|
||||
schema = self.get_schema(generator, request, not private)
|
||||
|
||||
if output_file == '-':
|
||||
self.write_schema(schema, self.stdout, format)
|
||||
else:
|
||||
# normally this would be easily done with open(mode='x'/'w'),
|
||||
# but python 2 is a pain in the ass as usual
|
||||
# TODO: simplify when dropping support for python 2.7
|
||||
flags = os.O_CREAT | os.O_WRONLY
|
||||
flags = flags | (os.O_TRUNC if overwrite else os.O_EXCL)
|
||||
with os.fdopen(os.open(output_file, flags), "w") as stream:
|
||||
|
||||
+72
-46
@@ -1,12 +1,21 @@
|
||||
import six
|
||||
|
||||
import collections
|
||||
import logging
|
||||
import re
|
||||
from collections import OrderedDict
|
||||
|
||||
from coreapi.compat import urlparse
|
||||
from django.urls import get_script_prefix
|
||||
from django.utils.functional import Promise
|
||||
from inflection import camelize
|
||||
|
||||
from .utils import filter_none
|
||||
from .utils import dict_has_ordered_keys, filter_none, force_real_str
|
||||
|
||||
try:
|
||||
from collections import abc as collections_abc
|
||||
except ImportError:
|
||||
collections_abc = collections
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -128,13 +137,22 @@ class SwaggerDict(OrderedDict):
|
||||
if id(obj) in memo:
|
||||
return memo[id(obj)]
|
||||
|
||||
if isinstance(obj, dict):
|
||||
if isinstance(obj, Promise) and hasattr(obj, '_proxy____cast'):
|
||||
# handle __proxy__ objects from django.utils.functional.lazy
|
||||
obj = obj._proxy____cast()
|
||||
|
||||
if isinstance(obj, collections_abc.Mapping):
|
||||
result = OrderedDict()
|
||||
memo[id(obj)] = result
|
||||
for attr, val in obj.items():
|
||||
items = obj.items()
|
||||
if not dict_has_ordered_keys(obj):
|
||||
items = sorted(items)
|
||||
for attr, val in items:
|
||||
result[attr] = SwaggerDict._as_odict(val, memo)
|
||||
return result
|
||||
elif isinstance(obj, (list, tuple)):
|
||||
elif isinstance(obj, six.string_types):
|
||||
return force_real_str(obj)
|
||||
elif isinstance(obj, collections_abc.Iterable) and not isinstance(obj, collections_abc.Iterator):
|
||||
return type(obj)(SwaggerDict._as_odict(elem, memo) for elem in obj)
|
||||
|
||||
return obj
|
||||
@@ -224,12 +242,12 @@ class Swagger(SwaggerDict):
|
||||
:param str _prefix: api path prefix to use in setting basePath; this will be appended to the wsgi
|
||||
SCRIPT_NAME prefix or Django's FORCE_SCRIPT_NAME if applicable
|
||||
:param str _version: version string to override Info
|
||||
:param dict[str,dict[str,str]] security_definitions: list of supported authentication mechanisms
|
||||
:param list[dict] security: authentication mechanisms accepted by default; can be overriden in Operation
|
||||
:param dict[str,dict] security_definitions: list of supported authentication mechanisms
|
||||
:param list[dict[str,list[str]]] security: authentication mechanisms accepted globally
|
||||
:param list[str] consumes: consumed MIME types; can be overriden in Operation
|
||||
:param list[str] produces: produced MIME types; can be overriden in Operation
|
||||
:param .Paths paths: paths object
|
||||
:param dict[str,.Schema] definitions: named models
|
||||
:param Paths paths: paths object
|
||||
:param dict[str,Schema] definitions: named models
|
||||
"""
|
||||
super(Swagger, self).__init__(**extra)
|
||||
self.swagger = '2.0'
|
||||
@@ -280,7 +298,7 @@ class Paths(SwaggerDict):
|
||||
def __init__(self, paths, **extra):
|
||||
"""A listing of all the paths in the API.
|
||||
|
||||
:param dict[str,.PathItem] paths:
|
||||
:param dict[str,PathItem] paths:
|
||||
"""
|
||||
super(Paths, self).__init__(**extra)
|
||||
for path, path_obj in paths.items():
|
||||
@@ -297,14 +315,14 @@ class PathItem(SwaggerDict):
|
||||
head=None, patch=None, parameters=None, **extra):
|
||||
"""Information about a single path
|
||||
|
||||
:param .Operation get: operation for GET
|
||||
:param .Operation put: operation for PUT
|
||||
:param .Operation post: operation for POST
|
||||
:param .Operation delete: operation for DELETE
|
||||
:param .Operation options: operation for OPTIONS
|
||||
:param .Operation head: operation for HEAD
|
||||
:param .Operation patch: operation for PATCH
|
||||
:param list[.Parameter] parameters: parameters that apply to all operations
|
||||
:param Operation get: operation for GET
|
||||
:param Operation put: operation for PUT
|
||||
:param Operation post: operation for POST
|
||||
:param Operation delete: operation for DELETE
|
||||
:param Operation options: operation for OPTIONS
|
||||
:param Operation head: operation for HEAD
|
||||
:param Operation patch: operation for PATCH
|
||||
:param list[Parameter] parameters: parameters that apply to all operations
|
||||
"""
|
||||
super(PathItem, self).__init__(**extra)
|
||||
self.get = get
|
||||
@@ -333,8 +351,8 @@ class Operation(SwaggerDict):
|
||||
"""Information about an API operation (path + http method combination)
|
||||
|
||||
:param str operation_id: operation ID, should be unique across all operations
|
||||
:param .Responses responses: responses returned
|
||||
:param list[.Parameter] parameters: parameters accepted
|
||||
:param Responses responses: responses returned
|
||||
:param list[Parameter] parameters: parameters accepted
|
||||
:param list[str] consumes: content types accepted
|
||||
:param list[str] produces: content types produced
|
||||
:param str summary: operation summary; should be < 120 characters
|
||||
@@ -355,6 +373,17 @@ class Operation(SwaggerDict):
|
||||
self._insert_extras__()
|
||||
|
||||
|
||||
def _check_type(type, format, enum, pattern, items, _obj_type):
|
||||
if items and type != TYPE_ARRAY:
|
||||
raise AssertionError("items can only be used when type is array")
|
||||
if type == TYPE_ARRAY and not items:
|
||||
raise AssertionError("TYPE_ARRAY requires the items attribute")
|
||||
if pattern and type != TYPE_STRING:
|
||||
raise AssertionError("pattern can only be used when type is string")
|
||||
if (format or enum or pattern) and type in (TYPE_OBJECT, TYPE_ARRAY, None):
|
||||
raise AssertionError("[format, enum, pattern] can only be applied to primitive " + _obj_type)
|
||||
|
||||
|
||||
class Items(SwaggerDict):
|
||||
def __init__(self, type=None, format=None, enum=None, pattern=None, items=None, **extra):
|
||||
"""Used when defining an array :class:`.Parameter` to describe the array elements.
|
||||
@@ -373,10 +402,7 @@ class Items(SwaggerDict):
|
||||
self.pattern = pattern
|
||||
self.items = items
|
||||
self._insert_extras__()
|
||||
if items and type != TYPE_ARRAY:
|
||||
raise AssertionError("items can only be used when type is array")
|
||||
if pattern and type != TYPE_STRING:
|
||||
raise AssertionError("pattern can only be used when type is string")
|
||||
_check_type(type, format, enum, pattern, items, self.__class__)
|
||||
|
||||
|
||||
class Parameter(SwaggerDict):
|
||||
@@ -389,7 +415,8 @@ class Parameter(SwaggerDict):
|
||||
:param str in_: parameter location
|
||||
:param str description: parameter description
|
||||
:param bool required: whether the parameter is required for the operation
|
||||
:param .Schema,.SchemaRef schema: required if `in_` is ``body``
|
||||
:param schema: required if `in_` is ``body``
|
||||
:type schema: Schema or SchemaRef
|
||||
:param str type: parameter type; required if `in_` is not ``body``; must not be ``object``
|
||||
:param str format: value format, see OpenAPI spec
|
||||
:param list enum: restrict possible values
|
||||
@@ -420,12 +447,9 @@ class Parameter(SwaggerDict):
|
||||
self.required = True
|
||||
if self['in'] != IN_BODY and schema is not None:
|
||||
raise AssertionError("schema can only be applied to a body Parameter, not %s" % type)
|
||||
if (format or enum or pattern or default) and not type:
|
||||
raise AssertionError("[format, enum, pattern, default] can only be applied to non-body Parameter")
|
||||
if items and type != TYPE_ARRAY:
|
||||
raise AssertionError("items can only be used when type is array")
|
||||
if pattern and type != TYPE_STRING:
|
||||
raise AssertionError("pattern can only be used when type is string")
|
||||
if default and not type:
|
||||
raise AssertionError("default can only be applied to a non-body Parameter")
|
||||
_check_type(type, format, enum, pattern, items, self.__class__)
|
||||
|
||||
|
||||
class Schema(SwaggerDict):
|
||||
@@ -441,10 +465,13 @@ 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 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 properties: object properties; required if `type` is ``object``
|
||||
:type properties: dict[str,Schema or SchemaRef]
|
||||
:param additional_properties: allow wildcard properties not listed in `properties`
|
||||
:type additional_properties: bool or Schema or SchemaRef
|
||||
:param list[str] required: list of requried property names
|
||||
:param .Schema,.SchemaRef items: type of array items, only valid if `type` is ``array``
|
||||
:param items: type of array items, only valid if `type` is ``array``
|
||||
:type items: Schema or SchemaRef
|
||||
:param default: only valid when insider another ``Schema``\\ 's ``properties``;
|
||||
the default value of this property if it is not provided, must conform to the type of this Schema
|
||||
:param read_only: only valid when insider another ``Schema``\\ 's ``properties``;
|
||||
@@ -471,12 +498,7 @@ class Schema(SwaggerDict):
|
||||
self._insert_extras__()
|
||||
if (properties or (additional_properties is not None)) and type != TYPE_OBJECT:
|
||||
raise AssertionError("only object Schema can have properties")
|
||||
if (format or enum or pattern) and type in (TYPE_OBJECT, TYPE_ARRAY):
|
||||
raise AssertionError("[format, enum, pattern] can only be applied to primitive Schema")
|
||||
if items and type != TYPE_ARRAY:
|
||||
raise AssertionError("items can only be used when type is array")
|
||||
if pattern and type != TYPE_STRING:
|
||||
raise AssertionError("pattern can only be used when type is string")
|
||||
_check_type(type, format, enum, pattern, items, self.__class__)
|
||||
|
||||
def _remove_read_only(self):
|
||||
# readOnly is only valid for Schemas inside another Schema's properties;
|
||||
@@ -495,7 +517,7 @@ class _Ref(SwaggerDict):
|
||||
:param str name: referenced object name, e.g. "Article"
|
||||
:param str scope: reference scope, e.g. "definitions"
|
||||
:param type[.SwaggerDict] expected_type: the expected type that will be asserted on the object found in resolver
|
||||
:param bool ignore_unresolved: allow the reference to be not defined in resolver
|
||||
:param bool ignore_unresolved: do not throw if the referenced object does not exist
|
||||
"""
|
||||
super(_Ref, self).__init__()
|
||||
assert not type(self) == _Ref, "do not instantiate _Ref directly"
|
||||
@@ -530,7 +552,7 @@ class SchemaRef(_Ref):
|
||||
|
||||
:param .ReferenceResolver resolver: component resolver which must contain the definition
|
||||
:param str schema_name: schema name
|
||||
:param bool ignore_unresolved: allow the reference to be not defined in resolver
|
||||
:param bool ignore_unresolved: do not throw if the referenced object does not exist
|
||||
"""
|
||||
assert SCHEMA_DEFINITIONS in resolver.scopes
|
||||
super(SchemaRef, self).__init__(resolver, schema_name, SCHEMA_DEFINITIONS, Schema, ignore_unresolved)
|
||||
@@ -542,7 +564,8 @@ Schema.OR_REF = (Schema, SchemaRef)
|
||||
def resolve_ref(ref_or_obj, resolver):
|
||||
"""Resolve `ref_or_obj` if it is a reference type. Return it unchaged if not.
|
||||
|
||||
:param SwaggerDict,_Ref ref_or_obj:
|
||||
:param ref_or_obj: object to derefernece
|
||||
:type ref_or_obj: SwaggerDict or _Ref
|
||||
:param resolver: component resolver which must contain the referenced object
|
||||
"""
|
||||
if isinstance(ref_or_obj, _Ref):
|
||||
@@ -554,8 +577,9 @@ class Responses(SwaggerDict):
|
||||
def __init__(self, responses, default=None, **extra):
|
||||
"""Describes the expected responses of an :class:`.Operation`.
|
||||
|
||||
:param dict[(str,int),.Response] responses: mapping of status code to response definition
|
||||
:param .Response default: description of the response structure to expect if another status code is returned
|
||||
:param responses: mapping of status code to response definition
|
||||
:type responses: dict[str or int,Response]
|
||||
:param Response default: description of the response structure to expect if another status code is returned
|
||||
"""
|
||||
super(Responses, self).__init__(**extra)
|
||||
for status, response in responses.items():
|
||||
@@ -570,7 +594,9 @@ class Response(SwaggerDict):
|
||||
"""Describes the structure of an operation's response.
|
||||
|
||||
:param str description: response description
|
||||
:param .Schema,.SchemaRef schema: sturcture of the response body
|
||||
:param schema: sturcture of the response body
|
||||
:type schema: Schema or SchemaRef or rest_framework.serializers.Serializer
|
||||
or type[rest_framework.serializers.Serializer]
|
||||
:param dict examples: example bodies mapped by mime type
|
||||
"""
|
||||
super(Response, self).__init__(**extra)
|
||||
@@ -643,7 +669,7 @@ class ReferenceResolver(object):
|
||||
"""Set an object in the given scope only if it does not exist.
|
||||
|
||||
:param str name: reference name
|
||||
:param callable maker: object factory, called only if necessary
|
||||
:param function maker: object factory, called only if necessary
|
||||
:param str scope: reference scope
|
||||
"""
|
||||
scope = self._check_scope(scope)
|
||||
|
||||
+29
-17
@@ -1,9 +1,11 @@
|
||||
import six
|
||||
|
||||
from django.shortcuts import render, resolve_url
|
||||
from django.shortcuts import resolve_url
|
||||
from django.template.loader import render_to_string
|
||||
from django.utils.encoding import force_text
|
||||
from django.utils.functional import Promise
|
||||
from rest_framework.renderers import BaseRenderer, JSONRenderer, TemplateHTMLRenderer
|
||||
from rest_framework.utils import json
|
||||
from rest_framework.utils import encoders, json
|
||||
|
||||
from .app_settings import redoc_settings, swagger_settings
|
||||
from .codecs import VALIDATORS, OpenAPICodecJson, OpenAPICodecYaml
|
||||
@@ -28,9 +30,10 @@ class _SpecRenderer(BaseRenderer):
|
||||
|
||||
if not isinstance(data, Swagger): # pragma: no cover
|
||||
# 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
|
||||
# in that case, it's probably better to let the default ``JSONRenderer`` render it
|
||||
# see https://github.com/axnsan12/drf-yasg/issues/58
|
||||
return JSONRenderer().render(data, media_type, renderer_context)
|
||||
|
||||
return codec.encode(data)
|
||||
|
||||
|
||||
@@ -67,17 +70,14 @@ class _UIRenderer(BaseRenderer):
|
||||
# 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'],
|
||||
self.template,
|
||||
renderer_context
|
||||
)
|
||||
|
||||
def set_context(self, renderer_context, swagger):
|
||||
renderer_context['title'] = swagger.info.title
|
||||
renderer_context['version'] = swagger.info.version
|
||||
renderer_context['oauth2_config'] = json.dumps(self.get_oauth2_config())
|
||||
self.set_context(renderer_context, swagger)
|
||||
return render_to_string(self.template, renderer_context, renderer_context['request'])
|
||||
|
||||
def set_context(self, renderer_context, swagger=None):
|
||||
renderer_context['title'] = swagger.info.title or '' if swagger else ''
|
||||
renderer_context['version'] = swagger.info.version or '' if swagger else ''
|
||||
renderer_context['oauth2_config'] = json.dumps(self.get_oauth2_config(), cls=encoders.JSONEncoder)
|
||||
renderer_context['USE_SESSION_AUTH'] = swagger_settings.USE_SESSION_AUTH
|
||||
renderer_context.update(self.get_auth_urls())
|
||||
|
||||
@@ -119,9 +119,16 @@ class SwaggerUIRenderer(_UIRenderer):
|
||||
template = 'drf-yasg/swagger-ui.html'
|
||||
format = 'swagger'
|
||||
|
||||
def set_context(self, renderer_context, swagger):
|
||||
def set_context(self, renderer_context, swagger=None):
|
||||
super(SwaggerUIRenderer, self).set_context(renderer_context, swagger)
|
||||
renderer_context['swagger_settings'] = json.dumps(self.get_swagger_ui_settings())
|
||||
swagger_ui_settings = self.get_swagger_ui_settings()
|
||||
|
||||
request = renderer_context.get('request', None)
|
||||
oauth_redirect_url = force_text(swagger_ui_settings.get('oauth2RedirectUrl', ''))
|
||||
if request and oauth_redirect_url:
|
||||
swagger_ui_settings['oauth2RedirectUrl'] = request.build_absolute_uri(oauth_redirect_url)
|
||||
|
||||
renderer_context['swagger_settings'] = json.dumps(swagger_ui_settings, cls=encoders.JSONEncoder)
|
||||
|
||||
def get_swagger_ui_settings(self):
|
||||
data = {
|
||||
@@ -138,6 +145,10 @@ class SwaggerUIRenderer(_UIRenderer):
|
||||
'oauth2RedirectUrl': swagger_settings.OAUTH2_REDIRECT_URL,
|
||||
'supportedSubmitMethods': swagger_settings.SUPPORTED_SUBMIT_METHODS,
|
||||
'displayOperationId': swagger_settings.DISPLAY_OPERATION_ID,
|
||||
'persistAuth': swagger_settings.PERSIST_AUTH,
|
||||
'refetchWithAuth': swagger_settings.REFETCH_SCHEMA_WITH_AUTH,
|
||||
'refetchOnLogout': swagger_settings.REFETCH_SCHEMA_ON_LOGOUT,
|
||||
'fetchSchemaWithQuery': swagger_settings.FETCH_SCHEMA_WITH_QUERY,
|
||||
}
|
||||
|
||||
data = filter_none(data)
|
||||
@@ -152,9 +163,9 @@ class ReDocRenderer(_UIRenderer):
|
||||
template = 'drf-yasg/redoc.html'
|
||||
format = 'redoc'
|
||||
|
||||
def set_context(self, renderer_context, swagger):
|
||||
def set_context(self, renderer_context, swagger=None):
|
||||
super(ReDocRenderer, self).set_context(renderer_context, swagger)
|
||||
renderer_context['redoc_settings'] = json.dumps(self.get_redoc_settings())
|
||||
renderer_context['redoc_settings'] = json.dumps(self.get_redoc_settings(), cls=encoders.JSONEncoder)
|
||||
|
||||
def get_redoc_settings(self):
|
||||
data = {
|
||||
@@ -165,6 +176,7 @@ class ReDocRenderer(_UIRenderer):
|
||||
'pathInMiddlePanel': redoc_settings.PATH_IN_MIDDLE,
|
||||
'nativeScrollbars': redoc_settings.NATIVE_SCROLLBARS,
|
||||
'requiredPropsFirst': redoc_settings.REQUIRED_PROPS_FIRST,
|
||||
'fetchSchemaWithQuery': redoc_settings.FETCH_SCHEMA_WITH_QUERY,
|
||||
}
|
||||
|
||||
return filter_none(data)
|
||||
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.Immutable=e()}(this,function(){"use strict";function t(t,e){e&&(t.prototype=Object.create(e.prototype)),t.prototype.constructor=t}function e(t){return o(t)?t:O(t)}function r(t){return u(t)?t:x(t)}function n(t){return s(t)?t:k(t)}function i(t){return o(t)&&!a(t)?t:A(t)}function o(t){return!(!t||!t[ar])}function u(t){return!(!t||!t[hr])}function s(t){return!(!t||!t[fr])}function a(t){return u(t)||s(t)}function h(t){return!(!t||!t[cr])}function f(t){return t.value=!1,t}function c(t){t&&(t.value=!0)}function _(){}function p(t,e){e=e||0;for(var r=Math.max(0,t.length-e),n=Array(r),i=0;r>i;i++)n[i]=t[i+e];return n}function v(t){return void 0===t.size&&(t.size=t.__iterate(y)),t.size}function l(t,e){if("number"!=typeof e){var r=e>>>0;if(""+r!==e||4294967295===r)return NaN;e=r}return 0>e?v(t)+e:e}function y(){return!0}function d(t,e,r){return(0===t||void 0!==r&&-r>=t)&&(void 0===e||void 0!==r&&e>=r)}function m(t,e){return w(t,e,0)}function g(t,e){return w(t,e,e)}function w(t,e,r){return void 0===t?r:0>t?Math.max(0,e+t):void 0===e?t:Math.min(e,t)}function S(t){this.next=t}function z(t,e,r,n){var i=0===t?e:1===t?r:[e,r];return n?n.value=i:n={value:i,done:!1},n}function I(){return{value:void 0,done:!0}}function b(t){return!!M(t)}function q(t){return t&&"function"==typeof t.next}function D(t){var e=M(t);return e&&e.call(t)}function M(t){var e=t&&(zr&&t[zr]||t[Ir]);return"function"==typeof e?e:void 0}function E(t){return t&&"number"==typeof t.length}function O(t){return null===t||void 0===t?T():o(t)?t.toSeq():C(t)}function x(t){return null===t||void 0===t?T().toKeyedSeq():o(t)?u(t)?t.toSeq():t.fromEntrySeq():B(t)}function k(t){return null===t||void 0===t?T():o(t)?u(t)?t.entrySeq():t.toIndexedSeq():W(t)}function A(t){return(null===t||void 0===t?T():o(t)?u(t)?t.entrySeq():t:W(t)).toSetSeq()}function j(t){this._array=t,this.size=t.length}function R(t){var e=Object.keys(t);this._object=t,this._keys=e,
|
||||
this.size=e.length}function U(t){this._iterable=t,this.size=t.length||t.size}function K(t){this._iterator=t,this._iteratorCache=[]}function L(t){return!(!t||!t[qr])}function T(){return Dr||(Dr=new j([]))}function B(t){var e=Array.isArray(t)?new j(t).fromEntrySeq():q(t)?new K(t).fromEntrySeq():b(t)?new U(t).fromEntrySeq():"object"==typeof t?new R(t):void 0;if(!e)throw new TypeError("Expected Array or iterable object of [k, v] entries, or keyed object: "+t);return e}function W(t){var e=J(t);if(!e)throw new TypeError("Expected Array or iterable object of values: "+t);return e}function C(t){var e=J(t)||"object"==typeof t&&new R(t);if(!e)throw new TypeError("Expected Array or iterable object of values, or keyed object: "+t);return e}function J(t){return E(t)?new j(t):q(t)?new K(t):b(t)?new U(t):void 0}function N(t,e,r,n){var i=t._cache;if(i){for(var o=i.length-1,u=0;o>=u;u++){var s=i[r?o-u:u];if(e(s[1],n?s[0]:u,t)===!1)return u+1}return u}return t.__iterateUncached(e,r)}function P(t,e,r,n){var i=t._cache;if(i){var o=i.length-1,u=0;return new S(function(){var t=i[r?o-u:u];return u++>o?I():z(e,n?t[0]:u-1,t[1])})}return t.__iteratorUncached(e,r)}function H(t,e){return e?V(e,t,"",{"":t}):Y(t)}function V(t,e,r,n){return Array.isArray(e)?t.call(n,r,k(e).map(function(r,n){return V(t,r,n,e)})):Q(e)?t.call(n,r,x(e).map(function(r,n){return V(t,r,n,e)})):e}function Y(t){return Array.isArray(t)?k(t).map(Y).toList():Q(t)?x(t).map(Y).toMap():t}function Q(t){return t&&(t.constructor===Object||void 0===t.constructor)}function X(t,e){if(t===e||t!==t&&e!==e)return!0;if(!t||!e)return!1;if("function"==typeof t.valueOf&&"function"==typeof e.valueOf){if(t=t.valueOf(),e=e.valueOf(),t===e||t!==t&&e!==e)return!0;if(!t||!e)return!1}return"function"==typeof t.equals&&"function"==typeof e.equals&&t.equals(e)?!0:!1}function F(t,e){if(t===e)return!0;if(!o(e)||void 0!==t.size&&void 0!==e.size&&t.size!==e.size||void 0!==t.__hash&&void 0!==e.__hash&&t.__hash!==e.__hash||u(t)!==u(e)||s(t)!==s(e)||h(t)!==h(e))return!1;if(0===t.size&&0===e.size)return!0;
|
||||
var r=!a(t);if(h(t)){var n=t.entries();return e.every(function(t,e){var i=n.next().value;return i&&X(i[1],t)&&(r||X(i[0],e))})&&n.next().done}var i=!1;if(void 0===t.size)if(void 0===e.size)"function"==typeof t.cacheResult&&t.cacheResult();else{i=!0;var f=t;t=e,e=f}var c=!0,_=e.__iterate(function(e,n){return(r?t.has(e):i?X(e,t.get(n,yr)):X(t.get(n,yr),e))?void 0:(c=!1,!1)});return c&&t.size===_}function G(t,e){if(!(this instanceof G))return new G(t,e);if(this._value=t,this.size=void 0===e?1/0:Math.max(0,e),0===this.size){if(Mr)return Mr;Mr=this}}function Z(t,e){if(!t)throw Error(e)}function $(t,e,r){if(!(this instanceof $))return new $(t,e,r);if(Z(0!==r,"Cannot step a Range by 0"),t=t||0,void 0===e&&(e=1/0),r=void 0===r?1:Math.abs(r),t>e&&(r=-r),this._start=t,this._end=e,this._step=r,this.size=Math.max(0,Math.ceil((e-t)/r-1)+1),0===this.size){if(Er)return Er;Er=this}}function tt(){throw TypeError("Abstract")}function et(){}function rt(){}function nt(){}function it(t){return t>>>1&1073741824|3221225471&t}function ot(t){if(t===!1||null===t||void 0===t)return 0;if("function"==typeof t.valueOf&&(t=t.valueOf(),t===!1||null===t||void 0===t))return 0;if(t===!0)return 1;var e=typeof t;if("number"===e){if(t!==t||t===1/0)return 0;var r=0|t;for(r!==t&&(r^=4294967295*t);t>4294967295;)t/=4294967295,r^=t;return it(r)}if("string"===e)return t.length>Kr?ut(t):st(t);if("function"==typeof t.hashCode)return t.hashCode();if("object"===e)return at(t);if("function"==typeof t.toString)return st(""+t);throw Error("Value type "+e+" cannot be hashed.")}function ut(t){var e=Br[t];return void 0===e&&(e=st(t),Tr===Lr&&(Tr=0,Br={}),Tr++,Br[t]=e),e}function st(t){for(var e=0,r=0;t.length>r;r++)e=31*e+t.charCodeAt(r)|0;return it(e)}function at(t){var e;if(jr&&(e=Or.get(t),void 0!==e))return e;if(e=t[Ur],void 0!==e)return e;if(!Ar){if(e=t.propertyIsEnumerable&&t.propertyIsEnumerable[Ur],void 0!==e)return e;if(e=ht(t),void 0!==e)return e}if(e=++Rr,1073741824&Rr&&(Rr=0),jr)Or.set(t,e);else{if(void 0!==kr&&kr(t)===!1)throw Error("Non-extensible objects are not allowed as keys.");
|
||||
if(Ar)Object.defineProperty(t,Ur,{enumerable:!1,configurable:!1,writable:!1,value:e});else if(void 0!==t.propertyIsEnumerable&&t.propertyIsEnumerable===t.constructor.prototype.propertyIsEnumerable)t.propertyIsEnumerable=function(){return this.constructor.prototype.propertyIsEnumerable.apply(this,arguments)},t.propertyIsEnumerable[Ur]=e;else{if(void 0===t.nodeType)throw Error("Unable to set a non-enumerable property on object.");t[Ur]=e}}return e}function ht(t){if(t&&t.nodeType>0)switch(t.nodeType){case 1:return t.uniqueID;case 9:return t.documentElement&&t.documentElement.uniqueID}}function ft(t){Z(t!==1/0,"Cannot perform this action with an infinite size.")}function ct(t){return null===t||void 0===t?zt():_t(t)&&!h(t)?t:zt().withMutations(function(e){var n=r(t);ft(n.size),n.forEach(function(t,r){return e.set(r,t)})})}function _t(t){return!(!t||!t[Wr])}function pt(t,e){this.ownerID=t,this.entries=e}function vt(t,e,r){this.ownerID=t,this.bitmap=e,this.nodes=r}function lt(t,e,r){this.ownerID=t,this.count=e,this.nodes=r}function yt(t,e,r){this.ownerID=t,this.keyHash=e,this.entries=r}function dt(t,e,r){this.ownerID=t,this.keyHash=e,this.entry=r}function mt(t,e,r){this._type=e,this._reverse=r,this._stack=t._root&&wt(t._root)}function gt(t,e){return z(t,e[0],e[1])}function wt(t,e){return{node:t,index:0,__prev:e}}function St(t,e,r,n){var i=Object.create(Cr);return i.size=t,i._root=e,i.__ownerID=r,i.__hash=n,i.__altered=!1,i}function zt(){return Jr||(Jr=St(0))}function It(t,e,r){var n,i;if(t._root){var o=f(dr),u=f(mr);if(n=bt(t._root,t.__ownerID,0,void 0,e,r,o,u),!u.value)return t;i=t.size+(o.value?r===yr?-1:1:0)}else{if(r===yr)return t;i=1,n=new pt(t.__ownerID,[[e,r]])}return t.__ownerID?(t.size=i,t._root=n,t.__hash=void 0,t.__altered=!0,t):n?St(i,n):zt()}function bt(t,e,r,n,i,o,u,s){return t?t.update(e,r,n,i,o,u,s):o===yr?t:(c(s),c(u),new dt(e,n,[i,o]))}function qt(t){return t.constructor===dt||t.constructor===yt}function Dt(t,e,r,n,i){if(t.keyHash===n)return new yt(e,n,[t.entry,i]);var o,u=(0===r?t.keyHash:t.keyHash>>>r)&lr,s=(0===r?n:n>>>r)&lr,a=u===s?[Dt(t,e,r+pr,n,i)]:(o=new dt(e,n,i),
|
||||
s>u?[t,o]:[o,t]);return new vt(e,1<<u|1<<s,a)}function Mt(t,e,r,n){t||(t=new _);for(var i=new dt(t,ot(r),[r,n]),o=0;e.length>o;o++){var u=e[o];i=i.update(t,0,void 0,u[0],u[1])}return i}function Et(t,e,r,n){for(var i=0,o=0,u=Array(r),s=0,a=1,h=e.length;h>s;s++,a<<=1){var f=e[s];void 0!==f&&s!==n&&(i|=a,u[o++]=f)}return new vt(t,i,u)}function Ot(t,e,r,n,i){for(var o=0,u=Array(vr),s=0;0!==r;s++,r>>>=1)u[s]=1&r?e[o++]:void 0;return u[n]=i,new lt(t,o+1,u)}function xt(t,e,n){for(var i=[],u=0;n.length>u;u++){var s=n[u],a=r(s);o(s)||(a=a.map(function(t){return H(t)})),i.push(a)}return jt(t,e,i)}function kt(t,e,r){return t&&t.mergeDeep&&o(e)?t.mergeDeep(e):X(t,e)?t:e}function At(t){return function(e,r,n){if(e&&e.mergeDeepWith&&o(r))return e.mergeDeepWith(t,r);var i=t(e,r,n);return X(e,i)?e:i}}function jt(t,e,r){return r=r.filter(function(t){return 0!==t.size}),0===r.length?t:0!==t.size||t.__ownerID||1!==r.length?t.withMutations(function(t){for(var n=e?function(r,n){t.update(n,yr,function(t){return t===yr?r:e(t,r,n)})}:function(e,r){t.set(r,e)},i=0;r.length>i;i++)r[i].forEach(n)}):t.constructor(r[0])}function Rt(t,e,r,n){var i=t===yr,o=e.next();if(o.done){var u=i?r:t,s=n(u);return s===u?t:s}Z(i||t&&t.set,"invalid keyPath");var a=o.value,h=i?yr:t.get(a,yr),f=Rt(h,e,r,n);return f===h?t:f===yr?t.remove(a):(i?zt():t).set(a,f)}function Ut(t){return t-=t>>1&1431655765,t=(858993459&t)+(t>>2&858993459),t=t+(t>>4)&252645135,t+=t>>8,t+=t>>16,127&t}function Kt(t,e,r,n){var i=n?t:p(t);return i[e]=r,i}function Lt(t,e,r,n){var i=t.length+1;if(n&&e+1===i)return t[e]=r,t;for(var o=Array(i),u=0,s=0;i>s;s++)s===e?(o[s]=r,u=-1):o[s]=t[s+u];return o}function Tt(t,e,r){var n=t.length-1;if(r&&e===n)return t.pop(),t;for(var i=Array(n),o=0,u=0;n>u;u++)u===e&&(o=1),i[u]=t[u+o];return i}function Bt(t){var e=Pt();if(null===t||void 0===t)return e;if(Wt(t))return t;var r=n(t),i=r.size;return 0===i?e:(ft(i),i>0&&vr>i?Nt(0,i,pr,null,new Ct(r.toArray())):e.withMutations(function(t){t.setSize(i),r.forEach(function(e,r){return t.set(r,e)})}))}function Wt(t){
|
||||
return!(!t||!t[Vr])}function Ct(t,e){this.array=t,this.ownerID=e}function Jt(t,e){function r(t,e,r){return 0===e?n(t,r):i(t,e,r)}function n(t,r){var n=r===s?a&&a.array:t&&t.array,i=r>o?0:o-r,h=u-r;return h>vr&&(h=vr),function(){if(i===h)return Xr;var t=e?--h:i++;return n&&n[t]}}function i(t,n,i){var s,a=t&&t.array,h=i>o?0:o-i>>n,f=(u-i>>n)+1;return f>vr&&(f=vr),function(){for(;;){if(s){var t=s();if(t!==Xr)return t;s=null}if(h===f)return Xr;var o=e?--f:h++;s=r(a&&a[o],n-pr,i+(o<<n))}}}var o=t._origin,u=t._capacity,s=Gt(u),a=t._tail;return r(t._root,t._level,0)}function Nt(t,e,r,n,i,o,u){var s=Object.create(Yr);return s.size=e-t,s._origin=t,s._capacity=e,s._level=r,s._root=n,s._tail=i,s.__ownerID=o,s.__hash=u,s.__altered=!1,s}function Pt(){return Qr||(Qr=Nt(0,0,pr))}function Ht(t,e,r){if(e=l(t,e),e!==e)return t;if(e>=t.size||0>e)return t.withMutations(function(t){0>e?Xt(t,e).set(0,r):Xt(t,0,e+1).set(e,r)});e+=t._origin;var n=t._tail,i=t._root,o=f(mr);return e>=Gt(t._capacity)?n=Vt(n,t.__ownerID,0,e,r,o):i=Vt(i,t.__ownerID,t._level,e,r,o),o.value?t.__ownerID?(t._root=i,t._tail=n,t.__hash=void 0,t.__altered=!0,t):Nt(t._origin,t._capacity,t._level,i,n):t}function Vt(t,e,r,n,i,o){var u=n>>>r&lr,s=t&&t.array.length>u;if(!s&&void 0===i)return t;var a;if(r>0){var h=t&&t.array[u],f=Vt(h,e,r-pr,n,i,o);return f===h?t:(a=Yt(t,e),a.array[u]=f,a)}return s&&t.array[u]===i?t:(c(o),a=Yt(t,e),void 0===i&&u===a.array.length-1?a.array.pop():a.array[u]=i,a)}function Yt(t,e){return e&&t&&e===t.ownerID?t:new Ct(t?t.array.slice():[],e)}function Qt(t,e){if(e>=Gt(t._capacity))return t._tail;if(1<<t._level+pr>e){for(var r=t._root,n=t._level;r&&n>0;)r=r.array[e>>>n&lr],n-=pr;return r}}function Xt(t,e,r){void 0!==e&&(e=0|e),void 0!==r&&(r=0|r);var n=t.__ownerID||new _,i=t._origin,o=t._capacity,u=i+e,s=void 0===r?o:0>r?o+r:i+r;if(u===i&&s===o)return t;if(u>=s)return t.clear();for(var a=t._level,h=t._root,f=0;0>u+f;)h=new Ct(h&&h.array.length?[void 0,h]:[],n),a+=pr,f+=1<<a;f&&(u+=f,i+=f,s+=f,o+=f);for(var c=Gt(o),p=Gt(s);p>=1<<a+pr;)h=new Ct(h&&h.array.length?[h]:[],n),
|
||||
a+=pr;var v=t._tail,l=c>p?Qt(t,s-1):p>c?new Ct([],n):v;if(v&&p>c&&o>u&&v.array.length){h=Yt(h,n);for(var y=h,d=a;d>pr;d-=pr){var m=c>>>d&lr;y=y.array[m]=Yt(y.array[m],n)}y.array[c>>>pr&lr]=v}if(o>s&&(l=l&&l.removeAfter(n,0,s)),u>=p)u-=p,s-=p,a=pr,h=null,l=l&&l.removeBefore(n,0,u);else if(u>i||c>p){for(f=0;h;){var g=u>>>a&lr;if(g!==p>>>a&lr)break;g&&(f+=(1<<a)*g),a-=pr,h=h.array[g]}h&&u>i&&(h=h.removeBefore(n,a,u-f)),h&&c>p&&(h=h.removeAfter(n,a,p-f)),f&&(u-=f,s-=f)}return t.__ownerID?(t.size=s-u,t._origin=u,t._capacity=s,t._level=a,t._root=h,t._tail=l,t.__hash=void 0,t.__altered=!0,t):Nt(u,s,a,h,l)}function Ft(t,e,r){for(var i=[],u=0,s=0;r.length>s;s++){var a=r[s],h=n(a);h.size>u&&(u=h.size),o(a)||(h=h.map(function(t){return H(t)})),i.push(h)}return u>t.size&&(t=t.setSize(u)),jt(t,e,i)}function Gt(t){return vr>t?0:t-1>>>pr<<pr}function Zt(t){return null===t||void 0===t?ee():$t(t)?t:ee().withMutations(function(e){var n=r(t);ft(n.size),n.forEach(function(t,r){return e.set(r,t)})})}function $t(t){return _t(t)&&h(t)}function te(t,e,r,n){var i=Object.create(Zt.prototype);return i.size=t?t.size:0,i._map=t,i._list=e,i.__ownerID=r,i.__hash=n,i}function ee(){return Fr||(Fr=te(zt(),Pt()))}function re(t,e,r){var n,i,o=t._map,u=t._list,s=o.get(e),a=void 0!==s;if(r===yr){if(!a)return t;u.size>=vr&&u.size>=2*o.size?(i=u.filter(function(t,e){return void 0!==t&&s!==e}),n=i.toKeyedSeq().map(function(t){return t[0]}).flip().toMap(),t.__ownerID&&(n.__ownerID=i.__ownerID=t.__ownerID)):(n=o.remove(e),i=s===u.size-1?u.pop():u.set(s,void 0))}else if(a){if(r===u.get(s)[1])return t;n=o,i=u.set(s,[e,r])}else n=o.set(e,u.size),i=u.set(u.size,[e,r]);return t.__ownerID?(t.size=n.size,t._map=n,t._list=i,t.__hash=void 0,t):te(n,i)}function ne(t,e){this._iter=t,this._useKeys=e,this.size=t.size}function ie(t){this._iter=t,this.size=t.size}function oe(t){this._iter=t,this.size=t.size}function ue(t){this._iter=t,this.size=t.size}function se(t){var e=Ee(t);return e._iter=t,e.size=t.size,e.flip=function(){return t},e.reverse=function(){var e=t.reverse.apply(this);
|
||||
return e.flip=function(){return t.reverse()},e},e.has=function(e){return t.includes(e)},e.includes=function(e){return t.has(e)},e.cacheResult=Oe,e.__iterateUncached=function(e,r){var n=this;return t.__iterate(function(t,r){return e(r,t,n)!==!1},r)},e.__iteratorUncached=function(e,r){if(e===Sr){var n=t.__iterator(e,r);return new S(function(){var t=n.next();if(!t.done){var e=t.value[0];t.value[0]=t.value[1],t.value[1]=e}return t})}return t.__iterator(e===wr?gr:wr,r)},e}function ae(t,e,r){var n=Ee(t);return n.size=t.size,n.has=function(e){return t.has(e)},n.get=function(n,i){var o=t.get(n,yr);return o===yr?i:e.call(r,o,n,t)},n.__iterateUncached=function(n,i){var o=this;return t.__iterate(function(t,i,u){return n(e.call(r,t,i,u),i,o)!==!1},i)},n.__iteratorUncached=function(n,i){var o=t.__iterator(Sr,i);return new S(function(){var i=o.next();if(i.done)return i;var u=i.value,s=u[0];return z(n,s,e.call(r,u[1],s,t),i)})},n}function he(t,e){var r=Ee(t);return r._iter=t,r.size=t.size,r.reverse=function(){return t},t.flip&&(r.flip=function(){var e=se(t);return e.reverse=function(){return t.flip()},e}),r.get=function(r,n){return t.get(e?r:-1-r,n)},r.has=function(r){return t.has(e?r:-1-r)},r.includes=function(e){return t.includes(e)},r.cacheResult=Oe,r.__iterate=function(e,r){var n=this;return t.__iterate(function(t,r){return e(t,r,n)},!r)},r.__iterator=function(e,r){return t.__iterator(e,!r)},r}function fe(t,e,r,n){var i=Ee(t);return n&&(i.has=function(n){var i=t.get(n,yr);return i!==yr&&!!e.call(r,i,n,t)},i.get=function(n,i){var o=t.get(n,yr);return o!==yr&&e.call(r,o,n,t)?o:i}),i.__iterateUncached=function(i,o){var u=this,s=0;return t.__iterate(function(t,o,a){return e.call(r,t,o,a)?(s++,i(t,n?o:s-1,u)):void 0},o),s},i.__iteratorUncached=function(i,o){var u=t.__iterator(Sr,o),s=0;return new S(function(){for(;;){var o=u.next();if(o.done)return o;var a=o.value,h=a[0],f=a[1];if(e.call(r,f,h,t))return z(i,n?h:s++,f,o)}})},i}function ce(t,e,r){var n=ct().asMutable();return t.__iterate(function(i,o){n.update(e.call(r,i,o,t),0,function(t){
|
||||
return t+1})}),n.asImmutable()}function _e(t,e,r){var n=u(t),i=(h(t)?Zt():ct()).asMutable();t.__iterate(function(o,u){i.update(e.call(r,o,u,t),function(t){return t=t||[],t.push(n?[u,o]:o),t})});var o=Me(t);return i.map(function(e){return be(t,o(e))})}function pe(t,e,r,n){var i=t.size;if(void 0!==e&&(e=0|e),void 0!==r&&(r=r===1/0?i:0|r),d(e,r,i))return t;var o=m(e,i),u=g(r,i);if(o!==o||u!==u)return pe(t.toSeq().cacheResult(),e,r,n);var s,a=u-o;a===a&&(s=0>a?0:a);var h=Ee(t);return h.size=0===s?s:t.size&&s||void 0,!n&&L(t)&&s>=0&&(h.get=function(e,r){return e=l(this,e),e>=0&&s>e?t.get(e+o,r):r}),h.__iterateUncached=function(e,r){var i=this;if(0===s)return 0;if(r)return this.cacheResult().__iterate(e,r);var u=0,a=!0,h=0;return t.__iterate(function(t,r){return a&&(a=u++<o)?void 0:(h++,e(t,n?r:h-1,i)!==!1&&h!==s)}),h},h.__iteratorUncached=function(e,r){if(0!==s&&r)return this.cacheResult().__iterator(e,r);var i=0!==s&&t.__iterator(e,r),u=0,a=0;return new S(function(){for(;u++<o;)i.next();if(++a>s)return I();var t=i.next();return n||e===wr?t:e===gr?z(e,a-1,void 0,t):z(e,a-1,t.value[1],t)})},h}function ve(t,e,r){var n=Ee(t);return n.__iterateUncached=function(n,i){var o=this;if(i)return this.cacheResult().__iterate(n,i);var u=0;return t.__iterate(function(t,i,s){return e.call(r,t,i,s)&&++u&&n(t,i,o)}),u},n.__iteratorUncached=function(n,i){var o=this;if(i)return this.cacheResult().__iterator(n,i);var u=t.__iterator(Sr,i),s=!0;return new S(function(){if(!s)return I();var t=u.next();if(t.done)return t;var i=t.value,a=i[0],h=i[1];return e.call(r,h,a,o)?n===Sr?t:z(n,a,h,t):(s=!1,I())})},n}function le(t,e,r,n){var i=Ee(t);return i.__iterateUncached=function(i,o){var u=this;if(o)return this.cacheResult().__iterate(i,o);var s=!0,a=0;return t.__iterate(function(t,o,h){return s&&(s=e.call(r,t,o,h))?void 0:(a++,i(t,n?o:a-1,u))}),a},i.__iteratorUncached=function(i,o){var u=this;if(o)return this.cacheResult().__iterator(i,o);var s=t.__iterator(Sr,o),a=!0,h=0;return new S(function(){var t,o,f;do{if(t=s.next(),t.done)return n||i===wr?t:i===gr?z(i,h++,void 0,t):z(i,h++,t.value[1],t);
|
||||
var c=t.value;o=c[0],f=c[1],a&&(a=e.call(r,f,o,u))}while(a);return i===Sr?t:z(i,o,f,t)})},i}function ye(t,e){var n=u(t),i=[t].concat(e).map(function(t){return o(t)?n&&(t=r(t)):t=n?B(t):W(Array.isArray(t)?t:[t]),t}).filter(function(t){return 0!==t.size});if(0===i.length)return t;if(1===i.length){var a=i[0];if(a===t||n&&u(a)||s(t)&&s(a))return a}var h=new j(i);return n?h=h.toKeyedSeq():s(t)||(h=h.toSetSeq()),h=h.flatten(!0),h.size=i.reduce(function(t,e){if(void 0!==t){var r=e.size;if(void 0!==r)return t+r}},0),h}function de(t,e,r){var n=Ee(t);return n.__iterateUncached=function(n,i){function u(t,h){var f=this;t.__iterate(function(t,i){return(!e||e>h)&&o(t)?u(t,h+1):n(t,r?i:s++,f)===!1&&(a=!0),!a},i)}var s=0,a=!1;return u(t,0),s},n.__iteratorUncached=function(n,i){var u=t.__iterator(n,i),s=[],a=0;return new S(function(){for(;u;){var t=u.next();if(t.done===!1){var h=t.value;if(n===Sr&&(h=h[1]),e&&!(e>s.length)||!o(h))return r?t:z(n,a++,h,t);s.push(u),u=h.__iterator(n,i)}else u=s.pop()}return I()})},n}function me(t,e,r){var n=Me(t);return t.toSeq().map(function(i,o){return n(e.call(r,i,o,t))}).flatten(!0)}function ge(t,e){var r=Ee(t);return r.size=t.size&&2*t.size-1,r.__iterateUncached=function(r,n){var i=this,o=0;return t.__iterate(function(t,n){return(!o||r(e,o++,i)!==!1)&&r(t,o++,i)!==!1},n),o},r.__iteratorUncached=function(r,n){var i,o=t.__iterator(wr,n),u=0;return new S(function(){return(!i||u%2)&&(i=o.next(),i.done)?i:u%2?z(r,u++,e):z(r,u++,i.value,i)})},r}function we(t,e,r){e||(e=xe);var n=u(t),i=0,o=t.toSeq().map(function(e,n){return[n,e,i++,r?r(e,n,t):e]}).toArray();return o.sort(function(t,r){return e(t[3],r[3])||t[2]-r[2]}).forEach(n?function(t,e){o[e].length=2}:function(t,e){o[e]=t[1]}),n?x(o):s(t)?k(o):A(o)}function Se(t,e,r){if(e||(e=xe),r){var n=t.toSeq().map(function(e,n){return[e,r(e,n,t)]}).reduce(function(t,r){return ze(e,t[1],r[1])?r:t});return n&&n[0]}return t.reduce(function(t,r){return ze(e,t,r)?r:t})}function ze(t,e,r){var n=t(r,e);return 0===n&&r!==e&&(void 0===r||null===r||r!==r)||n>0}function Ie(t,r,n){
|
||||
var i=Ee(t);return i.size=new j(n).map(function(t){return t.size}).min(),i.__iterate=function(t,e){for(var r,n=this.__iterator(wr,e),i=0;!(r=n.next()).done&&t(r.value,i++,this)!==!1;);return i},i.__iteratorUncached=function(t,i){var o=n.map(function(t){return t=e(t),D(i?t.reverse():t)}),u=0,s=!1;return new S(function(){var e;return s||(e=o.map(function(t){return t.next()}),s=e.some(function(t){return t.done})),s?I():z(t,u++,r.apply(null,e.map(function(t){return t.value})))})},i}function be(t,e){return L(t)?e:t.constructor(e)}function qe(t){if(t!==Object(t))throw new TypeError("Expected [K, V] tuple: "+t)}function De(t){return ft(t.size),v(t)}function Me(t){return u(t)?r:s(t)?n:i}function Ee(t){return Object.create((u(t)?x:s(t)?k:A).prototype)}function Oe(){return this._iter.cacheResult?(this._iter.cacheResult(),this.size=this._iter.size,this):O.prototype.cacheResult.call(this)}function xe(t,e){return t>e?1:e>t?-1:0}function ke(t){var r=D(t);if(!r){if(!E(t))throw new TypeError("Expected iterable or array-like: "+t);r=D(e(t))}return r}function Ae(t,e){var r,n=function(o){if(o instanceof n)return o;if(!(this instanceof n))return new n(o);if(!r){r=!0;var u=Object.keys(t);Ue(i,u),i.size=u.length,i._name=e,i._keys=u,i._defaultValues=t}this._map=ct(o)},i=n.prototype=Object.create(Gr);return i.constructor=n,n}function je(t,e,r){var n=Object.create(Object.getPrototypeOf(t));return n._map=e,n.__ownerID=r,n}function Re(t){return t._name||t.constructor.name||"Record"}function Ue(t,e){try{e.forEach(Ke.bind(void 0,t))}catch(r){}}function Ke(t,e){Object.defineProperty(t,e,{get:function(){return this.get(e)},set:function(t){Z(this.__ownerID,"Cannot set on an immutable record."),this.set(e,t)}})}function Le(t){return null===t||void 0===t?Ce():Te(t)&&!h(t)?t:Ce().withMutations(function(e){var r=i(t);ft(r.size),r.forEach(function(t){return e.add(t)})})}function Te(t){return!(!t||!t[Zr])}function Be(t,e){return t.__ownerID?(t.size=e.size,t._map=e,t):e===t._map?t:0===e.size?t.__empty():t.__make(e)}function We(t,e){var r=Object.create($r);
|
||||
return r.size=t?t.size:0,r._map=t,r.__ownerID=e,r}function Ce(){return tn||(tn=We(zt()))}function Je(t){return null===t||void 0===t?He():Ne(t)?t:He().withMutations(function(e){var r=i(t);ft(r.size),r.forEach(function(t){return e.add(t)})})}function Ne(t){return Te(t)&&h(t)}function Pe(t,e){var r=Object.create(en);return r.size=t?t.size:0,r._map=t,r.__ownerID=e,r}function He(){return rn||(rn=Pe(ee()))}function Ve(t){return null===t||void 0===t?Xe():Ye(t)?t:Xe().unshiftAll(t)}function Ye(t){return!(!t||!t[nn])}function Qe(t,e,r,n){var i=Object.create(on);return i.size=t,i._head=e,i.__ownerID=r,i.__hash=n,i.__altered=!1,i}function Xe(){return un||(un=Qe(0))}function Fe(t,e){var r=function(r){t.prototype[r]=e[r]};return Object.keys(e).forEach(r),Object.getOwnPropertySymbols&&Object.getOwnPropertySymbols(e).forEach(r),t}function Ge(t,e){return e}function Ze(t,e){return[e,t]}function $e(t){return function(){return!t.apply(this,arguments)}}function tr(t){return function(){return-t.apply(this,arguments)}}function er(t){return"string"==typeof t?JSON.stringify(t):t+""}function rr(){return p(arguments)}function nr(t,e){return e>t?1:t>e?-1:0}function ir(t){if(t.size===1/0)return 0;var e=h(t),r=u(t),n=e?1:0,i=t.__iterate(r?e?function(t,e){n=31*n+ur(ot(t),ot(e))|0}:function(t,e){n=n+ur(ot(t),ot(e))|0}:e?function(t){n=31*n+ot(t)|0}:function(t){n=n+ot(t)|0});return or(i,n)}function or(t,e){return e=xr(e,3432918353),e=xr(e<<15|e>>>-15,461845907),e=xr(e<<13|e>>>-13,5),e=(e+3864292196|0)^t,e=xr(e^e>>>16,2246822507),e=xr(e^e>>>13,3266489909),e=it(e^e>>>16)}function ur(t,e){return t^e+2654435769+(t<<6)+(t>>2)|0}var sr=Array.prototype.slice;t(r,e),t(n,e),t(i,e),e.isIterable=o,e.isKeyed=u,e.isIndexed=s,e.isAssociative=a,e.isOrdered=h,e.Keyed=r,e.Indexed=n,e.Set=i;var ar="@@__IMMUTABLE_ITERABLE__@@",hr="@@__IMMUTABLE_KEYED__@@",fr="@@__IMMUTABLE_INDEXED__@@",cr="@@__IMMUTABLE_ORDERED__@@",_r="delete",pr=5,vr=1<<pr,lr=vr-1,yr={},dr={value:!1},mr={value:!1},gr=0,wr=1,Sr=2,zr="function"==typeof Symbol&&Symbol.iterator,Ir="@@iterator",br=zr||Ir;
|
||||
S.prototype.toString=function(){return"[Iterator]"},S.KEYS=gr,S.VALUES=wr,S.ENTRIES=Sr,S.prototype.inspect=S.prototype.toSource=function(){return""+this},S.prototype[br]=function(){return this},t(O,e),O.of=function(){return O(arguments)},O.prototype.toSeq=function(){return this},O.prototype.toString=function(){return this.__toString("Seq {","}")},O.prototype.cacheResult=function(){return!this._cache&&this.__iterateUncached&&(this._cache=this.entrySeq().toArray(),this.size=this._cache.length),this},O.prototype.__iterate=function(t,e){return N(this,t,e,!0)},O.prototype.__iterator=function(t,e){return P(this,t,e,!0)},t(x,O),x.prototype.toKeyedSeq=function(){return this},t(k,O),k.of=function(){return k(arguments)},k.prototype.toIndexedSeq=function(){return this},k.prototype.toString=function(){return this.__toString("Seq [","]")},k.prototype.__iterate=function(t,e){return N(this,t,e,!1)},k.prototype.__iterator=function(t,e){return P(this,t,e,!1)},t(A,O),A.of=function(){return A(arguments)},A.prototype.toSetSeq=function(){return this},O.isSeq=L,O.Keyed=x,O.Set=A,O.Indexed=k;var qr="@@__IMMUTABLE_SEQ__@@";O.prototype[qr]=!0,t(j,k),j.prototype.get=function(t,e){return this.has(t)?this._array[l(this,t)]:e},j.prototype.__iterate=function(t,e){for(var r=this._array,n=r.length-1,i=0;n>=i;i++)if(t(r[e?n-i:i],i,this)===!1)return i+1;return i},j.prototype.__iterator=function(t,e){var r=this._array,n=r.length-1,i=0;return new S(function(){return i>n?I():z(t,i,r[e?n-i++:i++])})},t(R,x),R.prototype.get=function(t,e){return void 0===e||this.has(t)?this._object[t]:e},R.prototype.has=function(t){return this._object.hasOwnProperty(t)},R.prototype.__iterate=function(t,e){for(var r=this._object,n=this._keys,i=n.length-1,o=0;i>=o;o++){var u=n[e?i-o:o];if(t(r[u],u,this)===!1)return o+1}return o},R.prototype.__iterator=function(t,e){var r=this._object,n=this._keys,i=n.length-1,o=0;return new S(function(){var u=n[e?i-o:o];return o++>i?I():z(t,u,r[u])})},R.prototype[cr]=!0,t(U,k),U.prototype.__iterateUncached=function(t,e){if(e)return this.cacheResult().__iterate(t,e);
|
||||
var r=this._iterable,n=D(r),i=0;if(q(n))for(var o;!(o=n.next()).done&&t(o.value,i++,this)!==!1;);return i},U.prototype.__iteratorUncached=function(t,e){if(e)return this.cacheResult().__iterator(t,e);var r=this._iterable,n=D(r);if(!q(n))return new S(I);var i=0;return new S(function(){var e=n.next();return e.done?e:z(t,i++,e.value)})},t(K,k),K.prototype.__iterateUncached=function(t,e){if(e)return this.cacheResult().__iterate(t,e);for(var r=this._iterator,n=this._iteratorCache,i=0;n.length>i;)if(t(n[i],i++,this)===!1)return i;for(var o;!(o=r.next()).done;){var u=o.value;if(n[i]=u,t(u,i++,this)===!1)break}return i},K.prototype.__iteratorUncached=function(t,e){if(e)return this.cacheResult().__iterator(t,e);var r=this._iterator,n=this._iteratorCache,i=0;return new S(function(){if(i>=n.length){var e=r.next();if(e.done)return e;n[i]=e.value}return z(t,i,n[i++])})};var Dr;t(G,k),G.prototype.toString=function(){return 0===this.size?"Repeat []":"Repeat [ "+this._value+" "+this.size+" times ]"},G.prototype.get=function(t,e){return this.has(t)?this._value:e},G.prototype.includes=function(t){return X(this._value,t)},G.prototype.slice=function(t,e){var r=this.size;return d(t,e,r)?this:new G(this._value,g(e,r)-m(t,r))},G.prototype.reverse=function(){return this},G.prototype.indexOf=function(t){return X(this._value,t)?0:-1},G.prototype.lastIndexOf=function(t){return X(this._value,t)?this.size:-1},G.prototype.__iterate=function(t,e){for(var r=0;this.size>r;r++)if(t(this._value,r,this)===!1)return r+1;return r},G.prototype.__iterator=function(t,e){var r=this,n=0;return new S(function(){return r.size>n?z(t,n++,r._value):I()})},G.prototype.equals=function(t){return t instanceof G?X(this._value,t._value):F(t)};var Mr;t($,k),$.prototype.toString=function(){return 0===this.size?"Range []":"Range [ "+this._start+"..."+this._end+(1!==this._step?" by "+this._step:"")+" ]"},$.prototype.get=function(t,e){return this.has(t)?this._start+l(this,t)*this._step:e},$.prototype.includes=function(t){var e=(t-this._start)/this._step;return e>=0&&this.size>e&&e===Math.floor(e);
|
||||
},$.prototype.slice=function(t,e){return d(t,e,this.size)?this:(t=m(t,this.size),e=g(e,this.size),t>=e?new $(0,0):new $(this.get(t,this._end),this.get(e,this._end),this._step))},$.prototype.indexOf=function(t){var e=t-this._start;if(e%this._step===0){var r=e/this._step;if(r>=0&&this.size>r)return r}return-1},$.prototype.lastIndexOf=function(t){return this.indexOf(t)},$.prototype.__iterate=function(t,e){for(var r=this.size-1,n=this._step,i=e?this._start+r*n:this._start,o=0;r>=o;o++){if(t(i,o,this)===!1)return o+1;i+=e?-n:n}return o},$.prototype.__iterator=function(t,e){var r=this.size-1,n=this._step,i=e?this._start+r*n:this._start,o=0;return new S(function(){var u=i;return i+=e?-n:n,o>r?I():z(t,o++,u)})},$.prototype.equals=function(t){return t instanceof $?this._start===t._start&&this._end===t._end&&this._step===t._step:F(this,t)};var Er;t(tt,e),t(et,tt),t(rt,tt),t(nt,tt),tt.Keyed=et,tt.Indexed=rt,tt.Set=nt;var Or,xr="function"==typeof Math.imul&&-2===Math.imul(4294967295,2)?Math.imul:function(t,e){t=0|t,e=0|e;var r=65535&t,n=65535&e;return r*n+((t>>>16)*n+r*(e>>>16)<<16>>>0)|0},kr=Object.isExtensible,Ar=function(){try{return Object.defineProperty({},"@",{}),!0}catch(t){return!1}}(),jr="function"==typeof WeakMap;jr&&(Or=new WeakMap);var Rr=0,Ur="__immutablehash__";"function"==typeof Symbol&&(Ur=Symbol(Ur));var Kr=16,Lr=255,Tr=0,Br={};t(ct,et),ct.of=function(){var t=sr.call(arguments,0);return zt().withMutations(function(e){for(var r=0;t.length>r;r+=2){if(r+1>=t.length)throw Error("Missing value for key: "+t[r]);e.set(t[r],t[r+1])}})},ct.prototype.toString=function(){return this.__toString("Map {","}")},ct.prototype.get=function(t,e){return this._root?this._root.get(0,void 0,t,e):e},ct.prototype.set=function(t,e){return It(this,t,e)},ct.prototype.setIn=function(t,e){return this.updateIn(t,yr,function(){return e})},ct.prototype.remove=function(t){return It(this,t,yr)},ct.prototype.deleteIn=function(t){return this.updateIn(t,function(){return yr})},ct.prototype.update=function(t,e,r){return 1===arguments.length?t(this):this.updateIn([t],e,r);
|
||||
},ct.prototype.updateIn=function(t,e,r){r||(r=e,e=void 0);var n=Rt(this,ke(t),e,r);return n===yr?void 0:n},ct.prototype.clear=function(){return 0===this.size?this:this.__ownerID?(this.size=0,this._root=null,this.__hash=void 0,this.__altered=!0,this):zt()},ct.prototype.merge=function(){return xt(this,void 0,arguments)},ct.prototype.mergeWith=function(t){var e=sr.call(arguments,1);return xt(this,t,e)},ct.prototype.mergeIn=function(t){var e=sr.call(arguments,1);return this.updateIn(t,zt(),function(t){return"function"==typeof t.merge?t.merge.apply(t,e):e[e.length-1]})},ct.prototype.mergeDeep=function(){return xt(this,kt,arguments)},ct.prototype.mergeDeepWith=function(t){var e=sr.call(arguments,1);return xt(this,At(t),e)},ct.prototype.mergeDeepIn=function(t){var e=sr.call(arguments,1);return this.updateIn(t,zt(),function(t){return"function"==typeof t.mergeDeep?t.mergeDeep.apply(t,e):e[e.length-1]})},ct.prototype.sort=function(t){return Zt(we(this,t))},ct.prototype.sortBy=function(t,e){return Zt(we(this,e,t))},ct.prototype.withMutations=function(t){var e=this.asMutable();return t(e),e.wasAltered()?e.__ensureOwner(this.__ownerID):this},ct.prototype.asMutable=function(){return this.__ownerID?this:this.__ensureOwner(new _)},ct.prototype.asImmutable=function(){return this.__ensureOwner()},ct.prototype.wasAltered=function(){return this.__altered},ct.prototype.__iterator=function(t,e){return new mt(this,t,e)},ct.prototype.__iterate=function(t,e){var r=this,n=0;return this._root&&this._root.iterate(function(e){return n++,t(e[1],e[0],r)},e),n},ct.prototype.__ensureOwner=function(t){return t===this.__ownerID?this:t?St(this.size,this._root,t,this.__hash):(this.__ownerID=t,this.__altered=!1,this)},ct.isMap=_t;var Wr="@@__IMMUTABLE_MAP__@@",Cr=ct.prototype;Cr[Wr]=!0,Cr[_r]=Cr.remove,Cr.removeIn=Cr.deleteIn,pt.prototype.get=function(t,e,r,n){for(var i=this.entries,o=0,u=i.length;u>o;o++)if(X(r,i[o][0]))return i[o][1];return n},pt.prototype.update=function(t,e,r,n,i,o,u){for(var s=i===yr,a=this.entries,h=0,f=a.length;f>h&&!X(n,a[h][0]);h++);
|
||||
var _=f>h;if(_?a[h][1]===i:s)return this;if(c(u),(s||!_)&&c(o),!s||1!==a.length){if(!_&&!s&&a.length>=Nr)return Mt(t,a,n,i);var v=t&&t===this.ownerID,l=v?a:p(a);return _?s?h===f-1?l.pop():l[h]=l.pop():l[h]=[n,i]:l.push([n,i]),v?(this.entries=l,this):new pt(t,l)}},vt.prototype.get=function(t,e,r,n){void 0===e&&(e=ot(r));var i=1<<((0===t?e:e>>>t)&lr),o=this.bitmap;return 0===(o&i)?n:this.nodes[Ut(o&i-1)].get(t+pr,e,r,n)},vt.prototype.update=function(t,e,r,n,i,o,u){void 0===r&&(r=ot(n));var s=(0===e?r:r>>>e)&lr,a=1<<s,h=this.bitmap,f=0!==(h&a);if(!f&&i===yr)return this;var c=Ut(h&a-1),_=this.nodes,p=f?_[c]:void 0,v=bt(p,t,e+pr,r,n,i,o,u);if(v===p)return this;if(!f&&v&&_.length>=Pr)return Ot(t,_,h,s,v);if(f&&!v&&2===_.length&&qt(_[1^c]))return _[1^c];if(f&&v&&1===_.length&&qt(v))return v;var l=t&&t===this.ownerID,y=f?v?h:h^a:h|a,d=f?v?Kt(_,c,v,l):Tt(_,c,l):Lt(_,c,v,l);return l?(this.bitmap=y,this.nodes=d,this):new vt(t,y,d)},lt.prototype.get=function(t,e,r,n){void 0===e&&(e=ot(r));var i=(0===t?e:e>>>t)&lr,o=this.nodes[i];return o?o.get(t+pr,e,r,n):n},lt.prototype.update=function(t,e,r,n,i,o,u){void 0===r&&(r=ot(n));var s=(0===e?r:r>>>e)&lr,a=i===yr,h=this.nodes,f=h[s];if(a&&!f)return this;var c=bt(f,t,e+pr,r,n,i,o,u);if(c===f)return this;var _=this.count;if(f){if(!c&&(_--,Hr>_))return Et(t,h,_,s)}else _++;var p=t&&t===this.ownerID,v=Kt(h,s,c,p);return p?(this.count=_,this.nodes=v,this):new lt(t,_,v)},yt.prototype.get=function(t,e,r,n){for(var i=this.entries,o=0,u=i.length;u>o;o++)if(X(r,i[o][0]))return i[o][1];return n},yt.prototype.update=function(t,e,r,n,i,o,u){void 0===r&&(r=ot(n));var s=i===yr;if(r!==this.keyHash)return s?this:(c(u),c(o),Dt(this,t,e,r,[n,i]));for(var a=this.entries,h=0,f=a.length;f>h&&!X(n,a[h][0]);h++);var _=f>h;if(_?a[h][1]===i:s)return this;if(c(u),(s||!_)&&c(o),s&&2===f)return new dt(t,this.keyHash,a[1^h]);var v=t&&t===this.ownerID,l=v?a:p(a);return _?s?h===f-1?l.pop():l[h]=l.pop():l[h]=[n,i]:l.push([n,i]),v?(this.entries=l,this):new yt(t,this.keyHash,l)},dt.prototype.get=function(t,e,r,n){return X(r,this.entry[0])?this.entry[1]:n;
|
||||
},dt.prototype.update=function(t,e,r,n,i,o,u){var s=i===yr,a=X(n,this.entry[0]);return(a?i===this.entry[1]:s)?this:(c(u),s?void c(o):a?t&&t===this.ownerID?(this.entry[1]=i,this):new dt(t,this.keyHash,[n,i]):(c(o),Dt(this,t,e,ot(n),[n,i])))},pt.prototype.iterate=yt.prototype.iterate=function(t,e){for(var r=this.entries,n=0,i=r.length-1;i>=n;n++)if(t(r[e?i-n:n])===!1)return!1},vt.prototype.iterate=lt.prototype.iterate=function(t,e){for(var r=this.nodes,n=0,i=r.length-1;i>=n;n++){var o=r[e?i-n:n];if(o&&o.iterate(t,e)===!1)return!1}},dt.prototype.iterate=function(t,e){return t(this.entry)},t(mt,S),mt.prototype.next=function(){for(var t=this._type,e=this._stack;e;){var r,n=e.node,i=e.index++;if(n.entry){if(0===i)return gt(t,n.entry)}else if(n.entries){if(r=n.entries.length-1,r>=i)return gt(t,n.entries[this._reverse?r-i:i])}else if(r=n.nodes.length-1,r>=i){var o=n.nodes[this._reverse?r-i:i];if(o){if(o.entry)return gt(t,o.entry);e=this._stack=wt(o,e)}continue}e=this._stack=this._stack.__prev}return I()};var Jr,Nr=vr/4,Pr=vr/2,Hr=vr/4;t(Bt,rt),Bt.of=function(){return this(arguments)},Bt.prototype.toString=function(){return this.__toString("List [","]")},Bt.prototype.get=function(t,e){if(t=l(this,t),t>=0&&this.size>t){t+=this._origin;var r=Qt(this,t);return r&&r.array[t&lr]}return e},Bt.prototype.set=function(t,e){return Ht(this,t,e)},Bt.prototype.remove=function(t){return this.has(t)?0===t?this.shift():t===this.size-1?this.pop():this.splice(t,1):this},Bt.prototype.insert=function(t,e){return this.splice(t,0,e)},Bt.prototype.clear=function(){return 0===this.size?this:this.__ownerID?(this.size=this._origin=this._capacity=0,this._level=pr,this._root=this._tail=null,this.__hash=void 0,this.__altered=!0,this):Pt()},Bt.prototype.push=function(){var t=arguments,e=this.size;return this.withMutations(function(r){Xt(r,0,e+t.length);for(var n=0;t.length>n;n++)r.set(e+n,t[n])})},Bt.prototype.pop=function(){return Xt(this,0,-1)},Bt.prototype.unshift=function(){var t=arguments;return this.withMutations(function(e){Xt(e,-t.length);for(var r=0;t.length>r;r++)e.set(r,t[r]);
|
||||
})},Bt.prototype.shift=function(){return Xt(this,1)},Bt.prototype.merge=function(){return Ft(this,void 0,arguments)},Bt.prototype.mergeWith=function(t){var e=sr.call(arguments,1);return Ft(this,t,e)},Bt.prototype.mergeDeep=function(){return Ft(this,kt,arguments)},Bt.prototype.mergeDeepWith=function(t){var e=sr.call(arguments,1);return Ft(this,At(t),e)},Bt.prototype.setSize=function(t){return Xt(this,0,t)},Bt.prototype.slice=function(t,e){var r=this.size;return d(t,e,r)?this:Xt(this,m(t,r),g(e,r))},Bt.prototype.__iterator=function(t,e){var r=0,n=Jt(this,e);return new S(function(){var e=n();return e===Xr?I():z(t,r++,e)})},Bt.prototype.__iterate=function(t,e){for(var r,n=0,i=Jt(this,e);(r=i())!==Xr&&t(r,n++,this)!==!1;);return n},Bt.prototype.__ensureOwner=function(t){return t===this.__ownerID?this:t?Nt(this._origin,this._capacity,this._level,this._root,this._tail,t,this.__hash):(this.__ownerID=t,this)},Bt.isList=Wt;var Vr="@@__IMMUTABLE_LIST__@@",Yr=Bt.prototype;Yr[Vr]=!0,Yr[_r]=Yr.remove,Yr.setIn=Cr.setIn,Yr.deleteIn=Yr.removeIn=Cr.removeIn,Yr.update=Cr.update,Yr.updateIn=Cr.updateIn,Yr.mergeIn=Cr.mergeIn,Yr.mergeDeepIn=Cr.mergeDeepIn,Yr.withMutations=Cr.withMutations,Yr.asMutable=Cr.asMutable,Yr.asImmutable=Cr.asImmutable,Yr.wasAltered=Cr.wasAltered,Ct.prototype.removeBefore=function(t,e,r){if(r===e?1<<e:0===this.array.length)return this;var n=r>>>e&lr;if(n>=this.array.length)return new Ct([],t);var i,o=0===n;if(e>0){var u=this.array[n];if(i=u&&u.removeBefore(t,e-pr,r),i===u&&o)return this}if(o&&!i)return this;var s=Yt(this,t);if(!o)for(var a=0;n>a;a++)s.array[a]=void 0;return i&&(s.array[n]=i),s},Ct.prototype.removeAfter=function(t,e,r){if(r===(e?1<<e:0)||0===this.array.length)return this;var n=r-1>>>e&lr;if(n>=this.array.length)return this;var i;if(e>0){var o=this.array[n];if(i=o&&o.removeAfter(t,e-pr,r),i===o&&n===this.array.length-1)return this}var u=Yt(this,t);return u.array.splice(n+1),i&&(u.array[n]=i),u};var Qr,Xr={};t(Zt,ct),Zt.of=function(){return this(arguments)},Zt.prototype.toString=function(){return this.__toString("OrderedMap {","}");
|
||||
},Zt.prototype.get=function(t,e){var r=this._map.get(t);return void 0!==r?this._list.get(r)[1]:e},Zt.prototype.clear=function(){return 0===this.size?this:this.__ownerID?(this.size=0,this._map.clear(),this._list.clear(),this):ee()},Zt.prototype.set=function(t,e){return re(this,t,e)},Zt.prototype.remove=function(t){return re(this,t,yr)},Zt.prototype.wasAltered=function(){return this._map.wasAltered()||this._list.wasAltered()},Zt.prototype.__iterate=function(t,e){var r=this;return this._list.__iterate(function(e){return e&&t(e[1],e[0],r)},e)},Zt.prototype.__iterator=function(t,e){return this._list.fromEntrySeq().__iterator(t,e)},Zt.prototype.__ensureOwner=function(t){if(t===this.__ownerID)return this;var e=this._map.__ensureOwner(t),r=this._list.__ensureOwner(t);return t?te(e,r,t,this.__hash):(this.__ownerID=t,this._map=e,this._list=r,this)},Zt.isOrderedMap=$t,Zt.prototype[cr]=!0,Zt.prototype[_r]=Zt.prototype.remove;var Fr;t(ne,x),ne.prototype.get=function(t,e){return this._iter.get(t,e)},ne.prototype.has=function(t){return this._iter.has(t)},ne.prototype.valueSeq=function(){return this._iter.valueSeq()},ne.prototype.reverse=function(){var t=this,e=he(this,!0);return this._useKeys||(e.valueSeq=function(){return t._iter.toSeq().reverse()}),e},ne.prototype.map=function(t,e){var r=this,n=ae(this,t,e);return this._useKeys||(n.valueSeq=function(){return r._iter.toSeq().map(t,e)}),n},ne.prototype.__iterate=function(t,e){var r,n=this;return this._iter.__iterate(this._useKeys?function(e,r){return t(e,r,n)}:(r=e?De(this):0,function(i){return t(i,e?--r:r++,n)}),e)},ne.prototype.__iterator=function(t,e){if(this._useKeys)return this._iter.__iterator(t,e);var r=this._iter.__iterator(wr,e),n=e?De(this):0;return new S(function(){var i=r.next();return i.done?i:z(t,e?--n:n++,i.value,i)})},ne.prototype[cr]=!0,t(ie,k),ie.prototype.includes=function(t){return this._iter.includes(t)},ie.prototype.__iterate=function(t,e){var r=this,n=0;return this._iter.__iterate(function(e){return t(e,n++,r)},e)},ie.prototype.__iterator=function(t,e){var r=this._iter.__iterator(wr,e),n=0;
|
||||
return new S(function(){var e=r.next();return e.done?e:z(t,n++,e.value,e)})},t(oe,A),oe.prototype.has=function(t){return this._iter.includes(t)},oe.prototype.__iterate=function(t,e){var r=this;return this._iter.__iterate(function(e){return t(e,e,r)},e)},oe.prototype.__iterator=function(t,e){var r=this._iter.__iterator(wr,e);return new S(function(){var e=r.next();return e.done?e:z(t,e.value,e.value,e)})},t(ue,x),ue.prototype.entrySeq=function(){return this._iter.toSeq()},ue.prototype.__iterate=function(t,e){var r=this;return this._iter.__iterate(function(e){if(e){qe(e);var n=o(e);return t(n?e.get(1):e[1],n?e.get(0):e[0],r)}},e)},ue.prototype.__iterator=function(t,e){var r=this._iter.__iterator(wr,e);return new S(function(){for(;;){var e=r.next();if(e.done)return e;var n=e.value;if(n){qe(n);var i=o(n);return z(t,i?n.get(0):n[0],i?n.get(1):n[1],e)}}})},ie.prototype.cacheResult=ne.prototype.cacheResult=oe.prototype.cacheResult=ue.prototype.cacheResult=Oe,t(Ae,et),Ae.prototype.toString=function(){return this.__toString(Re(this)+" {","}")},Ae.prototype.has=function(t){return this._defaultValues.hasOwnProperty(t)},Ae.prototype.get=function(t,e){if(!this.has(t))return e;var r=this._defaultValues[t];return this._map?this._map.get(t,r):r},Ae.prototype.clear=function(){if(this.__ownerID)return this._map&&this._map.clear(),this;var t=this.constructor;return t._empty||(t._empty=je(this,zt()))},Ae.prototype.set=function(t,e){if(!this.has(t))throw Error('Cannot set unknown key "'+t+'" on '+Re(this));if(this._map&&!this._map.has(t)){var r=this._defaultValues[t];if(e===r)return this}var n=this._map&&this._map.set(t,e);return this.__ownerID||n===this._map?this:je(this,n)},Ae.prototype.remove=function(t){if(!this.has(t))return this;var e=this._map&&this._map.remove(t);return this.__ownerID||e===this._map?this:je(this,e)},Ae.prototype.wasAltered=function(){return this._map.wasAltered()},Ae.prototype.__iterator=function(t,e){var n=this;return r(this._defaultValues).map(function(t,e){return n.get(e)}).__iterator(t,e)},Ae.prototype.__iterate=function(t,e){
|
||||
var n=this;return r(this._defaultValues).map(function(t,e){return n.get(e)}).__iterate(t,e)},Ae.prototype.__ensureOwner=function(t){if(t===this.__ownerID)return this;var e=this._map&&this._map.__ensureOwner(t);return t?je(this,e,t):(this.__ownerID=t,this._map=e,this)};var Gr=Ae.prototype;Gr[_r]=Gr.remove,Gr.deleteIn=Gr.removeIn=Cr.removeIn,Gr.merge=Cr.merge,Gr.mergeWith=Cr.mergeWith,Gr.mergeIn=Cr.mergeIn,Gr.mergeDeep=Cr.mergeDeep,Gr.mergeDeepWith=Cr.mergeDeepWith,Gr.mergeDeepIn=Cr.mergeDeepIn,Gr.setIn=Cr.setIn,Gr.update=Cr.update,Gr.updateIn=Cr.updateIn,Gr.withMutations=Cr.withMutations,Gr.asMutable=Cr.asMutable,Gr.asImmutable=Cr.asImmutable,t(Le,nt),Le.of=function(){return this(arguments)},Le.fromKeys=function(t){return this(r(t).keySeq())},Le.prototype.toString=function(){return this.__toString("Set {","}")},Le.prototype.has=function(t){return this._map.has(t)},Le.prototype.add=function(t){return Be(this,this._map.set(t,!0))},Le.prototype.remove=function(t){return Be(this,this._map.remove(t))},Le.prototype.clear=function(){return Be(this,this._map.clear())},Le.prototype.union=function(){var t=sr.call(arguments,0);return t=t.filter(function(t){return 0!==t.size}),0===t.length?this:0!==this.size||this.__ownerID||1!==t.length?this.withMutations(function(e){for(var r=0;t.length>r;r++)i(t[r]).forEach(function(t){return e.add(t)})}):this.constructor(t[0])},Le.prototype.intersect=function(){var t=sr.call(arguments,0);if(0===t.length)return this;t=t.map(function(t){return i(t)});var e=this;return this.withMutations(function(r){e.forEach(function(e){t.every(function(t){return t.includes(e)})||r.remove(e)})})},Le.prototype.subtract=function(){var t=sr.call(arguments,0);if(0===t.length)return this;t=t.map(function(t){return i(t)});var e=this;return this.withMutations(function(r){e.forEach(function(e){t.some(function(t){return t.includes(e)})&&r.remove(e)})})},Le.prototype.merge=function(){return this.union.apply(this,arguments)},Le.prototype.mergeWith=function(t){var e=sr.call(arguments,1);return this.union.apply(this,e)},
|
||||
Le.prototype.sort=function(t){return Je(we(this,t))},Le.prototype.sortBy=function(t,e){return Je(we(this,e,t))},Le.prototype.wasAltered=function(){return this._map.wasAltered()},Le.prototype.__iterate=function(t,e){var r=this;return this._map.__iterate(function(e,n){return t(n,n,r)},e)},Le.prototype.__iterator=function(t,e){return this._map.map(function(t,e){return e}).__iterator(t,e)},Le.prototype.__ensureOwner=function(t){if(t===this.__ownerID)return this;var e=this._map.__ensureOwner(t);return t?this.__make(e,t):(this.__ownerID=t,this._map=e,this)},Le.isSet=Te;var Zr="@@__IMMUTABLE_SET__@@",$r=Le.prototype;$r[Zr]=!0,$r[_r]=$r.remove,$r.mergeDeep=$r.merge,$r.mergeDeepWith=$r.mergeWith,$r.withMutations=Cr.withMutations,$r.asMutable=Cr.asMutable,$r.asImmutable=Cr.asImmutable,$r.__empty=Ce,$r.__make=We;var tn;t(Je,Le),Je.of=function(){return this(arguments)},Je.fromKeys=function(t){return this(r(t).keySeq())},Je.prototype.toString=function(){return this.__toString("OrderedSet {","}")},Je.isOrderedSet=Ne;var en=Je.prototype;en[cr]=!0,en.__empty=He,en.__make=Pe;var rn;t(Ve,rt),Ve.of=function(){return this(arguments)},Ve.prototype.toString=function(){return this.__toString("Stack [","]")},Ve.prototype.get=function(t,e){var r=this._head;for(t=l(this,t);r&&t--;)r=r.next;return r?r.value:e},Ve.prototype.peek=function(){return this._head&&this._head.value},Ve.prototype.push=function(){if(0===arguments.length)return this;for(var t=this.size+arguments.length,e=this._head,r=arguments.length-1;r>=0;r--)e={value:arguments[r],next:e};return this.__ownerID?(this.size=t,this._head=e,this.__hash=void 0,this.__altered=!0,this):Qe(t,e)},Ve.prototype.pushAll=function(t){if(t=n(t),0===t.size)return this;ft(t.size);var e=this.size,r=this._head;return t.reverse().forEach(function(t){e++,r={value:t,next:r}}),this.__ownerID?(this.size=e,this._head=r,this.__hash=void 0,this.__altered=!0,this):Qe(e,r)},Ve.prototype.pop=function(){return this.slice(1)},Ve.prototype.unshift=function(){return this.push.apply(this,arguments)},Ve.prototype.unshiftAll=function(t){
|
||||
return this.pushAll(t)},Ve.prototype.shift=function(){return this.pop.apply(this,arguments)},Ve.prototype.clear=function(){return 0===this.size?this:this.__ownerID?(this.size=0,this._head=void 0,this.__hash=void 0,this.__altered=!0,this):Xe()},Ve.prototype.slice=function(t,e){if(d(t,e,this.size))return this;var r=m(t,this.size),n=g(e,this.size);if(n!==this.size)return rt.prototype.slice.call(this,t,e);for(var i=this.size-r,o=this._head;r--;)o=o.next;return this.__ownerID?(this.size=i,this._head=o,this.__hash=void 0,this.__altered=!0,this):Qe(i,o)},Ve.prototype.__ensureOwner=function(t){return t===this.__ownerID?this:t?Qe(this.size,this._head,t,this.__hash):(this.__ownerID=t,this.__altered=!1,this)},Ve.prototype.__iterate=function(t,e){if(e)return this.reverse().__iterate(t);for(var r=0,n=this._head;n&&t(n.value,r++,this)!==!1;)n=n.next;return r},Ve.prototype.__iterator=function(t,e){if(e)return this.reverse().__iterator(t);var r=0,n=this._head;return new S(function(){if(n){var e=n.value;return n=n.next,z(t,r++,e)}return I()})},Ve.isStack=Ye;var nn="@@__IMMUTABLE_STACK__@@",on=Ve.prototype;on[nn]=!0,on.withMutations=Cr.withMutations,on.asMutable=Cr.asMutable,on.asImmutable=Cr.asImmutable,on.wasAltered=Cr.wasAltered;var un;e.Iterator=S,Fe(e,{toArray:function(){ft(this.size);var t=Array(this.size||0);return this.valueSeq().__iterate(function(e,r){t[r]=e}),t},toIndexedSeq:function(){return new ie(this)},toJS:function(){return this.toSeq().map(function(t){return t&&"function"==typeof t.toJS?t.toJS():t}).__toJS()},toJSON:function(){return this.toSeq().map(function(t){return t&&"function"==typeof t.toJSON?t.toJSON():t}).__toJS()},toKeyedSeq:function(){return new ne(this,!0)},toMap:function(){return ct(this.toKeyedSeq())},toObject:function(){ft(this.size);var t={};return this.__iterate(function(e,r){t[r]=e}),t},toOrderedMap:function(){return Zt(this.toKeyedSeq())},toOrderedSet:function(){return Je(u(this)?this.valueSeq():this)},toSet:function(){return Le(u(this)?this.valueSeq():this)},toSetSeq:function(){return new oe(this);
|
||||
},toSeq:function(){return s(this)?this.toIndexedSeq():u(this)?this.toKeyedSeq():this.toSetSeq()},toStack:function(){return Ve(u(this)?this.valueSeq():this)},toList:function(){return Bt(u(this)?this.valueSeq():this)},toString:function(){return"[Iterable]"},__toString:function(t,e){return 0===this.size?t+e:t+" "+this.toSeq().map(this.__toStringMapper).join(", ")+" "+e},concat:function(){var t=sr.call(arguments,0);return be(this,ye(this,t))},includes:function(t){return this.some(function(e){return X(e,t)})},entries:function(){return this.__iterator(Sr)},every:function(t,e){ft(this.size);var r=!0;return this.__iterate(function(n,i,o){return t.call(e,n,i,o)?void 0:(r=!1,!1)}),r},filter:function(t,e){return be(this,fe(this,t,e,!0))},find:function(t,e,r){var n=this.findEntry(t,e);return n?n[1]:r},forEach:function(t,e){return ft(this.size),this.__iterate(e?t.bind(e):t)},join:function(t){ft(this.size),t=void 0!==t?""+t:",";var e="",r=!0;return this.__iterate(function(n){r?r=!1:e+=t,e+=null!==n&&void 0!==n?""+n:""}),e},keys:function(){return this.__iterator(gr)},map:function(t,e){return be(this,ae(this,t,e))},reduce:function(t,e,r){ft(this.size);var n,i;return arguments.length<2?i=!0:n=e,this.__iterate(function(e,o,u){i?(i=!1,n=e):n=t.call(r,n,e,o,u)}),n},reduceRight:function(t,e,r){var n=this.toKeyedSeq().reverse();return n.reduce.apply(n,arguments)},reverse:function(){return be(this,he(this,!0))},slice:function(t,e){return be(this,pe(this,t,e,!0))},some:function(t,e){return!this.every($e(t),e)},sort:function(t){return be(this,we(this,t))},values:function(){return this.__iterator(wr)},butLast:function(){return this.slice(0,-1)},isEmpty:function(){return void 0!==this.size?0===this.size:!this.some(function(){return!0})},count:function(t,e){return v(t?this.toSeq().filter(t,e):this)},countBy:function(t,e){return ce(this,t,e)},equals:function(t){return F(this,t)},entrySeq:function(){var t=this;if(t._cache)return new j(t._cache);var e=t.toSeq().map(Ze).toIndexedSeq();return e.fromEntrySeq=function(){return t.toSeq()},e},filterNot:function(t,e){
|
||||
return this.filter($e(t),e)},findEntry:function(t,e,r){var n=r;return this.__iterate(function(r,i,o){return t.call(e,r,i,o)?(n=[i,r],!1):void 0}),n},findKey:function(t,e){var r=this.findEntry(t,e);return r&&r[0]},findLast:function(t,e,r){return this.toKeyedSeq().reverse().find(t,e,r)},findLastEntry:function(t,e,r){return this.toKeyedSeq().reverse().findEntry(t,e,r)},findLastKey:function(t,e){return this.toKeyedSeq().reverse().findKey(t,e)},first:function(){return this.find(y)},flatMap:function(t,e){return be(this,me(this,t,e))},flatten:function(t){return be(this,de(this,t,!0))},fromEntrySeq:function(){return new ue(this)},get:function(t,e){return this.find(function(e,r){return X(r,t)},void 0,e)},getIn:function(t,e){for(var r,n=this,i=ke(t);!(r=i.next()).done;){var o=r.value;if(n=n&&n.get?n.get(o,yr):yr,n===yr)return e}return n},groupBy:function(t,e){return _e(this,t,e)},has:function(t){return this.get(t,yr)!==yr},hasIn:function(t){return this.getIn(t,yr)!==yr},isSubset:function(t){return t="function"==typeof t.includes?t:e(t),this.every(function(e){return t.includes(e)})},isSuperset:function(t){return t="function"==typeof t.isSubset?t:e(t),t.isSubset(this)},keyOf:function(t){return this.findKey(function(e){return X(e,t)})},keySeq:function(){return this.toSeq().map(Ge).toIndexedSeq()},last:function(){return this.toSeq().reverse().first()},lastKeyOf:function(t){return this.toKeyedSeq().reverse().keyOf(t)},max:function(t){return Se(this,t)},maxBy:function(t,e){return Se(this,e,t)},min:function(t){return Se(this,t?tr(t):nr)},minBy:function(t,e){return Se(this,e?tr(e):nr,t)},rest:function(){return this.slice(1)},skip:function(t){return this.slice(Math.max(0,t))},skipLast:function(t){return be(this,this.toSeq().reverse().skip(t).reverse())},skipWhile:function(t,e){return be(this,le(this,t,e,!0))},skipUntil:function(t,e){return this.skipWhile($e(t),e)},sortBy:function(t,e){return be(this,we(this,e,t))},take:function(t){return this.slice(0,Math.max(0,t))},takeLast:function(t){return be(this,this.toSeq().reverse().take(t).reverse());
|
||||
},takeWhile:function(t,e){return be(this,ve(this,t,e))},takeUntil:function(t,e){return this.takeWhile($e(t),e)},valueSeq:function(){return this.toIndexedSeq()},hashCode:function(){return this.__hash||(this.__hash=ir(this))}});var sn=e.prototype;sn[ar]=!0,sn[br]=sn.values,sn.__toJS=sn.toArray,sn.__toStringMapper=er,sn.inspect=sn.toSource=function(){return""+this},sn.chain=sn.flatMap,sn.contains=sn.includes,Fe(r,{flip:function(){return be(this,se(this))},mapEntries:function(t,e){var r=this,n=0;return be(this,this.toSeq().map(function(i,o){return t.call(e,[o,i],n++,r)}).fromEntrySeq())},mapKeys:function(t,e){var r=this;return be(this,this.toSeq().flip().map(function(n,i){return t.call(e,n,i,r)}).flip())}});var an=r.prototype;an[hr]=!0,an[br]=sn.entries,an.__toJS=sn.toObject,an.__toStringMapper=function(t,e){return JSON.stringify(e)+": "+er(t)},Fe(n,{toKeyedSeq:function(){return new ne(this,!1)},filter:function(t,e){return be(this,fe(this,t,e,!1))},findIndex:function(t,e){var r=this.findEntry(t,e);return r?r[0]:-1},indexOf:function(t){var e=this.keyOf(t);return void 0===e?-1:e},lastIndexOf:function(t){var e=this.lastKeyOf(t);return void 0===e?-1:e},reverse:function(){return be(this,he(this,!1))},slice:function(t,e){return be(this,pe(this,t,e,!1))},splice:function(t,e){var r=arguments.length;if(e=Math.max(0|e,0),0===r||2===r&&!e)return this;t=m(t,0>t?this.count():this.size);var n=this.slice(0,t);return be(this,1===r?n:n.concat(p(arguments,2),this.slice(t+e)))},findLastIndex:function(t,e){var r=this.findLastEntry(t,e);return r?r[0]:-1},first:function(){return this.get(0)},flatten:function(t){return be(this,de(this,t,!1))},get:function(t,e){return t=l(this,t),0>t||this.size===1/0||void 0!==this.size&&t>this.size?e:this.find(function(e,r){return r===t},void 0,e)},has:function(t){return t=l(this,t),t>=0&&(void 0!==this.size?this.size===1/0||this.size>t:-1!==this.indexOf(t))},interpose:function(t){return be(this,ge(this,t))},interleave:function(){var t=[this].concat(p(arguments)),e=Ie(this.toSeq(),k.of,t),r=e.flatten(!0);return e.size&&(r.size=e.size*t.length),
|
||||
be(this,r)},keySeq:function(){return $(0,this.size)},last:function(){return this.get(-1)},skipWhile:function(t,e){return be(this,le(this,t,e,!1))},zip:function(){var t=[this].concat(p(arguments));return be(this,Ie(this,rr,t))},zipWith:function(t){var e=p(arguments);return e[0]=this,be(this,Ie(this,t,e))}}),n.prototype[fr]=!0,n.prototype[cr]=!0,Fe(i,{get:function(t,e){return this.has(t)?t:e},includes:function(t){return this.has(t)},keySeq:function(){return this.valueSeq()}}),i.prototype.has=sn.includes,i.prototype.contains=i.prototype.includes,Fe(x,r.prototype),Fe(k,n.prototype),Fe(A,i.prototype),Fe(et,r.prototype),Fe(rt,n.prototype),Fe(nt,i.prototype);var hn={Iterable:e,Seq:O,Collection:tt,Map:ct,OrderedMap:Zt,List:Bt,Stack:Ve,Set:Le,OrderedSet:Je,Record:Ae,Range:$,Repeat:G,is:X,fromJS:H};return hn});
|
||||
@@ -7,8 +7,20 @@ var redoc = document.createElement("redoc");
|
||||
var redocSettings = JSON.parse(document.getElementById('redoc-settings').innerHTML);
|
||||
if (redocSettings.url) {
|
||||
specURL = redocSettings.url;
|
||||
delete redocSettings.url;
|
||||
}
|
||||
delete redocSettings.url;
|
||||
if (redocSettings.fetchSchemaWithQuery) {
|
||||
var query = new URLSearchParams(window.location.search || '').entries();
|
||||
var url = specURL.split('?');
|
||||
var usp = new URLSearchParams(url[1] || '');
|
||||
for (var it = query.next(); !it.done; it = query.next()) {
|
||||
usp.set(it.value[0], it.value[1]);
|
||||
}
|
||||
url[1] = usp.toString();
|
||||
specURL = url[1] ? url.join('?') : url[0];
|
||||
}
|
||||
delete redocSettings.fetchSchemaWithQuery;
|
||||
|
||||
redoc.setAttribute("spec-url", specURL);
|
||||
|
||||
function camelToKebab(str) {
|
||||
@@ -23,7 +35,7 @@ for (var p in redocSettings) {
|
||||
}
|
||||
}
|
||||
|
||||
document.body.appendChild(redoc);
|
||||
document.body.replaceChild(redoc, document.getElementById('redoc-placeholder'));
|
||||
|
||||
function hideEmptyVersion() {
|
||||
// 'span.api-info-version' is for redoc 1.x, 'div.api-info span' is for redoc 2-alpha
|
||||
@@ -36,8 +48,8 @@ function hideEmptyVersion() {
|
||||
var versionString = apiVersion.innerText;
|
||||
if (versionString) {
|
||||
// trim spaces and surrounding ()
|
||||
versionString = versionString.replace(/ /g,'');
|
||||
versionString = versionString.replace(/(^\()|(\)$)/g,'');
|
||||
versionString = versionString.replace(/ /g, '');
|
||||
versionString = versionString.replace(/(^\()|(\)$)/g, '');
|
||||
}
|
||||
|
||||
if (!versionString) {
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 4.9 KiB |
+41
-33
File diff suppressed because one or more lines are too long
Binary file not shown.
|
Before Width: | Height: | Size: 445 B |
Binary file not shown.
|
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.6 KiB |
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
@@ -1,27 +1,63 @@
|
||||
"use strict";
|
||||
var currentPath = window.location.protocol + "//" + window.location.host + window.location.pathname;
|
||||
var specURL = currentPath + '?format=openapi';
|
||||
var defaultSpecUrl = currentPath + '?format=openapi';
|
||||
|
||||
function slugify(text) {
|
||||
return text.toString().toLowerCase()
|
||||
.replace(/\s+/g, '-') // Replace spaces with -
|
||||
.replace(/[^\w\-]+/g, '') // Remove all non-word chars
|
||||
.replace(/--+/g, '-') // Replace multiple - with single -
|
||||
.replace(/^-+/, '') // Trim - from start of text
|
||||
.replace(/-+$/, ''); // Trim - from end of text
|
||||
}
|
||||
|
||||
var KEY_AUTH = slugify(window.location.pathname) + "-drf-yasg-auth";
|
||||
|
||||
// load the saved authorization state from localStorage; ImmutableJS is used for consistency with swagger-ui state
|
||||
var savedAuth = Immutable.fromJS({});
|
||||
|
||||
// global SwaggerUI config object; can be changed directly or by hooking initSwaggerUiConfig
|
||||
var swaggerUiConfig = {
|
||||
url: defaultSpecUrl,
|
||||
dom_id: '#swagger-ui',
|
||||
displayRequestDuration: true,
|
||||
presets: [
|
||||
SwaggerUIBundle.presets.apis,
|
||||
SwaggerUIStandalonePreset
|
||||
],
|
||||
plugins: [
|
||||
SwaggerUIBundle.plugins.DownloadUrl
|
||||
],
|
||||
layout: "StandaloneLayout",
|
||||
filter: true,
|
||||
requestInterceptor: function (request) {
|
||||
var headers = request.headers || {};
|
||||
var csrftoken = document.querySelector("[name=csrfmiddlewaretoken]");
|
||||
if (csrftoken) {
|
||||
headers["X-CSRFToken"] = csrftoken.value;
|
||||
}
|
||||
|
||||
return request;
|
||||
}
|
||||
};
|
||||
|
||||
function patchSwaggerUi() {
|
||||
if (document.querySelector('.auth-wrapper #django-session-auth')) {
|
||||
return;
|
||||
}
|
||||
|
||||
var authWrapper = document.querySelector('.auth-wrapper');
|
||||
var authorizeButton = document.querySelector('.auth-wrapper .authorize');
|
||||
var djangoSessionAuth = document.querySelector('#django-session-auth');
|
||||
|
||||
if (!djangoSessionAuth) {
|
||||
console.log("WARNING: session auth disabled");
|
||||
return;
|
||||
}
|
||||
|
||||
if (document.querySelector('.auth-wrapper #django-session-auth')) {
|
||||
console.log("WARNING: session auth already patched; skipping patchSwaggerUi()");
|
||||
return;
|
||||
}
|
||||
|
||||
djangoSessionAuth = djangoSessionAuth.cloneNode(true);
|
||||
authWrapper.insertBefore(djangoSessionAuth, authorizeButton);
|
||||
djangoSessionAuth.classList.remove("hidden");
|
||||
|
||||
var divider = document.createElement("div");
|
||||
divider.classList.add("divider");
|
||||
authWrapper.insertBefore(divider, authorizeButton);
|
||||
}
|
||||
|
||||
function initSwaggerUi() {
|
||||
@@ -29,58 +65,321 @@ function initSwaggerUi() {
|
||||
console.log("WARNING: skipping initSwaggerUi() because window.ui is already defined");
|
||||
return;
|
||||
}
|
||||
var swaggerConfig = {
|
||||
url: specURL,
|
||||
dom_id: '#swagger-ui',
|
||||
displayRequestDuration: true,
|
||||
presets: [
|
||||
SwaggerUIBundle.presets.apis,
|
||||
SwaggerUIStandalonePreset
|
||||
],
|
||||
plugins: [
|
||||
SwaggerUIBundle.plugins.DownloadUrl
|
||||
],
|
||||
layout: "StandaloneLayout",
|
||||
filter: true,
|
||||
requestInterceptor: function (request) {
|
||||
var headers = request.headers || {};
|
||||
var csrftoken = document.querySelector("[name=csrfmiddlewaretoken]");
|
||||
if (csrftoken) {
|
||||
headers["X-CSRFToken"] = csrftoken.value;
|
||||
}
|
||||
return request;
|
||||
}
|
||||
};
|
||||
if (document.querySelector('.auth-wrapper .authorize')) {
|
||||
patchSwaggerUi();
|
||||
} else {
|
||||
insertionQ('.auth-wrapper .authorize').every(patchSwaggerUi);
|
||||
}
|
||||
|
||||
var swaggerSettings = JSON.parse(document.getElementById('swagger-settings').innerHTML);
|
||||
if (!('oauth2RedirectUrl' in swaggerSettings)) {
|
||||
var oauth2RedirectUrl = document.getElementById('oauth2-redirect-url');
|
||||
if (oauth2RedirectUrl) {
|
||||
swaggerSettings['oauth2RedirectUrl'] = oauth2RedirectUrl.href;
|
||||
oauth2RedirectUrl.parentNode.removeChild(oauth2RedirectUrl);
|
||||
|
||||
var oauth2RedirectUrl = document.getElementById('oauth2-redirect-url');
|
||||
if (oauth2RedirectUrl) {
|
||||
if (!('oauth2RedirectUrl' in swaggerSettings)) {
|
||||
if (oauth2RedirectUrl) {
|
||||
swaggerSettings['oauth2RedirectUrl'] = oauth2RedirectUrl.href;
|
||||
}
|
||||
}
|
||||
oauth2RedirectUrl.parentNode.removeChild(oauth2RedirectUrl);
|
||||
}
|
||||
|
||||
console.log('swaggerSettings', swaggerSettings);
|
||||
for (var p in swaggerSettings) {
|
||||
if (swaggerSettings.hasOwnProperty(p)) {
|
||||
swaggerConfig[p] = swaggerSettings[p];
|
||||
}
|
||||
}
|
||||
window.ui = SwaggerUIBundle(swaggerConfig);
|
||||
|
||||
var oauth2Config = JSON.parse(document.getElementById('oauth2-config').innerHTML);
|
||||
console.log('oauth2Config', oauth2Config);
|
||||
|
||||
initSwaggerUiConfig(swaggerSettings, oauth2Config);
|
||||
window.ui = SwaggerUIBundle(swaggerUiConfig);
|
||||
window.ui.initOAuth(oauth2Config);
|
||||
}
|
||||
|
||||
window.onload = function () {
|
||||
initSwaggerUi();
|
||||
};
|
||||
/**
|
||||
* Initialize the global swaggerUiConfig with any given additional settings.
|
||||
* @param swaggerSettings SWAGGER_SETTINGS from Django settings
|
||||
* @param oauth2Settings OAUTH2_CONFIG from Django settings
|
||||
*/
|
||||
function initSwaggerUiConfig(swaggerSettings, oauth2Settings) {
|
||||
var persistAuth = swaggerSettings.persistAuth;
|
||||
var refetchWithAuth = swaggerSettings.refetchWithAuth;
|
||||
var refetchOnLogout = swaggerSettings.refetchOnLogout;
|
||||
var fetchSchemaWithQuery = swaggerSettings.fetchSchemaWithQuery;
|
||||
delete swaggerSettings['persistAuth'];
|
||||
delete swaggerSettings['refetchWithAuth'];
|
||||
delete swaggerSettings['refetchOnLogout'];
|
||||
delete swaggerSettings['fetchSchemaWithQuery'];
|
||||
|
||||
if (document.querySelector('.auth-wrapper .authorize')) {
|
||||
patchSwaggerUi();
|
||||
for (var p in swaggerSettings) {
|
||||
if (swaggerSettings.hasOwnProperty(p)) {
|
||||
swaggerUiConfig[p] = swaggerSettings[p];
|
||||
}
|
||||
}
|
||||
|
||||
var specURL = swaggerUiConfig.url;
|
||||
if (fetchSchemaWithQuery) {
|
||||
// only add query params from document for the first spec request
|
||||
// this ensures we otherwise honor the spec selector box which might be manually modified
|
||||
var query = new URLSearchParams(window.location.search || '').entries();
|
||||
for (var it = query.next(); !it.done; it = query.next()) {
|
||||
specURL = setQueryParam(specURL, it.value[0], it.value[1]);
|
||||
}
|
||||
}
|
||||
if (persistAuth) {
|
||||
try {
|
||||
savedAuth = Immutable.fromJS(JSON.parse(localStorage.getItem(KEY_AUTH)) || {});
|
||||
} catch (e) {
|
||||
localStorage.removeItem(KEY_AUTH);
|
||||
}
|
||||
}
|
||||
if (refetchWithAuth) {
|
||||
specURL = applyAuth(savedAuth, specURL) || specURL;
|
||||
}
|
||||
swaggerUiConfig.url = specURL;
|
||||
|
||||
if (persistAuth || refetchWithAuth) {
|
||||
var hookedAuth = false;
|
||||
|
||||
var oldOnComplete = swaggerUiConfig.onComplete;
|
||||
swaggerUiConfig.onComplete = function () {
|
||||
if (persistAuth) {
|
||||
preauthorizeAll(savedAuth, window.ui);
|
||||
}
|
||||
|
||||
if (!hookedAuth) {
|
||||
hookAuthActions(window.ui, persistAuth, refetchWithAuth, refetchOnLogout);
|
||||
hookedAuth = true;
|
||||
}
|
||||
if (oldOnComplete) {
|
||||
oldOnComplete();
|
||||
}
|
||||
};
|
||||
|
||||
var specRequestsInFlight = {};
|
||||
var oldRequestInterceptor = swaggerUiConfig.requestInterceptor;
|
||||
swaggerUiConfig.requestInterceptor = function (request) {
|
||||
var headers = request.headers || {};
|
||||
if (request.loadSpec) {
|
||||
var newUrl = request.url;
|
||||
if (refetchWithAuth) {
|
||||
newUrl = applyAuth(savedAuth, newUrl, headers) || newUrl;
|
||||
}
|
||||
|
||||
if (newUrl !== request.url) {
|
||||
request.url = newUrl;
|
||||
|
||||
if (window.ui) {
|
||||
// this visually updates the spec url before the request is done, i.e. while loading
|
||||
window.ui.specActions.updateUrl(request.url);
|
||||
} else {
|
||||
// setTimeout is needed here because the request interceptor can be called *during*
|
||||
// window.ui initialization (by the SwaggerUIBundle constructor)
|
||||
setTimeout(function () {
|
||||
window.ui.specActions.updateUrl(request.url);
|
||||
});
|
||||
}
|
||||
|
||||
// need to manually remember requests for spec urls because
|
||||
// responseInterceptor has no reference to the request...
|
||||
var absUrl = new URL(request.url, currentPath);
|
||||
specRequestsInFlight[absUrl.href] = request.url;
|
||||
}
|
||||
}
|
||||
|
||||
if (oldRequestInterceptor) {
|
||||
request = oldRequestInterceptor(request);
|
||||
}
|
||||
return request;
|
||||
};
|
||||
|
||||
var oldResponseInterceptor = swaggerUiConfig.responseInterceptor;
|
||||
swaggerUiConfig.responseInterceptor = function (response) {
|
||||
var absUrl = new URL(response.url, currentPath);
|
||||
if (absUrl.href in specRequestsInFlight) {
|
||||
var setToUrl = specRequestsInFlight[absUrl.href];
|
||||
delete specRequestsInFlight[absUrl.href];
|
||||
if (response.ok) {
|
||||
// need setTimeout here because swagger-ui insists to call updateUrl
|
||||
// with the initial request url after the response...
|
||||
setTimeout(function () {
|
||||
var currentUrl = new URL(window.ui.specSelectors.url(), currentPath);
|
||||
if (currentUrl.href !== absUrl.href) {
|
||||
window.ui.specActions.updateUrl(setToUrl);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (oldResponseInterceptor) {
|
||||
response = oldResponseInterceptor(response);
|
||||
}
|
||||
return response;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
insertionQ('.auth-wrapper .authorize').every(patchSwaggerUi);
|
||||
|
||||
function _usp(url, fn) {
|
||||
url = url.split('?');
|
||||
var usp = new URLSearchParams(url[1] || '');
|
||||
fn(usp);
|
||||
url[1] = usp.toString();
|
||||
return url[1] ? url.join('?') : url[0];
|
||||
}
|
||||
|
||||
function setQueryParam(url, key, value) {
|
||||
return _usp(url, function (usp) {
|
||||
usp.set(key, value);
|
||||
});
|
||||
}
|
||||
|
||||
function removeQueryParam(url, key) {
|
||||
return _usp(url, function (usp) {
|
||||
usp.delete(key);
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Call sui.preauthorize### for all authorizations in authorization.
|
||||
* @param authorization authorization object {key => authScheme} saved from authActions.authorize
|
||||
* @param sui SwaggerUI or SwaggerUIBundle instance
|
||||
*/
|
||||
function preauthorizeAll(authorization, sui) {
|
||||
authorization.valueSeq().forEach(function (authScheme) {
|
||||
var schemeName = authScheme.get("name"), schemeType = authScheme.getIn(["schema", "type"]);
|
||||
if (schemeType === "basic" && schemeName) {
|
||||
var username = authScheme.getIn(["value", "username"]);
|
||||
var password = authScheme.getIn(["value", "password"]);
|
||||
if (username && password) {
|
||||
sui.preauthorizeBasic(schemeName, username, password);
|
||||
}
|
||||
} else if (schemeType === "apiKey" && schemeName) {
|
||||
var key = authScheme.get("value");
|
||||
if (key) {
|
||||
sui.preauthorizeApiKey(schemeName, key);
|
||||
}
|
||||
} else {
|
||||
// TODO: OAuth2
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Manually apply auth headers from the given auth object.
|
||||
* @param {object} authorization authorization object {key => authScheme} saved from authActions.authorize
|
||||
* @param {string} requestUrl the request url
|
||||
* @param {object} requestHeaders target headers, modified in place by the function
|
||||
* @return string new request url
|
||||
*/
|
||||
function applyAuth(authorization, requestUrl, requestHeaders) {
|
||||
authorization.valueSeq().forEach(function (authScheme) {
|
||||
requestHeaders = requestHeaders || {};
|
||||
var schemeName = authScheme.get("name"), schemeType = authScheme.getIn(["schema", "type"]);
|
||||
if (schemeType === "basic" && schemeName) {
|
||||
var username = authScheme.getIn(["value", "username"]);
|
||||
var password = authScheme.getIn(["value", "password"]);
|
||||
if (username && password) {
|
||||
requestHeaders["Authorization"] = "Basic " + btoa(username + ":" + password);
|
||||
}
|
||||
} else if (schemeType === "apiKey" && schemeName) {
|
||||
var _in = authScheme.getIn(["schema", "in"]), paramName = authScheme.getIn(["schema", "name"]);
|
||||
var key = authScheme.get("value");
|
||||
if (key && paramName) {
|
||||
if (_in === "header") {
|
||||
requestHeaders[paramName] = key;
|
||||
}
|
||||
if (_in === "query") {
|
||||
if (requestUrl) {
|
||||
requestUrl = setQueryParam(requestUrl, paramName, key);
|
||||
} else {
|
||||
console.warn("WARNING: cannot apply apiKey query parameter via interceptor");
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// TODO: OAuth2
|
||||
}
|
||||
});
|
||||
|
||||
return requestUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the given authorization scheme from the url.
|
||||
* @param {object} authorization authorization object {key => authScheme} containing schemes to deauthorize
|
||||
* @param {string} requestUrl request url
|
||||
* @return string new request url
|
||||
*/
|
||||
function deauthUrl(authorization, requestUrl) {
|
||||
authorization.valueSeq().forEach(function (authScheme) {
|
||||
var schemeType = authScheme.getIn(["schema", "type"]);
|
||||
if (schemeType === "apiKey") {
|
||||
var _in = authScheme.getIn(["schema", "in"]), paramName = authScheme.getIn(["schema", "name"]);
|
||||
if (_in === "query" && requestUrl && paramName) {
|
||||
requestUrl = removeQueryParam(requestUrl, paramName);
|
||||
}
|
||||
} else {
|
||||
// TODO: OAuth2?
|
||||
}
|
||||
});
|
||||
return requestUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook the authorize and logout actions of SwaggerUI.
|
||||
* The hooks are used to persist authorization data and trigger schema refetch.
|
||||
* @param sui SwaggerUI or SwaggerUIBundle instance
|
||||
* @param {boolean} persistAuth true to save auth to local storage
|
||||
* @param {boolean} refetchWithAuth true to trigger schema fetch on login
|
||||
* @param {boolean} refetchOnLogout true to trigger schema fetch on logout
|
||||
*/
|
||||
function hookAuthActions(sui, persistAuth, refetchWithAuth, refetchOnLogout) {
|
||||
if (!persistAuth && !refetchWithAuth) {
|
||||
// nothing to do
|
||||
return;
|
||||
}
|
||||
|
||||
var originalAuthorize = sui.authActions.authorize;
|
||||
sui.authActions.authorize = function (authorization) {
|
||||
originalAuthorize(authorization);
|
||||
// authorization is map of scheme name to scheme object
|
||||
// need to use ImmutableJS because schema is already an ImmutableJS object
|
||||
var newAuths = Immutable.fromJS(authorization);
|
||||
savedAuth = savedAuth.merge(newAuths);
|
||||
|
||||
if (refetchWithAuth) {
|
||||
var url = sui.specSelectors.url();
|
||||
url = applyAuth(savedAuth, url) || url;
|
||||
sui.specActions.updateUrl(url);
|
||||
sui.specActions.download();
|
||||
sui.authActions.showDefinitions(); // hide authorize dialog
|
||||
}
|
||||
if (persistAuth) {
|
||||
localStorage.setItem(KEY_AUTH, JSON.stringify(savedAuth.toJSON()));
|
||||
}
|
||||
};
|
||||
|
||||
var originalLogout = sui.authActions.logout;
|
||||
sui.authActions.logout = function (authorization) {
|
||||
// stash logged out methods for use with deauthUrl
|
||||
var loggedOut = savedAuth.filter(function (val, key) {
|
||||
return authorization.indexOf(key) !== -1;
|
||||
}).mapEntries(function (entry) {
|
||||
return [entry[0], entry[1].set("value", null)]
|
||||
});
|
||||
// remove logged out methods from savedAuth
|
||||
savedAuth = savedAuth.filter(function (val, key) {
|
||||
return authorization.indexOf(key) === -1;
|
||||
});
|
||||
|
||||
if (refetchWithAuth) {
|
||||
var url = sui.specSelectors.url();
|
||||
url = deauthUrl(loggedOut, url) || url;
|
||||
sui.specActions.updateUrl(url);
|
||||
sui.specActions.download(url);
|
||||
sui.authActions.showDefinitions(); // hide authorize dialog
|
||||
}
|
||||
if (persistAuth) {
|
||||
localStorage.setItem(KEY_AUTH, JSON.stringify(savedAuth.toJSON()));
|
||||
}
|
||||
originalLogout(authorization);
|
||||
};
|
||||
}
|
||||
|
||||
window.addEventListener('load', initSwaggerUi);
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -2,21 +2,46 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>{{ title }}</title>
|
||||
<meta charset="utf-8"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>{% block title %}{{ title }}{% endblock %}</title>
|
||||
|
||||
<link rel="stylesheet" type="text/css" href="{% static 'drf-yasg/style.css' %}"/>
|
||||
{% block extra_head %}
|
||||
{# -- Add any extra HTML heads tags here - except scripts and styles -- #}
|
||||
{% endblock %}
|
||||
|
||||
{% block favicon %}
|
||||
{# -- Maybe replace the favicon -- #}
|
||||
<link rel="icon" type="image/png" href="{% static 'drf-yasg/redoc/redoc-logo.png' %}"/>
|
||||
{% endblock %}
|
||||
|
||||
{% block main_styles %}
|
||||
<link rel="stylesheet" type="text/css" href="{% static 'drf-yasg/style.css' %}"/>
|
||||
{% endblock %}
|
||||
{% block extra_styles %}
|
||||
{# -- Add any additional CSS scripts here -- #}
|
||||
{% endblock %}
|
||||
</head>
|
||||
<body>
|
||||
|
||||
{% block extra_body %}
|
||||
{# -- Add any header/body markup here (rendered BEFORE the swagger-ui/redoc element) -- #}
|
||||
{% endblock %}
|
||||
|
||||
<div id="redoc-placeholder"></div>
|
||||
|
||||
{% block footer %}
|
||||
{# -- Add any footer markup here (rendered AFTER the swagger-ui/redoc element) -- #}
|
||||
{% endblock %}
|
||||
|
||||
<script id="redoc-settings" type="application/json">{{ redoc_settings | safe }}</script>
|
||||
|
||||
<script src="{% static 'drf-yasg/insQ.min.js' %}"></script>
|
||||
<script src="{% static 'drf-yasg/redoc-init.js' %}"></script>
|
||||
<script src="{% static 'drf-yasg/redoc/redoc.min.js' %}"></script>
|
||||
{% block main_scripts %}
|
||||
<script src="{% static 'drf-yasg/insQ.min.js' %}"></script>
|
||||
<script src="{% static 'drf-yasg/url-polyfill.min.js' %}"></script>
|
||||
<script src="{% static 'drf-yasg/redoc-init.js' %}"></script>
|
||||
<script src="{% static 'drf-yasg/redoc/redoc.min.js' %}"></script>
|
||||
{% endblock %}
|
||||
{% block extra_scripts %}
|
||||
{# -- Add any additional scripts here -- #}
|
||||
{% endblock %}
|
||||
|
||||
@@ -1,16 +1,23 @@
|
||||
<!-- HTML for static distribution bundle build -->
|
||||
{% load static %}
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>{{ title }}</title>
|
||||
<meta charset="utf-8"/>
|
||||
<title>{% block title %}{{ title }}{% endblock %}</title>
|
||||
|
||||
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:400,700|Source+Code+Pro:300,600|Titillium+Web:400,600,700">
|
||||
<link rel="stylesheet" type="text/css" href="{% static 'drf-yasg/style.css' %}"/>
|
||||
<link rel="stylesheet" type="text/css" href="{% static 'drf-yasg/swagger-ui-dist/swagger-ui.css' %}">
|
||||
<link rel="icon" type="image/png" href="{% static 'drf-yasg/swagger-ui-dist/favicon-32x32.png' %}" sizes="32x32"/>
|
||||
<link rel="icon" type="image/png" href="{% static 'drf-yasg/swagger-ui-dist/favicon-16x16.png' %}" sizes="16x16"/>
|
||||
{% block extra_head %}
|
||||
{# -- Add any extra HTML heads tags here - except scripts and styles -- #}
|
||||
{% endblock %}
|
||||
|
||||
{% block favicon %}
|
||||
{# -- Maybe replace the favicon -- #}
|
||||
<link rel="icon" type="image/png" href="{% static 'drf-yasg/swagger-ui-dist/favicon-32x32.png' %}"/>
|
||||
{% endblock %}
|
||||
|
||||
{% block main_styles %}
|
||||
<link rel="stylesheet" type="text/css" href="{% static 'drf-yasg/style.css' %}"/>
|
||||
<link rel="stylesheet" type="text/css" href="{% static 'drf-yasg/swagger-ui-dist/swagger-ui.css' %}">
|
||||
{% endblock %}
|
||||
{% block extra_styles %}
|
||||
{# -- Add any additional CSS scripts here -- #}
|
||||
{% endblock %}
|
||||
@@ -18,15 +25,27 @@
|
||||
|
||||
<body class="swagger-body">
|
||||
|
||||
{% block extra_body %}
|
||||
{# -- Add any header/body markup here (rendered BEFORE the swagger-ui/redoc element) -- #}
|
||||
{% endblock %}
|
||||
|
||||
<div id="swagger-ui"></div>
|
||||
|
||||
{% block footer %}
|
||||
{# -- Add any footer markup here (rendered AFTER the swagger-ui/redoc element) -- #}
|
||||
{% endblock %}
|
||||
|
||||
<script id="swagger-settings" type="application/json">{{ swagger_settings | safe }}</script>
|
||||
<script id="oauth2-config" type="application/json">{{ oauth2_config | safe }}</script>
|
||||
|
||||
<script src="{% static 'drf-yasg/swagger-ui-dist/swagger-ui-bundle.js' %}"></script>
|
||||
<script src="{% static 'drf-yasg/swagger-ui-dist/swagger-ui-standalone-preset.js' %}"></script>
|
||||
<script src="{% static 'drf-yasg/insQ.min.js' %}"></script>
|
||||
<script src="{% static 'drf-yasg/swagger-ui-init.js' %}"></script>
|
||||
{% block main_scripts %}
|
||||
<script src="{% static 'drf-yasg/swagger-ui-dist/swagger-ui-bundle.js' %}"></script>
|
||||
<script src="{% static 'drf-yasg/swagger-ui-dist/swagger-ui-standalone-preset.js' %}"></script>
|
||||
<script src="{% static 'drf-yasg/insQ.min.js' %}"></script>
|
||||
<script src="{% static 'drf-yasg/immutable.min.js' %}"></script>
|
||||
<script src="{% static 'drf-yasg/url-polyfill.min.js' %}"></script>
|
||||
<script src="{% static 'drf-yasg/swagger-ui-init.js' %}"></script>
|
||||
{% endblock %}
|
||||
{% block extra_scripts %}
|
||||
{# -- Add any additional scripts here -- #}
|
||||
{% endblock %}
|
||||
@@ -35,33 +54,36 @@
|
||||
|
||||
{% if USE_SESSION_AUTH %}
|
||||
<div id="django-session-auth" class="hidden">
|
||||
{% csrf_token %}
|
||||
{% block session_auth_button %}
|
||||
{% csrf_token %}
|
||||
|
||||
{% block user_context_message %}
|
||||
{% if request.user.is_authenticated %}
|
||||
<div class="hello">
|
||||
<span class="django-session">Django</span> <span
|
||||
class="label label-primary">{{ request.user }}</span>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block user_context_message %}
|
||||
{% if request.user.is_authenticated %}
|
||||
<div class="hello">
|
||||
<span class="django-session">Django</span> <span class="label label-primary">{{ request.user }}</span>
|
||||
<div class='btn authorize'>
|
||||
<a id="auth" class="header__btn" href="{{ LOGOUT_URL }}?next={{ request.path }}" data-sw-translate>
|
||||
{% block django_logout_message %}
|
||||
Django Logout
|
||||
{% endblock %}
|
||||
</a>
|
||||
</div>
|
||||
{% else %}
|
||||
<div class='btn authorize'>
|
||||
<a id="auth" class="header__btn" href="{{ LOGIN_URL }}?next={{ request.path }}" data-sw-translate>
|
||||
{% block django_login_message %}
|
||||
Django Login
|
||||
{% endblock %}
|
||||
</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% if request.user.is_authenticated %}
|
||||
<div class='btn authorize'>
|
||||
<a id="auth" class="header__btn" href="{{ LOGOUT_URL }}?next={{ request.path }}" data-sw-translate>
|
||||
{% block django_logout_message %}
|
||||
Django Logout
|
||||
{% endblock %}
|
||||
</a>
|
||||
</div>
|
||||
{% else %}
|
||||
<div class='btn authorize'>
|
||||
<a id="auth" class="header__btn" href="{{ LOGIN_URL }}?next={{ request.path }}" data-sw-translate>
|
||||
{% block django_login_message %}
|
||||
Django Login
|
||||
{% endblock %}
|
||||
</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
</body>
|
||||
|
||||
+76
-29
@@ -1,5 +1,6 @@
|
||||
import inspect
|
||||
import logging
|
||||
import sys
|
||||
from collections import OrderedDict
|
||||
|
||||
from django.db import models
|
||||
@@ -29,7 +30,7 @@ class unset(object):
|
||||
def swagger_auto_schema(method=None, methods=None, auto_schema=unset, request_body=None, query_serializer=None,
|
||||
manual_parameters=None, operation_id=None, operation_description=None, operation_summary=None,
|
||||
security=None, deprecated=None, responses=None, field_inspectors=None, filter_inspectors=None,
|
||||
paginator_inspectors=None, **extra_overrides):
|
||||
paginator_inspectors=None, tags=None, **extra_overrides):
|
||||
"""Decorate a view method to customize the :class:`.Operation` object generated from it.
|
||||
|
||||
`method` and `methods` are mutually exclusive and must only be present when decorating a view method that accepts
|
||||
@@ -39,11 +40,11 @@ def swagger_auto_schema(method=None, methods=None, auto_schema=unset, request_bo
|
||||
|
||||
:param str method: for multi-method views, the http method the options should apply to
|
||||
:param list[str] methods: for multi-method views, the http methods the options should apply to
|
||||
:param .inspectors.SwaggerAutoSchema auto_schema: custom class to use for generating the Operation object;
|
||||
:param drf_yasg.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 :class:`.no_body`. The value given here
|
||||
will be used as the ``schema`` property of a :class:`.Parameter` with ``in: 'body'``.
|
||||
:param request_body: custom request body which 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
|
||||
are mutually exclusive in an :class:`.Operation`. If you need to set custom ``form`` parameters, you can use
|
||||
@@ -51,9 +52,11 @@ def swagger_auto_schema(method=None, methods=None, auto_schema=unset, request_bo
|
||||
|
||||
If a ``Serializer`` class or instance is given, it will be automatically converted into a :class:`.Schema`
|
||||
used as a ``body`` :class:`.Parameter`, or into a list of ``form`` :class:`.Parameter`\\ s, as appropriate.
|
||||
:type request_body: drf_yasg.openapi.Schema or drf_yasg.openapi.SchemaRef or rest_framework.serializers.Serializer
|
||||
or type[no_body]
|
||||
|
||||
:param .Serializer query_serializer: if you use a ``Serializer`` to parse query parameters, you can pass it here
|
||||
and have :class:`.Parameter` objects be generated automatically from it.
|
||||
:param rest_framework.serializers.Serializer query_serializer: if you use a ``Serializer`` to parse query
|
||||
parameters, you can pass it here and have :class:`.Parameter` objects be generated automatically from it.
|
||||
|
||||
If any ``Field`` on the serializer cannot be represented as a ``query`` :class:`.Parameter`
|
||||
(e.g. nested Serializers, file fields, ...), the schema generation will fail with an error.
|
||||
@@ -61,7 +64,8 @@ def swagger_auto_schema(method=None, methods=None, auto_schema=unset, request_bo
|
||||
Schema generation will also fail if the name of any Field on the `query_serializer` conflicts with parameters
|
||||
generated by ``filter_backends`` or ``paginator``.
|
||||
|
||||
:param list[.Parameter] manual_parameters: a list of manual parameters to override the automatically generated ones
|
||||
:param list[drf_yasg.openapi.Parameter] manual_parameters: a list of manual parameters to override the
|
||||
automatically generated ones
|
||||
|
||||
:class:`.Parameter`\\ s are identified by their (``name``, ``in``) combination, and any parameters given
|
||||
here will fully override automatically generated parameters if they collide.
|
||||
@@ -75,7 +79,7 @@ def swagger_auto_schema(method=None, methods=None, auto_schema=unset, request_bo
|
||||
is requried to call this API; an empty list marks the endpoint as unauthenticated (i.e. removes all accepted
|
||||
authentication schemes), and ``None`` will inherit the top-level secuirty requirements
|
||||
:param bool deprecated: deprecation status for operation
|
||||
:param dict[str,(.Schema,.SchemaRef,.Response,str,Serializer)] responses: a dict of documented manual responses
|
||||
:param responses: a dict of documented manual responses
|
||||
keyed on response status code. If no success (``2xx``) response is given, one will automatically be
|
||||
generated from the request body and http method. If any ``2xx`` response is given the automatic response is
|
||||
suppressed.
|
||||
@@ -89,13 +93,16 @@ def swagger_auto_schema(method=None, methods=None, auto_schema=unset, request_bo
|
||||
* a ``Serializer`` class or instance will be converted into a :class:`.Schema` and treated as above
|
||||
* a :class:`.Response` object will be used as-is; however if its ``schema`` attribute is a ``Serializer``,
|
||||
it will automatically be converted into a :class:`.Schema`
|
||||
:type responses: dict[str,(drf_yasg.openapi.Schema or drf_yasg.openapi.SchemaRef or drf_yasg.openapi.Response or
|
||||
str or rest_framework.serializers.Serializer)]
|
||||
|
||||
:param list[.FieldInspector] field_inspectors: extra serializer and field inspectors; these will be tried
|
||||
before :attr:`.ViewInspector.field_inspectors` on the :class:`.inspectors.SwaggerAutoSchema` instance
|
||||
:param list[.FilterInspector] filter_inspectors: extra filter inspectors; these will be tried before
|
||||
:attr:`.ViewInspector.filter_inspectors` on the :class:`.inspectors.SwaggerAutoSchema` instance
|
||||
:param list[.PaginatorInspector] paginator_inspectors: extra paginator inspectors; these will be tried before
|
||||
:attr:`.ViewInspector.paginator_inspectors` on the :class:`.inspectors.SwaggerAutoSchema` instance
|
||||
:param list[type[drf_yasg.inspectors.FieldInspector]] field_inspectors: extra serializer and field inspectors; these
|
||||
will be tried before :attr:`.ViewInspector.field_inspectors` on the :class:`.inspectors.SwaggerAutoSchema`
|
||||
:param list[type[drf_yasg.inspectors.FilterInspector]] filter_inspectors: extra filter inspectors; these will be
|
||||
tried before :attr:`.ViewInspector.filter_inspectors` on the :class:`.inspectors.SwaggerAutoSchema`
|
||||
:param list[type[drf_yasg.inspectors.PaginatorInspector]] paginator_inspectors: extra paginator inspectors; these
|
||||
will be tried before :attr:`.ViewInspector.paginator_inspectors` on the :class:`.inspectors.SwaggerAutoSchema`
|
||||
:param list[str] tags: tags override
|
||||
:param extra_overrides: extra values that will be saved into the ``overrides`` dict; these values will be available
|
||||
in the handling :class:`.inspectors.SwaggerAutoSchema` instance via ``self.overrides``
|
||||
"""
|
||||
@@ -115,6 +122,7 @@ def swagger_auto_schema(method=None, methods=None, auto_schema=unset, request_bo
|
||||
'filter_inspectors': list(filter_inspectors) if filter_inspectors else None,
|
||||
'paginator_inspectors': list(paginator_inspectors) if paginator_inspectors else None,
|
||||
'field_inspectors': list(field_inspectors) if field_inspectors else None,
|
||||
'tags': list(tags) if tags else None,
|
||||
}
|
||||
data = filter_none(data)
|
||||
if auto_schema is not unset:
|
||||
@@ -207,7 +215,7 @@ def is_list_view(path, method, view):
|
||||
"""
|
||||
# for ViewSets, it could be the default 'list' action, or a list_route
|
||||
action = getattr(view, 'action', '')
|
||||
method = getattr(view, action, None)
|
||||
method = getattr(view, action, None) or method
|
||||
detail = getattr(method, 'detail', None)
|
||||
suffix = getattr(view, 'suffix', None)
|
||||
if action in ('list', 'create') or detail is False or suffix == 'List':
|
||||
@@ -245,9 +253,9 @@ def param_list_to_odict(parameters):
|
||||
|
||||
Raises an ``AssertionError`` if `parameters` contains duplicate parameters (by their name + in combination).
|
||||
|
||||
:param list[.Parameter] parameters: the list of parameters
|
||||
:param list[drf_yasg.openapi.Parameter] parameters: the list of parameters
|
||||
:return: `parameters` keyed by ``(name, in_)``
|
||||
:rtype: dict[tuple(str,str),.Parameter]
|
||||
:rtype: dict[(str,str),drf_yasg.openapi.Parameter]
|
||||
"""
|
||||
result = OrderedDict(((param.name, param.in_), param) for param in parameters)
|
||||
assert len(result) == len(parameters), "duplicate Parameters found"
|
||||
@@ -260,10 +268,10 @@ def merge_params(parameters, overrides):
|
||||
|
||||
Raises an ``AssertionError`` if either list contains duplicate parameters.
|
||||
|
||||
:param list[.Parameter] parameters: initial parameters
|
||||
:param list[.Parameter] overrides: overriding parameters
|
||||
:param list[drf_yasg.openapi.Parameter] parameters: initial parameters
|
||||
:param list[drf_yasg.openapi.Parameter] overrides: overriding parameters
|
||||
:return: merged list
|
||||
:rtype: list[.Parameter]
|
||||
:rtype: list[drf_yasg.openapi.Parameter]
|
||||
"""
|
||||
parameters = param_list_to_odict(parameters)
|
||||
parameters.update(param_list_to_odict(overrides))
|
||||
@@ -273,7 +281,7 @@ def merge_params(parameters, overrides):
|
||||
def filter_none(obj):
|
||||
"""Remove ``None`` values from tuples, lists or dictionaries. Return other objects as-is.
|
||||
|
||||
:param obj:
|
||||
:param obj: the object
|
||||
:return: collection with ``None`` values removed
|
||||
"""
|
||||
if obj is None:
|
||||
@@ -293,6 +301,7 @@ def force_serializer_instance(serializer):
|
||||
an assertion error.
|
||||
|
||||
:param serializer: serializer class or instance
|
||||
:type serializer: serializers.BaseSerializer or type[serializers.BaseSerializer]
|
||||
:return: serializer instance
|
||||
:rtype: serializers.BaseSerializer
|
||||
"""
|
||||
@@ -325,28 +334,55 @@ def get_serializer_class(serializer):
|
||||
return type(serializer)
|
||||
|
||||
|
||||
def get_object_classes(classes_or_instances, expected_base_class=None):
|
||||
"""Given a list of instances or class objects, return the list of their classes.
|
||||
|
||||
:param classes_or_instances: mixed list to parse
|
||||
:type classes_or_instances: list[type or object]
|
||||
:param expected_base_class: if given, only subclasses or instances of this type will be returned
|
||||
:type expected_base_class: type
|
||||
:return: list of classes
|
||||
:rtype: list
|
||||
"""
|
||||
classes_or_instances = classes_or_instances or []
|
||||
result = []
|
||||
for obj in classes_or_instances:
|
||||
if inspect.isclass(obj):
|
||||
if not expected_base_class or issubclass(obj, expected_base_class):
|
||||
result.append(obj)
|
||||
else:
|
||||
if not expected_base_class or isinstance(obj, expected_base_class):
|
||||
result.append(type(obj))
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def get_consumes(parser_classes):
|
||||
"""Extract ``consumes`` MIME types from a list of parser classes.
|
||||
|
||||
:param list parser_classes: parser classes
|
||||
:type parser_classes: list[rest_framework.parsers.BaseParser or type[rest_framework.parsers.BaseParser]]
|
||||
:return: MIME types for ``consumes``
|
||||
:rtype: list[str]
|
||||
"""
|
||||
parser_classes = get_object_classes(parser_classes)
|
||||
media_types = [parser.media_type for parser in parser_classes or []]
|
||||
if all(is_form_media_type(encoding) for encoding in media_types):
|
||||
non_form_media_types = [encoding for encoding in media_types if not is_form_media_type(encoding)]
|
||||
if len(non_form_media_types) == 0:
|
||||
return media_types
|
||||
else:
|
||||
media_types = [encoding for encoding in media_types if not is_form_media_type(encoding)]
|
||||
return media_types
|
||||
return non_form_media_types
|
||||
|
||||
|
||||
def get_produces(renderer_classes):
|
||||
"""Extract ``produces`` MIME types from a list of renderer classes.
|
||||
|
||||
:param list renderer_classes: renderer classes
|
||||
:type renderer_classes: list[rest_framework.renderers.BaseRenderer or type[rest_framework.renderers.BaseRenderer]]
|
||||
:return: MIME types for ``produces``
|
||||
:rtype: list[str]
|
||||
"""
|
||||
renderer_classes = get_object_classes(renderer_classes)
|
||||
media_types = [renderer.media_type for renderer in renderer_classes or []]
|
||||
media_types = [encoding for encoding in media_types
|
||||
if not any(excluded in encoding for excluded in swagger_settings.EXCLUDED_MEDIA_TYPES)]
|
||||
@@ -354,8 +390,7 @@ def get_produces(renderer_classes):
|
||||
|
||||
|
||||
def decimal_as_float(field):
|
||||
"""
|
||||
Returns true if ``field`` is a django-rest-framework DecimalField and its ``coerce_to_string`` attribute or the
|
||||
"""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
|
||||
@@ -366,12 +401,11 @@ def decimal_as_float(field):
|
||||
|
||||
|
||||
def get_serializer_ref_name(serializer):
|
||||
"""
|
||||
Get serializer's ref_name (or None for ModelSerializer if it is named 'NestedSerializer')
|
||||
"""Get serializer's ref_name (or None for ModelSerializer if it is named 'NestedSerializer')
|
||||
|
||||
:param serializer: Serializer instance
|
||||
:return: Serializer's ``ref_name`` or ``None`` for inline serializer
|
||||
:rtype: str
|
||||
:rtype: str or None
|
||||
"""
|
||||
serializer_meta = getattr(serializer, 'Meta', None)
|
||||
serializer_name = type(serializer).__name__
|
||||
@@ -434,3 +468,16 @@ def get_field_default(field):
|
||||
default = serializers.empty
|
||||
|
||||
return default
|
||||
|
||||
|
||||
def dict_has_ordered_keys(obj):
|
||||
"""Check if a given object is a dict that maintains insertion order.
|
||||
|
||||
:param obj: the dict object to check
|
||||
:rtype: bool
|
||||
"""
|
||||
if sys.version_info >= (3, 7):
|
||||
# the Python 3.7 language spec says that dict must maintain insertion order.
|
||||
return isinstance(obj, dict)
|
||||
|
||||
return isinstance(obj, OrderedDict)
|
||||
|
||||
+13
-7
@@ -12,7 +12,8 @@ from rest_framework.views import APIView
|
||||
|
||||
from .app_settings import swagger_settings
|
||||
from .renderers import (
|
||||
OpenAPIRenderer, ReDocOldRenderer, ReDocRenderer, SwaggerJSONRenderer, SwaggerUIRenderer, SwaggerYAMLRenderer
|
||||
OpenAPIRenderer, ReDocOldRenderer, ReDocRenderer, SwaggerJSONRenderer, SwaggerUIRenderer, SwaggerYAMLRenderer,
|
||||
_SpecRenderer
|
||||
)
|
||||
|
||||
SPEC_RENDERERS = (SwaggerYAMLRenderer, SwaggerJSONRenderer, OpenAPIRenderer)
|
||||
@@ -56,12 +57,12 @@ def get_schema_view(info=None, url=None, patterns=None, urlconf=None, public=Fal
|
||||
:param patterns: same as :class:`.OpenAPISchemaGenerator`
|
||||
:param urlconf: same as :class:`.OpenAPISchemaGenerator`
|
||||
:param bool public: if False, includes only the endpoints that are accesible by the user viewing the schema
|
||||
:param list validators: a list of validator names to apply; allowed values are ``flex``, ``ssv``
|
||||
:param list validators: a list of validator names to apply; the only allowed value is ``ssv``, for now
|
||||
:param type generator_class: schema generator class to use; should be a subclass of :class:`.OpenAPISchemaGenerator`
|
||||
:param tuple authentication_classes: authentication classes for the schema view itself
|
||||
:param tuple permission_classes: permission classes for the schema view itself
|
||||
:return: SchemaView class
|
||||
:rtype: type[.SchemaView]
|
||||
:rtype: type[drf_yasg.views.SchemaView]
|
||||
"""
|
||||
_public = public
|
||||
_generator_class = generator_class or swagger_settings.DEFAULT_GENERATOR_CLASS
|
||||
@@ -85,7 +86,12 @@ def get_schema_view(info=None, url=None, patterns=None, urlconf=None, public=Fal
|
||||
renderer_classes = _spec_renderers
|
||||
|
||||
def get(self, request, version='', format=None):
|
||||
generator = self.generator_class(info, request.version or version or '', url, patterns, urlconf)
|
||||
version = request.version or version or ''
|
||||
if isinstance(request.accepted_renderer, _SpecRenderer):
|
||||
generator = self.generator_class(info, version, url, patterns, urlconf)
|
||||
else:
|
||||
generator = self.generator_class(info, version, url, patterns=[])
|
||||
|
||||
schema = generator.get_schema(request, self.public)
|
||||
if schema is None:
|
||||
raise exceptions.PermissionDenied() # pragma: no cover
|
||||
@@ -106,7 +112,7 @@ def get_schema_view(info=None, url=None, patterns=None, urlconf=None, public=Fal
|
||||
def as_cached_view(cls, cache_timeout=0, cache_kwargs=None, **initkwargs):
|
||||
"""
|
||||
Calls .as_view() and wraps the result in a cache_page decorator.
|
||||
See https://docs.djangoproject.com/en/1.11/topics/cache/
|
||||
See https://docs.djangoproject.com/en/dev/topics/cache/
|
||||
|
||||
:param int cache_timeout: same as cache_page; set to 0 for no cache
|
||||
:param dict cache_kwargs: dictionary of kwargs to be passed to cache_page
|
||||
@@ -125,7 +131,7 @@ def get_schema_view(info=None, url=None, patterns=None, urlconf=None, public=Fal
|
||||
def without_ui(cls, cache_timeout=0, cache_kwargs=None):
|
||||
"""
|
||||
Instantiate this view with just JSON and YAML renderers, optionally wrapped with cache_page.
|
||||
See https://docs.djangoproject.com/en/1.11/topics/cache/.
|
||||
See https://docs.djangoproject.com/en/dev/topics/cache/.
|
||||
|
||||
:param int cache_timeout: same as cache_page; set to 0 for no cache
|
||||
:param dict cache_kwargs: dictionary of kwargs to be passed to cache_page
|
||||
@@ -137,7 +143,7 @@ def get_schema_view(info=None, url=None, patterns=None, urlconf=None, public=Fal
|
||||
def with_ui(cls, renderer='swagger', cache_timeout=0, cache_kwargs=None):
|
||||
"""
|
||||
Instantiate this view with a Web UI renderer, optionally wrapped with cache_page.
|
||||
See https://docs.djangoproject.com/en/1.11/topics/cache/.
|
||||
See https://docs.djangoproject.com/en/dev/topics/cache/.
|
||||
|
||||
:param str renderer: UI renderer; allowed values are ``swagger``, ``redoc``
|
||||
:param int cache_timeout: same as cache_page; set to 0 for no cache
|
||||
|
||||
@@ -33,7 +33,13 @@ class ArticleSerializer(serializers.ModelSerializer):
|
||||
|
||||
|
||||
class ImageUploadSerializer(serializers.Serializer):
|
||||
what_am_i_doing = serializers.RegexField(regex=r"^69$", help_text="test", default="69")
|
||||
image_id = serializers.UUIDField(read_only=True)
|
||||
what_am_i_doing = serializers.RegexField(
|
||||
regex=r"^69$",
|
||||
help_text="test",
|
||||
default="69",
|
||||
allow_null=True
|
||||
)
|
||||
image_styles = serializers.ListSerializer(
|
||||
child=serializers.ChoiceField(choices=['wide', 'tall', 'thumb', 'social']),
|
||||
help_text="Parameter with Items"
|
||||
|
||||
+31
-39
@@ -1,10 +1,10 @@
|
||||
import datetime
|
||||
import functools
|
||||
|
||||
from django.utils.decorators import method_decorator
|
||||
from django_filters.rest_framework import DjangoFilterBackend
|
||||
from rest_framework import viewsets
|
||||
# noinspection PyDeprecation
|
||||
from rest_framework.decorators import detail_route, list_route
|
||||
from rest_framework.filters import OrderingFilter
|
||||
from rest_framework.pagination import LimitOffsetPagination
|
||||
from rest_framework.parsers import MultiPartParser
|
||||
@@ -62,7 +62,7 @@ class ArticlePagination(LimitOffsetPagination):
|
||||
|
||||
@method_decorator(name='list', decorator=swagger_auto_schema(
|
||||
operation_description="description from swagger_auto_schema via method_decorator",
|
||||
filter_inspectors=[DjangoFilterDescriptionInspector]
|
||||
filter_inspectors=[DjangoFilterDescriptionInspector],
|
||||
))
|
||||
class ArticleViewSet(viewsets.ModelViewSet):
|
||||
"""
|
||||
@@ -84,7 +84,10 @@ class ArticleViewSet(viewsets.ModelViewSet):
|
||||
|
||||
pagination_class = ArticlePagination
|
||||
filter_backends = (DjangoFilterBackend, OrderingFilter)
|
||||
filter_fields = ('title',)
|
||||
filterset_fields = ('title',)
|
||||
# django-filter 1.1 compatibility; was renamed to filterset_fields in 2.0
|
||||
# TODO: remove when dropping support for Django 1.11
|
||||
filter_fields = filterset_fields
|
||||
ordering_fields = ('date_modified', 'date_created')
|
||||
ordering = ('date_created',)
|
||||
|
||||
@@ -92,46 +95,35 @@ class ArticleViewSet(viewsets.ModelViewSet):
|
||||
|
||||
try:
|
||||
from rest_framework.decorators import action
|
||||
|
||||
@swagger_auto_schema(auto_schema=NoPagingAutoSchema, filter_inspectors=[DjangoFilterDescriptionInspector])
|
||||
@action(detail=False, methods=['get'])
|
||||
def today(self, request):
|
||||
today_min = datetime.datetime.combine(datetime.date.today(), datetime.time.min)
|
||||
today_max = datetime.datetime.combine(datetime.date.today(), datetime.time.max)
|
||||
articles = self.get_queryset().filter(date_created__range=(today_min, today_max)).all()
|
||||
serializer = self.serializer_class(articles, many=True)
|
||||
return Response(serializer.data)
|
||||
|
||||
@swagger_auto_schema(method='get', operation_description="image GET description override")
|
||||
@swagger_auto_schema(method='post', request_body=serializers.ImageUploadSerializer)
|
||||
@action(detail=True, methods=['get', 'post'], parser_classes=(MultiPartParser,))
|
||||
def image(self, request, slug=None):
|
||||
"""
|
||||
image method docstring
|
||||
"""
|
||||
pass
|
||||
list_route = functools.partial(action, detail=False)
|
||||
detail_route = functools.partial(action, detail=True)
|
||||
except ImportError:
|
||||
# TODO: remove when dropping support for DRF 3.7
|
||||
action = None
|
||||
from rest_framework.decorators import list_route, detail_route
|
||||
|
||||
# noinspection PyDeprecation
|
||||
@swagger_auto_schema(auto_schema=NoPagingAutoSchema, filter_inspectors=[DjangoFilterDescriptionInspector])
|
||||
@list_route(methods=['get'])
|
||||
def today(self, request):
|
||||
today_min = datetime.datetime.combine(datetime.date.today(), datetime.time.min)
|
||||
today_max = datetime.datetime.combine(datetime.date.today(), datetime.time.max)
|
||||
articles = self.get_queryset().filter(date_created__range=(today_min, today_max)).all()
|
||||
serializer = self.serializer_class(articles, many=True)
|
||||
return Response(serializer.data)
|
||||
@swagger_auto_schema(auto_schema=NoPagingAutoSchema, filter_inspectors=[DjangoFilterDescriptionInspector])
|
||||
@list_route(methods=['get'])
|
||||
def today(self, request):
|
||||
today_min = datetime.datetime.combine(datetime.date.today(), datetime.time.min)
|
||||
today_max = datetime.datetime.combine(datetime.date.today(), datetime.time.max)
|
||||
articles = self.get_queryset().filter(date_created__range=(today_min, today_max)).all()
|
||||
serializer = self.serializer_class(articles, many=True)
|
||||
return Response(serializer.data)
|
||||
|
||||
# noinspection PyDeprecation
|
||||
@swagger_auto_schema(method='get', operation_description="image GET description override")
|
||||
@swagger_auto_schema(method='post', request_body=serializers.ImageUploadSerializer)
|
||||
@detail_route(methods=['get', 'post'], parser_classes=(MultiPartParser,))
|
||||
def image(self, request, slug=None):
|
||||
"""
|
||||
image method docstring
|
||||
"""
|
||||
pass
|
||||
@swagger_auto_schema(method='get', operation_description="image GET description override")
|
||||
@swagger_auto_schema(method='post', request_body=serializers.ImageUploadSerializer)
|
||||
@swagger_auto_schema(method='delete', manual_parameters=[openapi.Parameter(
|
||||
name='delete_form_param', in_=openapi.IN_FORM,
|
||||
type=openapi.TYPE_INTEGER,
|
||||
description="this should not crash (form parameter on DELETE method)"
|
||||
)])
|
||||
@detail_route(methods=['get', 'post', 'delete'], parser_classes=(MultiPartParser,))
|
||||
def image(self, request, slug=None):
|
||||
"""
|
||||
image method docstring
|
||||
"""
|
||||
pass
|
||||
|
||||
@swagger_auto_schema(request_body=no_body, operation_id='no_body_test')
|
||||
def update(self, request, *args, **kwargs):
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
from __future__ import print_function
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
from django.db.utils import IntegrityError
|
||||
|
||||
username = 'admin'
|
||||
email = 'admin@admin.admin'
|
||||
password = 'passwordadmin'
|
||||
|
||||
try:
|
||||
User.objects.create_superuser(username, email, password)
|
||||
except IntegrityError:
|
||||
print("User '%s <%s>' already exists" % (username, email))
|
||||
else:
|
||||
print("Created superuser '%s <%s>' with password '%s'" % (username, email, password))
|
||||
@@ -7,9 +7,6 @@ if __name__ == "__main__":
|
||||
try:
|
||||
from django.core.management import execute_from_command_line
|
||||
except ImportError:
|
||||
# The above import may fail for some other reason. Ensure that the
|
||||
# issue is really that Django is missing to avoid masking other
|
||||
# exceptions on Python 2.
|
||||
try:
|
||||
import django # noqa: F401
|
||||
except ImportError:
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -83,11 +83,6 @@ class SnippetDetail(generics.RetrieveUpdateDestroyAPIView):
|
||||
description="path parameter override",
|
||||
required=True
|
||||
),
|
||||
openapi.Parameter(
|
||||
name='delete_form_param', in_=openapi.IN_FORM,
|
||||
type=openapi.TYPE_INTEGER,
|
||||
description="this should not crash (form parameter on DELETE method)"
|
||||
),
|
||||
],
|
||||
responses={
|
||||
status.HTTP_204_NO_CONTENT: openapi.Response(
|
||||
|
||||
@@ -3,6 +3,8 @@ import os
|
||||
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
||||
from django.urls import reverse_lazy
|
||||
|
||||
from testproj.util import static_lazy
|
||||
|
||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
ALLOWED_HOSTS = [
|
||||
@@ -22,6 +24,7 @@ INSTALLED_APPS = [
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
'rest_framework',
|
||||
'oauth2_provider',
|
||||
'corsheaders',
|
||||
|
||||
'drf_yasg',
|
||||
@@ -49,7 +52,7 @@ ROOT_URLCONF = 'testproj.urls'
|
||||
TEMPLATES = [
|
||||
{
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
'DIRS': [],
|
||||
'DIRS': [os.path.join(BASE_DIR, 'testproj', 'templates')],
|
||||
'APP_DIRS': True,
|
||||
'OPTIONS': {
|
||||
'context_processors': [
|
||||
@@ -64,9 +67,9 @@ TEMPLATES = [
|
||||
|
||||
WSGI_APPLICATION = 'testproj.wsgi.application'
|
||||
|
||||
# Password validation
|
||||
# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators
|
||||
LOGIN_URL = reverse_lazy('admin:login')
|
||||
|
||||
# Password validation
|
||||
AUTH_PASSWORD_VALIDATORS = [
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
||||
@@ -83,18 +86,28 @@ AUTH_PASSWORD_VALIDATORS = [
|
||||
]
|
||||
|
||||
# Django Rest Framework
|
||||
|
||||
REST_FRAMEWORK = {
|
||||
'DEFAULT_PERMISSION_CLASSES': (
|
||||
'rest_framework.permissions.IsAuthenticated',
|
||||
)
|
||||
}
|
||||
|
||||
# drf-yasg
|
||||
OAUTH2_CLIENT_ID = '12ee6bgxtpSEgP8TioWcHSXOiDBOUrVav4mRbVEs'
|
||||
OAUTH2_CLIENT_SECRET = '5FvYALo7W4uNnWE2ySw7Yzpkxh9PSf5GuY37RvOys00ydEyph64dbl1ECOKI9ceQ' \
|
||||
'AKoz0JpiVQtq0DUnsxNhU3ubrJgZ9YbtiXymbLGJq8L7n4fiER7gXbXaNSbze3BN'
|
||||
OAUTH2_APP_NAME = 'drf-yasg OAuth2 provider'
|
||||
|
||||
OAUTH2_REDIRECT_URL = static_lazy('drf-yasg/swagger-ui-dist/oauth2-redirect.html')
|
||||
OAUTH2_AUTHORIZE_URL = reverse_lazy('oauth2_provider:authorize')
|
||||
OAUTH2_TOKEN_URL = reverse_lazy('oauth2_provider:token')
|
||||
|
||||
# drf-yasg
|
||||
SWAGGER_SETTINGS = {
|
||||
'LOGIN_URL': reverse_lazy('admin:login'),
|
||||
'LOGOUT_URL': '/admin/logout',
|
||||
'PERSIST_AUTH': True,
|
||||
'REFETCH_SCHEMA_WITH_AUTH': True,
|
||||
'REFETCH_SCHEMA_ON_LOGOUT': True,
|
||||
|
||||
'DEFAULT_INFO': 'testproj.urls.swagger_info',
|
||||
|
||||
@@ -103,10 +116,30 @@ SWAGGER_SETTINGS = {
|
||||
'type': 'basic'
|
||||
},
|
||||
'Bearer': {
|
||||
'type': 'apiKey',
|
||||
'in': 'header',
|
||||
'name': 'Authorization',
|
||||
'in': 'header'
|
||||
}
|
||||
'type': 'apiKey',
|
||||
},
|
||||
'OAuth2 password': {
|
||||
'flow': 'password',
|
||||
'scopes': {
|
||||
'read': 'Read everything.',
|
||||
'write': 'Write everything,',
|
||||
},
|
||||
'tokenUrl': OAUTH2_TOKEN_URL,
|
||||
'type': 'oauth2',
|
||||
},
|
||||
'Query': {
|
||||
'in': 'query',
|
||||
'name': 'auth',
|
||||
'type': 'apiKey',
|
||||
},
|
||||
},
|
||||
'OAUTH2_REDIRECT_URL': OAUTH2_REDIRECT_URL,
|
||||
'OAUTH2_CONFIG': {
|
||||
'clientId': OAUTH2_CLIENT_ID,
|
||||
'clientSecret': OAUTH2_CLIENT_SECRET,
|
||||
'appName': OAUTH2_APP_NAME,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,30 +148,23 @@ REDOC_SETTINGS = {
|
||||
}
|
||||
|
||||
# Internationalization
|
||||
# https://docs.djangoproject.com/en/1.11/topics/i18n/
|
||||
|
||||
LANGUAGE_CODE = 'en-us'
|
||||
|
||||
TIME_ZONE = 'UTC'
|
||||
|
||||
USE_I18N = True
|
||||
|
||||
USE_L10N = True
|
||||
|
||||
USE_TZ = True
|
||||
|
||||
# Static files (CSS, JavaScript, Images)
|
||||
# https://docs.djangoproject.com/en/1.11/howto/static-files/
|
||||
|
||||
STATIC_URL = '/static/'
|
||||
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
|
||||
STATICFILES_DIRS = [
|
||||
os.path.join(BASE_DIR, 'testproj', 'static'),
|
||||
]
|
||||
|
||||
# Testing
|
||||
|
||||
TEST_RUNNER = 'testproj.runner.PytestTestRunner'
|
||||
|
||||
# Logging configuration
|
||||
|
||||
LOGGING = {
|
||||
'version': 1,
|
||||
'disable_existing_loggers': True,
|
||||
|
||||
@@ -23,8 +23,6 @@ STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
|
||||
MIDDLEWARE.insert(0, 'whitenoise.middleware.WhiteNoiseMiddleware')
|
||||
|
||||
# Database
|
||||
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases
|
||||
|
||||
DATABASES = {
|
||||
'default': dj_database_url.config(conn_max_age=600)
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@ DATABASES = {
|
||||
}
|
||||
|
||||
# Quick-start development settings - unsuitable for production
|
||||
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/
|
||||
|
||||
# SECURITY WARNING: keep the secret key used in production secret!
|
||||
SECRET_KEY = '!z1yj(9uz)zk0gg@5--j)bc4h^i!8))r^dezco8glf190e0&#p'
|
||||
|
||||
@@ -47,6 +47,12 @@ def root_redirect(request):
|
||||
return redirect(schema_view, permanent=True)
|
||||
|
||||
|
||||
# urlpatterns required for settings values
|
||||
required_urlpatterns = [
|
||||
url(r'^admin/', admin.site.urls),
|
||||
url(r'^o/', include('oauth2_provider.urls', namespace='oauth2_provider')),
|
||||
]
|
||||
|
||||
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'),
|
||||
@@ -59,11 +65,10 @@ urlpatterns = [
|
||||
|
||||
url(r'^$', root_redirect),
|
||||
|
||||
url(r'^admin/', admin.site.urls),
|
||||
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),
|
||||
]
|
||||
] + required_urlpatterns
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
from django.templatetags.static import static
|
||||
from django.utils.functional import lazy
|
||||
|
||||
static_lazy = lazy(static, str)
|
||||
@@ -0,0 +1,37 @@
|
||||
# Generated by Django 2.1.3 on 2018-12-19 08:07
|
||||
import sys
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.hashers import make_password
|
||||
from django.db import migrations, IntegrityError
|
||||
|
||||
|
||||
def add_default_user(apps, schema_editor):
|
||||
username = 'admin'
|
||||
email = 'admin@admin.admin'
|
||||
password = 'passwordadmin'
|
||||
User = apps.get_model(settings.AUTH_USER_MODEL)
|
||||
|
||||
try:
|
||||
admin = User(
|
||||
username=username,
|
||||
email=email,
|
||||
password=make_password(password),
|
||||
is_superuser=True,
|
||||
is_staff=True
|
||||
)
|
||||
admin.save()
|
||||
except IntegrityError:
|
||||
sys.stdout.write(" User '%s <%s>' already exists..." % (username, email))
|
||||
else:
|
||||
sys.stdout.write(" Created superuser '%s <%s>' with password '%s'!" % (username, email, password))
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(add_default_user)
|
||||
]
|
||||
@@ -0,0 +1,39 @@
|
||||
# Generated by Django 2.1.3 on 2018-12-19 07:57
|
||||
from django.conf import settings
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
def add_oauth_apps(apps, schema_editor):
|
||||
# We can't import the Person model directly as it may be a newer
|
||||
# version than this migration expects. We use the historical version.
|
||||
User = apps.get_model(settings.AUTH_USER_MODEL)
|
||||
Application = apps.get_model('oauth2_provider', 'application')
|
||||
|
||||
user = User.objects.get(username='admin')
|
||||
|
||||
oauth2_apps = [
|
||||
{
|
||||
"user": user,
|
||||
"client_type": "public",
|
||||
"authorization_grant_type": "password",
|
||||
"client_id": settings.OAUTH2_CLIENT_ID,
|
||||
"client_secret": settings.OAUTH2_CLIENT_SECRET,
|
||||
"redirect_uris": settings.OAUTH2_REDIRECT_URL,
|
||||
"name": settings.OAUTH2_APP_NAME
|
||||
}
|
||||
]
|
||||
|
||||
for app in oauth2_apps:
|
||||
Application.objects.get_or_create(client_id=app['client_id'], defaults=app)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
('oauth2_provider', '0006_auto_20171214_2232'),
|
||||
('users', '0001_create_admin_user'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(add_oauth_apps)
|
||||
]
|
||||
@@ -81,3 +81,4 @@ class UserSerializerrr(serializers.ModelSerializer):
|
||||
class UserListQuerySerializer(serializers.Serializer):
|
||||
username = serializers.CharField(help_text="this field is generated from a query_serializer", required=False)
|
||||
is_staff = serializers.BooleanField(help_text="this one too!", required=False)
|
||||
styles = serializers.MultipleChoiceField(help_text="and this one is fancy!", choices=('a', 'b', 'c', 'd'))
|
||||
|
||||
+12
-5
@@ -13,7 +13,11 @@ from users.serializers import UserListQuerySerializer, UserSerializerrr
|
||||
class UserList(APIView):
|
||||
"""UserList cbv classdoc"""
|
||||
|
||||
@swagger_auto_schema(query_serializer=UserListQuerySerializer, responses={200: UserSerializerrr(many=True)})
|
||||
@swagger_auto_schema(
|
||||
query_serializer=UserListQuerySerializer,
|
||||
responses={200: UserSerializerrr(many=True)},
|
||||
tags=['Users'],
|
||||
)
|
||||
def get(self, request):
|
||||
queryset = User.objects.all()
|
||||
serializer = UserSerializerrr(queryset, many=True)
|
||||
@@ -28,7 +32,8 @@ class UserList(APIView):
|
||||
'username': openapi.Schema(type=openapi.TYPE_STRING)
|
||||
},
|
||||
),
|
||||
security=[]
|
||||
security=[],
|
||||
tags=['Users'],
|
||||
)
|
||||
def post(self, request):
|
||||
serializer = UserSerializerrr(request.data)
|
||||
@@ -36,17 +41,19 @@ class UserList(APIView):
|
||||
serializer.save()
|
||||
return Response(serializer.data, status=status.HTTP_201_CREATED)
|
||||
|
||||
@swagger_auto_schema(operation_id="users_dummy", operation_description="dummy operation")
|
||||
@swagger_auto_schema(operation_id="users_dummy", operation_description="dummy operation", tags=['Users'])
|
||||
def patch(self, request):
|
||||
pass
|
||||
|
||||
|
||||
@swagger_auto_schema(method='put', request_body=UserSerializerrr)
|
||||
@swagger_auto_schema(method='put', request_body=UserSerializerrr, tags=['Users'])
|
||||
@swagger_auto_schema(methods=['get'], manual_parameters=[
|
||||
openapi.Parameter('test', openapi.IN_QUERY, "test manual param", type=openapi.TYPE_BOOLEAN),
|
||||
openapi.Parameter('test_array', openapi.IN_QUERY, "test query array arg", type=openapi.TYPE_ARRAY,
|
||||
items=openapi.Items(type=openapi.TYPE_STRING), required=True, collection_format='multi'),
|
||||
], responses={
|
||||
200: openapi.Response('response description', UserSerializerrr),
|
||||
})
|
||||
}, tags=['Users'])
|
||||
@api_view(['GET', 'PUT'])
|
||||
def user_detail(request, pk):
|
||||
"""user_detail fbv docstring"""
|
||||
|
||||
+9
-5
@@ -22,8 +22,7 @@ def mock_schema_request(db):
|
||||
from rest_framework.test import force_authenticate
|
||||
|
||||
factory = APIRequestFactory()
|
||||
user = User.objects.create_user(username='admin', is_staff=True, is_superuser=True)
|
||||
|
||||
user = User.objects.get(username='admin')
|
||||
request = factory.get('/swagger.json')
|
||||
force_authenticate(request, user=user)
|
||||
request = APIView().initialize_request(request)
|
||||
@@ -56,12 +55,17 @@ def swagger_dict(swagger, codec_json):
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def validate_schema(db):
|
||||
def validate_schema():
|
||||
def validate_schema(swagger):
|
||||
from flex.core import parse as validate_flex
|
||||
try:
|
||||
from flex.core import parse as validate_flex
|
||||
|
||||
validate_flex(copy.deepcopy(swagger))
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
from swagger_spec_validator.validator20 import validate_spec as validate_ssv
|
||||
|
||||
validate_flex(copy.deepcopy(swagger))
|
||||
validate_ssv(copy.deepcopy(swagger))
|
||||
|
||||
return validate_schema
|
||||
|
||||
+70
-9
@@ -27,9 +27,22 @@ securityDefinitions:
|
||||
in: header
|
||||
name: Authorization
|
||||
type: apiKey
|
||||
OAuth2 password:
|
||||
flow: password
|
||||
scopes:
|
||||
read: Read everything.
|
||||
write: Write everything,
|
||||
tokenUrl: /o/token/
|
||||
type: oauth2
|
||||
Query:
|
||||
in: query
|
||||
name: auth
|
||||
type: apiKey
|
||||
security:
|
||||
- Basic: []
|
||||
- Bearer: []
|
||||
- OAuth2 password: []
|
||||
- Query: []
|
||||
paths:
|
||||
/articles/:
|
||||
get:
|
||||
@@ -70,9 +83,11 @@ paths:
|
||||
next:
|
||||
type: string
|
||||
format: uri
|
||||
x-nullable: true
|
||||
previous:
|
||||
type: string
|
||||
format: uri
|
||||
x-nullable: true
|
||||
results:
|
||||
type: array
|
||||
items:
|
||||
@@ -207,6 +222,7 @@ paths:
|
||||
pattern: ^69$
|
||||
default: '69'
|
||||
minLength: 1
|
||||
x-nullable: true
|
||||
- name: image_styles
|
||||
in: formData
|
||||
description: Parameter with Items
|
||||
@@ -233,6 +249,21 @@ paths:
|
||||
- multipart/form-data
|
||||
tags:
|
||||
- articles
|
||||
delete:
|
||||
operationId: articles_image_delete
|
||||
description: image method docstring
|
||||
parameters:
|
||||
- name: delete_form_param
|
||||
in: formData
|
||||
description: this should not crash (form parameter on DELETE method)
|
||||
type: integer
|
||||
responses:
|
||||
'204':
|
||||
description: ''
|
||||
consumes:
|
||||
- multipart/form-data
|
||||
tags:
|
||||
- articles
|
||||
parameters:
|
||||
- name: slug
|
||||
in: path
|
||||
@@ -462,10 +493,6 @@ paths:
|
||||
description: path parameter override
|
||||
required: true
|
||||
type: integer
|
||||
- name: delete_form_param
|
||||
in: formData
|
||||
description: this should not crash (form parameter on DELETE method)
|
||||
type: integer
|
||||
responses:
|
||||
'204':
|
||||
description: this should not crash (response object with no schema)
|
||||
@@ -734,6 +761,19 @@ paths:
|
||||
description: this one too!
|
||||
required: false
|
||||
type: boolean
|
||||
- name: styles
|
||||
in: query
|
||||
description: and this one is fancy!
|
||||
required: true
|
||||
type: array
|
||||
items:
|
||||
type: string
|
||||
enum:
|
||||
- a
|
||||
- b
|
||||
- c
|
||||
- d
|
||||
collectionFormat: multi
|
||||
responses:
|
||||
'200':
|
||||
description: ''
|
||||
@@ -742,7 +782,7 @@ paths:
|
||||
items:
|
||||
$ref: '#/definitions/UserSerializerrr'
|
||||
tags:
|
||||
- users
|
||||
- Users
|
||||
post:
|
||||
operationId: users_create
|
||||
description: apiview post description override
|
||||
@@ -768,7 +808,7 @@ paths:
|
||||
username:
|
||||
type: string
|
||||
tags:
|
||||
- users
|
||||
- Users
|
||||
security: []
|
||||
patch:
|
||||
operationId: users_dummy
|
||||
@@ -778,7 +818,7 @@ paths:
|
||||
'200':
|
||||
description: ''
|
||||
tags:
|
||||
- users
|
||||
- Users
|
||||
parameters: []
|
||||
/users/{id}/:
|
||||
get:
|
||||
@@ -789,13 +829,21 @@ paths:
|
||||
in: query
|
||||
description: test manual param
|
||||
type: boolean
|
||||
- name: test_array
|
||||
in: query
|
||||
description: test query array arg
|
||||
required: true
|
||||
type: array
|
||||
items:
|
||||
type: string
|
||||
collectionFormat: multi
|
||||
responses:
|
||||
'200':
|
||||
description: response description
|
||||
schema:
|
||||
$ref: '#/definitions/UserSerializerrr'
|
||||
tags:
|
||||
- users
|
||||
- Users
|
||||
put:
|
||||
operationId: users_update
|
||||
description: user_detail fbv docstring
|
||||
@@ -811,7 +859,7 @@ paths:
|
||||
schema:
|
||||
$ref: '#/definitions/UserSerializerrr'
|
||||
tags:
|
||||
- users
|
||||
- Users
|
||||
parameters:
|
||||
- name: id
|
||||
in: path
|
||||
@@ -885,6 +933,7 @@ definitions:
|
||||
- 3
|
||||
- 7
|
||||
- 8
|
||||
x-nullable: true
|
||||
group:
|
||||
type: string
|
||||
format: uuid
|
||||
@@ -897,12 +946,17 @@ definitions:
|
||||
- image_styles
|
||||
type: object
|
||||
properties:
|
||||
image_id:
|
||||
type: string
|
||||
format: uuid
|
||||
readOnly: true
|
||||
what_am_i_doing:
|
||||
description: test
|
||||
type: string
|
||||
pattern: ^69$
|
||||
default: '69'
|
||||
minLength: 1
|
||||
x-nullable: true
|
||||
image_styles:
|
||||
description: Parameter with Items
|
||||
type: array
|
||||
@@ -931,12 +985,14 @@ definitions:
|
||||
type: string
|
||||
maxLength: 30
|
||||
minLength: 1
|
||||
x-nullable: true
|
||||
last_name:
|
||||
title: Last name
|
||||
description: <strong>Here's some HTML!</strong>
|
||||
type: string
|
||||
maxLength: 30
|
||||
minLength: 1
|
||||
x-nullable: true
|
||||
Person:
|
||||
required:
|
||||
- identity
|
||||
@@ -1149,6 +1205,7 @@ definitions:
|
||||
- fan
|
||||
- fancy
|
||||
- felix
|
||||
- fennel
|
||||
- fish
|
||||
- flatline
|
||||
- forth
|
||||
@@ -1174,6 +1231,7 @@ definitions:
|
||||
- haskell
|
||||
- haxeml
|
||||
- hexdump
|
||||
- hlsl
|
||||
- hsail
|
||||
- html
|
||||
- html+cheetah
|
||||
@@ -1440,6 +1498,7 @@ definitions:
|
||||
- xml+php
|
||||
- xml+smarty
|
||||
- xml+velocity
|
||||
- xorg.conf
|
||||
- xquery
|
||||
- xslt
|
||||
- xtend
|
||||
@@ -1488,6 +1547,7 @@ definitions:
|
||||
type: array
|
||||
items:
|
||||
type: integer
|
||||
x-nullable: true
|
||||
exampleProjects:
|
||||
type: array
|
||||
items:
|
||||
@@ -1552,6 +1612,7 @@ definitions:
|
||||
parent_id:
|
||||
type: integer
|
||||
title: Parent id
|
||||
x-nullable: true
|
||||
TodoTree:
|
||||
required:
|
||||
- title
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
import pytest
|
||||
from django.conf.urls import url
|
||||
from django.utils.decorators import method_decorator
|
||||
from rest_framework.authtoken.views import ObtainAuthToken
|
||||
from rest_framework.settings import api_settings
|
||||
|
||||
from drf_yasg import openapi
|
||||
from drf_yasg.errors import SwaggerGenerationError
|
||||
from drf_yasg.generators import OpenAPISchemaGenerator
|
||||
from drf_yasg.utils import swagger_auto_schema
|
||||
|
||||
|
||||
def test_no_form_parameters_with_non_form_parsers():
|
||||
# see https://github.com/axnsan12/drf-yasg/issues/270
|
||||
# test that manual form parameters for views that haven't set
|
||||
# all their parsers classes to form parsers are not allowed
|
||||
# even when the request body is empty
|
||||
|
||||
@method_decorator(name='post', decorator=swagger_auto_schema(
|
||||
operation_description="Logins a user and returns a token",
|
||||
manual_parameters=[
|
||||
openapi.Parameter(
|
||||
"username",
|
||||
openapi.IN_FORM,
|
||||
required=True,
|
||||
type=openapi.TYPE_STRING,
|
||||
description="Valid username or email for authentication"
|
||||
),
|
||||
]
|
||||
))
|
||||
class CustomObtainAuthToken(ObtainAuthToken):
|
||||
throttle_classes = api_settings.DEFAULT_THROTTLE_CLASSES
|
||||
|
||||
urlpatterns = [
|
||||
url(r'token/$', CustomObtainAuthToken.as_view()),
|
||||
]
|
||||
|
||||
generator = OpenAPISchemaGenerator(
|
||||
info=openapi.Info(title="Test generator", default_version="v1"),
|
||||
patterns=urlpatterns
|
||||
)
|
||||
|
||||
with pytest.raises(SwaggerGenerationError):
|
||||
generator.get_schema(None, True)
|
||||
@@ -0,0 +1,39 @@
|
||||
import uuid
|
||||
|
||||
import pytest
|
||||
|
||||
from drf_yasg import openapi
|
||||
from drf_yasg.inspectors.field import get_basic_type_info_from_hint
|
||||
|
||||
try:
|
||||
import typing
|
||||
from typing import Dict, List, Union, Optional, Set
|
||||
except ImportError:
|
||||
typing = None
|
||||
|
||||
if typing:
|
||||
@pytest.mark.parametrize('hint_class, expected_swagger_type_info', [
|
||||
(int, {'type': openapi.TYPE_INTEGER, 'format': None}),
|
||||
(str, {'type': openapi.TYPE_STRING, 'format': None}),
|
||||
(bool, {'type': openapi.TYPE_BOOLEAN, 'format': None}),
|
||||
(dict, {'type': openapi.TYPE_OBJECT, 'format': None}),
|
||||
(Dict[int, int], {'type': openapi.TYPE_OBJECT, 'format': None}),
|
||||
(uuid.UUID, {'type': openapi.TYPE_STRING, 'format': openapi.FORMAT_UUID}),
|
||||
(List[int], {'type': openapi.TYPE_ARRAY, 'items': openapi.Items(openapi.TYPE_INTEGER)}),
|
||||
(List[str], {'type': openapi.TYPE_ARRAY, 'items': openapi.Items(openapi.TYPE_STRING)}),
|
||||
(List[bool], {'type': openapi.TYPE_ARRAY, 'items': openapi.Items(openapi.TYPE_BOOLEAN)}),
|
||||
(Set[int], {'type': openapi.TYPE_ARRAY, 'items': openapi.Items(openapi.TYPE_INTEGER)}),
|
||||
(Optional[bool], {'type': openapi.TYPE_BOOLEAN, 'format': None, 'x-nullable': True}),
|
||||
(Optional[List[int]], {
|
||||
'type': openapi.TYPE_ARRAY, 'items': openapi.Items(openapi.TYPE_INTEGER), 'x-nullable': True
|
||||
}),
|
||||
(Union[List[int], type(None)], {
|
||||
'type': openapi.TYPE_ARRAY, 'items': openapi.Items(openapi.TYPE_INTEGER), 'x-nullable': True
|
||||
}),
|
||||
# Following cases are not 100% correct, but it should work somehow and not crash.
|
||||
(Union[int, float], None),
|
||||
(List, {'type': openapi.TYPE_ARRAY, 'items': openapi.Items(openapi.TYPE_STRING)}),
|
||||
])
|
||||
def test_get_basic_type_info_from_hint(hint_class, expected_swagger_type_info):
|
||||
type_info = get_basic_type_info_from_hint(hint_class)
|
||||
assert type_info == expected_swagger_type_info
|
||||
@@ -6,7 +6,6 @@ import tempfile
|
||||
from collections import OrderedDict
|
||||
|
||||
import pytest
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
from drf_yasg import openapi
|
||||
from drf_yasg.codecs import yaml_sane_load
|
||||
@@ -14,8 +13,6 @@ from drf_yasg.generators import OpenAPISchemaGenerator
|
||||
|
||||
|
||||
def test_reference_schema(call_generate_swagger, db, reference_schema):
|
||||
User.objects.create_superuser('admin', 'admin@admin.admin', 'blabla')
|
||||
|
||||
output = call_generate_swagger(format='yaml', api_url='http://test.local:8002/', user='admin')
|
||||
output_schema = yaml_sane_load(output)
|
||||
assert output_schema == reference_schema
|
||||
|
||||
@@ -3,6 +3,7 @@ from collections import OrderedDict
|
||||
|
||||
import pytest
|
||||
from django.conf.urls import url
|
||||
from django.utils.inspect import get_func_args
|
||||
from rest_framework import routers, serializers, viewsets
|
||||
from rest_framework.decorators import api_view
|
||||
from rest_framework.response import Response
|
||||
@@ -86,6 +87,14 @@ def test_securiy_requirements(swagger_settings, mock_schema_request):
|
||||
assert swagger['security'] == []
|
||||
|
||||
|
||||
def _basename_or_base_name(basename):
|
||||
# freaking DRF... TODO: remove when dropping support for DRF 3.8
|
||||
if 'basename' in get_func_args(routers.BaseRouter.register):
|
||||
return {'basename': basename}
|
||||
else:
|
||||
return {'base_name': basename}
|
||||
|
||||
|
||||
def test_replaced_serializer():
|
||||
class DetailSerializer(serializers.Serializer):
|
||||
detail = serializers.CharField()
|
||||
@@ -99,7 +108,7 @@ def test_replaced_serializer():
|
||||
return Response(serializer.data)
|
||||
|
||||
router = routers.DefaultRouter()
|
||||
router.register(r'details', DetailViewSet, base_name='details')
|
||||
router.register(r'details', DetailViewSet, **_basename_or_base_name('details'))
|
||||
|
||||
generator = OpenAPISchemaGenerator(
|
||||
info=openapi.Info(title="Test generator", default_version="v1"),
|
||||
@@ -146,7 +155,8 @@ def test_url_order():
|
||||
assert swagger['paths']['/test/']['get']['description'] == 'description override'
|
||||
|
||||
# get_endpoints only includes one endpoint
|
||||
assert len(generator.get_endpoints(None)['/test/'][1]) == 1
|
||||
endpoints = generator.get_endpoints(None)
|
||||
assert len(endpoints['/test/'][1]) == 1
|
||||
|
||||
|
||||
try:
|
||||
@@ -172,7 +182,7 @@ def test_action_mapping():
|
||||
pass
|
||||
|
||||
router = routers.DefaultRouter()
|
||||
router.register(r'action', ActionViewSet, base_name='action')
|
||||
router.register(r'action', ActionViewSet, **_basename_or_base_name('action'))
|
||||
|
||||
generator = OpenAPISchemaGenerator(
|
||||
info=openapi.Info(title="Test generator", default_version="v1"),
|
||||
@@ -190,3 +200,32 @@ def test_action_mapping():
|
||||
assert action_ops['post']['description'] == 'mapping docstring post'
|
||||
assert action_ops['get']['description'] == 'mapping docstring get/delete'
|
||||
assert action_ops['delete']['description'] == 'mapping docstring get/delete'
|
||||
|
||||
|
||||
@pytest.mark.parametrize('choices, expected_type', [
|
||||
(['A', 'B'], openapi.TYPE_STRING),
|
||||
([123, 456], openapi.TYPE_INTEGER),
|
||||
([1.2, 3.4], openapi.TYPE_NUMBER),
|
||||
(['A', 456], openapi.TYPE_STRING)
|
||||
])
|
||||
def test_choice_field(choices, expected_type):
|
||||
class DetailSerializer(serializers.Serializer):
|
||||
detail = serializers.ChoiceField(choices)
|
||||
|
||||
class DetailViewSet(viewsets.ViewSet):
|
||||
@swagger_auto_schema(responses={200: openapi.Response("OK", DetailSerializer)})
|
||||
def retrieve(self, request, pk=None):
|
||||
return Response({'detail': None})
|
||||
|
||||
router = routers.DefaultRouter()
|
||||
router.register(r'details', DetailViewSet, **_basename_or_base_name('details'))
|
||||
|
||||
generator = OpenAPISchemaGenerator(
|
||||
info=openapi.Info(title="Test generator", default_version="v1"),
|
||||
patterns=router.urls
|
||||
)
|
||||
|
||||
swagger = generator.get_schema(None, True)
|
||||
property_schema = swagger['definitions']['Detail']['properties']['detail']
|
||||
|
||||
assert property_schema == openapi.Schema(title='Detail', type=expected_type, enum=choices)
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
from django.conf.urls import url
|
||||
|
||||
from testproj.urls import required_urlpatterns
|
||||
|
||||
|
||||
def dummy(request):
|
||||
pass
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
urlpatterns = required_urlpatterns + [
|
||||
url(r'^test/login$', dummy, name='login'),
|
||||
url(r'^test/logout$', dummy, name='logout'),
|
||||
]
|
||||
|
||||
@@ -3,6 +3,7 @@ from rest_framework import generics, versioning
|
||||
|
||||
from snippets.models import Snippet
|
||||
from snippets.serializers import SnippetSerializer
|
||||
from testproj.urls import required_urlpatterns
|
||||
|
||||
|
||||
class SnippetList(generics.ListCreateAPIView):
|
||||
@@ -21,6 +22,6 @@ class SnippetList(generics.ListCreateAPIView):
|
||||
|
||||
app_name = 'test_ns_versioning'
|
||||
|
||||
urlpatterns = [
|
||||
urlpatterns = required_urlpatterns + [
|
||||
url(r"^$", SnippetList.as_view())
|
||||
]
|
||||
|
||||
@@ -2,6 +2,7 @@ from django.conf.urls import url
|
||||
from rest_framework import fields
|
||||
|
||||
from snippets.serializers import SnippetSerializer
|
||||
from testproj.urls import required_urlpatterns
|
||||
|
||||
from .ns_version1 import SnippetList as SnippetListV1
|
||||
|
||||
@@ -19,6 +20,6 @@ class SnippetListV2(SnippetListV1):
|
||||
|
||||
app_name = '2.0'
|
||||
|
||||
urlpatterns = [
|
||||
urlpatterns = required_urlpatterns + [
|
||||
url(r"^$", SnippetListV2.as_view())
|
||||
]
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from django.conf.urls import include, url
|
||||
from rest_framework import versioning
|
||||
|
||||
from testproj.urls import SchemaView
|
||||
from testproj.urls import SchemaView, required_urlpatterns
|
||||
|
||||
from . import ns_version1, ns_version2
|
||||
|
||||
@@ -17,7 +17,7 @@ schema_patterns = [
|
||||
]
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
urlpatterns = required_urlpatterns + [
|
||||
url(VERSION_PREFIX_NS + r"v1.0/snippets/", include(ns_version1, namespace='1.0')),
|
||||
url(VERSION_PREFIX_NS + r"v2.0/snippets/", include(ns_version2)),
|
||||
url(VERSION_PREFIX_NS + r'v1.0/', include((schema_patterns, '1.0'))),
|
||||
|
||||
@@ -3,7 +3,7 @@ from rest_framework import fields, generics, versioning
|
||||
|
||||
from snippets.models import Snippet
|
||||
from snippets.serializers import SnippetSerializer
|
||||
from testproj.urls import SchemaView
|
||||
from testproj.urls import SchemaView, required_urlpatterns
|
||||
|
||||
|
||||
class SnippetSerializerV2(SnippetSerializer):
|
||||
@@ -42,7 +42,7 @@ class VersionedSchemaView(SchemaView):
|
||||
versioning_class = versioning.URLPathVersioning
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
urlpatterns = required_urlpatterns + [
|
||||
url(VERSION_PREFIX_URL + r"snippets/$", SnippetList.as_view()),
|
||||
url(VERSION_PREFIX_URL + r'swagger(?P<format>.json|.yaml)$', VersionedSchemaView.without_ui(), name='vschema-json'),
|
||||
]
|
||||
|
||||
@@ -1,11 +1,19 @@
|
||||
[tox]
|
||||
minversion = 3.3.0
|
||||
isolated_build = true
|
||||
isolated_build_env=.package
|
||||
|
||||
# https://docs.djangoproject.com/en/dev/faq/install/#what-python-version-can-i-use-with-django
|
||||
envlist =
|
||||
py{27,34,35,36}-django111-drf{37,38},
|
||||
py{34,35,36,37}-django20-drf{37,38},
|
||||
py{35,36,37}-django21-drf{37,38},
|
||||
py{27,34,35,36}-django111-drf{37,38,39},
|
||||
py{34,35,36,37}-django20-drf{37,38,39},
|
||||
py{35,36,37}-django21-drf{37,38,39},
|
||||
djmaster, lint, docs
|
||||
|
||||
[testenv:.package]
|
||||
# no additional dependencies besides PEP 517
|
||||
deps =
|
||||
|
||||
[testenv]
|
||||
deps =
|
||||
django111: Django>=1.11,<2.0
|
||||
@@ -14,44 +22,42 @@ deps =
|
||||
|
||||
drf37: djangorestframework>=3.7.7,<3.8
|
||||
drf38: djangorestframework>=3.8.0,<3.9
|
||||
drf39: djangorestframework>=3.9,<3.10
|
||||
|
||||
# test with the latest build of django-rest-framework to get early warning of compatibility issues
|
||||
djmaster: https://github.com/encode/django-rest-framework/archive/master.tar.gz
|
||||
djmaster: https://github.com/django/django/archive/master.tar.gz
|
||||
|
||||
# other dependencies
|
||||
-rrequirements/setup.txt
|
||||
-rrequirements/validation.txt
|
||||
-rrequirements/test.txt
|
||||
-r requirements/validation.txt
|
||||
-r requirements/test.txt
|
||||
|
||||
commands =
|
||||
pytest --cov --cov-config .coveragerc --cov-append --cov-report="" {posargs}
|
||||
pytest -n 2 --cov --cov-config .coveragerc --cov-append --cov-report="" {posargs}
|
||||
|
||||
[testenv:lint]
|
||||
skip_install = true
|
||||
deps =
|
||||
-rrequirements/setup.txt
|
||||
-rrequirements/lint.txt
|
||||
-r requirements/lint.txt
|
||||
commands =
|
||||
flake8 src/drf_yasg testproj tests setup.py
|
||||
|
||||
[testenv:docs]
|
||||
deps =
|
||||
-rrequirements/setup.txt
|
||||
-rrequirements/docs.txt
|
||||
-r requirements/docs.txt
|
||||
commands =
|
||||
python setup.py check --restructuredtext --metadata --strict
|
||||
twine check .tox/dist/*
|
||||
sphinx-build -WnEa -b html docs docs/_build/html
|
||||
|
||||
[pytest]
|
||||
DJANGO_SETTINGS_MODULE = testproj.settings.local
|
||||
python_paths = testproj
|
||||
addopts = -n 2 --ignore=node_modules
|
||||
addopts = --ignore=node_modules
|
||||
|
||||
[flake8]
|
||||
max-line-length = 120
|
||||
exclude = **/migrations/*
|
||||
ignore = F405
|
||||
ignore = F405,W504
|
||||
|
||||
[isort]
|
||||
skip = .eggs,.tox,docs,env,venv,node_modules
|
||||
@@ -67,5 +73,5 @@ known_standard_library =
|
||||
known_third_party =
|
||||
coreapi,coreschema,datadiff,dj_database_url,django,django_filters,djangorestframework_camel_case,
|
||||
rest_framework_recursive,flex,gunicorn,inflection,pygments,pytest,rest_framework,ruamel,setuptools_scm,
|
||||
swagger_spec_validator,uritemplate,user_agents,whitenoise
|
||||
swagger_spec_validator,uritemplate,user_agents,whitenoise,oauth2_provider
|
||||
known_first_party = drf_yasg,testproj,articles,people,snippets,todo,users,urlconfs
|
||||
|
||||
+2
-2
@@ -7,6 +7,6 @@ wget https://rebilly.github.io/ReDoc/releases/v1.x.x/redoc.min.js -O src/drf_yas
|
||||
|
||||
cp -r node_modules/swagger-ui-dist src/drf_yasg/static/drf-yasg/
|
||||
pushd src/drf_yasg/static/drf-yasg/swagger-ui-dist/ >/dev/null
|
||||
rm -f package.json .npmignore README.md
|
||||
rm -f index.html *.map
|
||||
rm -f package.json .npmignore README.md favicon-16x16.png
|
||||
rm -f swagger-ui.js index.html *.map
|
||||
popd >/dev/null
|
||||
|
||||
Reference in New Issue
Block a user