Skip to content

Commit

Permalink
Merge branch 'master' of github.com:axnsan12/drf-yasg
Browse files Browse the repository at this point in the history
  • Loading branch information
Wesley Lima committed Nov 8, 2024
2 parents b9470f8 + 5201715 commit 49d41b0
Show file tree
Hide file tree
Showing 18 changed files with 115 additions and 52 deletions.
6 changes: 3 additions & 3 deletions .github/actions/install/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ runs:
using: composite
steps:
- name: Checkout the source code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Set the python version
uses: actions/setup-python@v3
uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python-version }}

- name: Set up pip package caching
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
Expand Down
13 changes: 13 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Keep GitHub Actions up to date with GitHub's Dependabot...
# https://docs.github.com/en/code-security/dependabot/working-with-dependabot/keeping-your-actions-up-to-date-with-dependabot
# https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file#package-ecosystem
version: 2
updates:
- package-ecosystem: github-actions
directory: /
groups:
github-actions:
patterns:
- "*" # Group all Actions updates into a single larger pull request
schedule:
interval: weekly
12 changes: 4 additions & 8 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,17 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout the source code
uses: actions/checkout@v2
uses: actions/checkout@v4

# This is the version of python used to package the code. The unit
# tests will have run against python 3.6, 3.7 etc ensuring
# compatibility with those runtimes.
# https://github.com/axnsan12/drf-yasg/pull/741#discussion_r713297594
- name: Set the python version
uses: actions/setup-python@v3
uses: actions/setup-python@v5
with:
python-version: 3.8
python-version: 3.11

- name: Install dependencies
uses: ./.github/actions/install
with:
python-version: 3.8
python-version: 3.11

- name: Install builders for publishing
run: pip install -r requirements/publish.txt
Expand Down
13 changes: 7 additions & 6 deletions .github/workflows/review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ jobs:
name: Run linters and tests
runs-on: "ubuntu-20.04"
strategy:
fail-fast: false
matrix:
python: ["3.6", "3.7", "3.10", "3.11"]

steps:
- name: Checkout the source code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Set the python version
uses: actions/setup-python@v3
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}

Expand All @@ -25,23 +26,23 @@ jobs:
python-version: ${{ matrix.python }}

- name: Run tests

# Python 3.6 tests have been removed since swagger-spec-validator no longer supports it.
# A successful workflow run for Python 3.6 is required by the GitHub branch protection rules.
if: ${{ matrix.python != 3.6 }}

env:
PYTHON_VERSION: ${{ matrix.python }}
run: tox -e $(tox -l | grep py${PYTHON_VERSION//.} | paste -sd "," -)

- name: Report coverage
if: ${{ matrix.python == 3.9 }}
if: ${{ matrix.python != 3.6 }}
run: |
pip install coverage
coverage report
- name: Check for incompatibilities with publishing to PyPi
if: ${{ matrix.python == 3.8 }}
if: ${{ matrix.python == 3.11 }}
run: |
pip install -r requirements/publish.txt
python setup.py sdist
Expand Down
32 changes: 18 additions & 14 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
drf-yasg - Yet another Swagger generator
########################################

|actions| |nbsp| |codecov| |nbsp| |rtd-badge| |nbsp| |pypi-version|
|actions| |nbsp| |codecov| |nbsp| |rtd-badge| |nbsp| |pypi-version| |nbsp| |gitter|

Generate **real** Swagger/OpenAPI 2.0 specifications from a Django Rest Framework API.

Compatible with

- **Django Rest Framework**: 3.10, 3.11, 3.12, 3.13, 3.14
- **Django**: 2.2, 3.0, 3.1, 3.2, 4.0, 4.1
- **Python**: 3.6, 3.7, 3.8, 3.9, 3.10, 3.11
- **Django**: 2.2, 3.0, 3.1, 3.2, 4.0, 4.1, 4.2
- **Python**: 3.6, 3.7, 3.8, 3.9, 3.10, 3.11, 3.12

Only the latest patch version of each ``major.minor`` series of Python, Django and Django REST Framework is supported.

Expand All @@ -24,14 +24,14 @@ through a deprecation cycle of a few minor releases.

Resources:

* **Source**: https://github.com/axnsan12/drf-yasg/
* **Documentation**: https://drf-yasg.readthedocs.io/
* **Changelog**: https://drf-yasg.readthedocs.io/en/stable/changelog.html
* **Live demo**: https://drf-yasg-demo.herokuapp.com/
* `Sources <https://github.com/axnsan12/drf-yasg>`_
* `Documentation <https://drf-yasg.readthedocs.io>`_
* `Changelog <https://drf-yasg.readthedocs.io/en/stable/changelog.html>`_
* `Live demo <https://drf-yasg-demo.herokuapp.com>`_
* `Discussion <https://app.gitter.im/#/room/#drf-yasg:gitter.im>`_

|heroku-button|


****************
OpenAPI 3.0 note
****************
Expand Down Expand Up @@ -102,14 +102,14 @@ The preferred installation method is directly from pypi:

.. code:: console
pip install -U drf-yasg
pip install --upgrade drf-yasg
Additionally, if you want to use the built-in validation mechanisms (see `4. Validation`_), you need to install
some extra requirements:

.. code:: console
pip install -U drf-yasg[validation]
pip install --upgrade drf-yasg[validation]
.. _readme-quickstart:

Expand Down Expand Up @@ -297,7 +297,7 @@ You can use the specification outputted by this library together with
$ docker run --rm -v ${PWD}:/local swaggerapi/swagger-codegen-cli generate -i /local/tests/reference.yaml -l javascript -o /local/.codegen/js
See the github page linked above for more details.
See the GitHub page linked above for more details.

.. _readme-testproj:

Expand All @@ -313,8 +313,8 @@ 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 -m pip install --upgrade pip setuptools
(venv) $ pip install --upgrade -r requirements.txt
(venv) $ python manage.py migrate
(venv) $ python manage.py runserver
(venv) $ firefox localhost:8000/swagger/
Expand All @@ -336,7 +336,7 @@ djangorestframework-recursive
Integration with `djangorestframework-recursive <https://github.com/heywbj/django-rest-framework-recursive>`_ is
provided out of the box - if you have ``djangorestframework-recursive`` installed.

.. |actions| image:: https://img.shields.io/github/workflow/status/axnsan12/drf-yasg/Review
.. |actions| image:: https://img.shields.io/github/actions/workflow/status/axnsan12/drf-yasg/review.yml?branch=master
:target: https://github.com/axnsan12/drf-yasg/actions
:alt: GitHub Workflow Status

Expand All @@ -348,6 +348,10 @@ provided out of the box - if you have ``djangorestframework-recursive`` installe
:target: https://pypi.org/project/drf-yasg/
:alt: PyPI

.. |gitter| image:: https://badges.gitter.im/drf-yasg.svg
:target: https://app.gitter.im/#/room/#drf-yasg:gitter.im
:alt: Gitter

.. |rtd-badge| image:: https://img.shields.io/readthedocs/drf-yasg.svg
:target: https://drf-yasg.readthedocs.io/
:alt: ReadTheDocs
Expand Down
7 changes: 7 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
Changelog
#########

**********
**1.21.8**
**********

**ADDED:** Python 3.11 and 3.12 support (:pr:`891`)
**FIXED:** Fix pkg_resources version lookups for Python 3.9+ (:pr:`891`)

**********
**1.21.7**
**********
Expand Down
12 changes: 9 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
from docutils import nodes, utils
from docutils.parsers.rst import roles
from docutils.parsers.rst.roles import set_classes
from pkg_resources import get_distribution

try:
from importlib import metadata
except ImportError: # Python < 3.8
from pkg_resources import get_distribution

# -- General configuration ------------------------------------------------

Expand Down Expand Up @@ -47,7 +51,10 @@
# built documents.

# The full version, including alpha/beta/rc tags.
release = get_distribution('drf_yasg').version
try:
release = metadata.version('drf_yasg')
except NameError: # Python < 3.8
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, '
Expand Down Expand Up @@ -82,7 +89,6 @@
# html_theme = 'default'

html_theme = "sphinx_rtd_theme"
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[build-system]
requires = ["setuptools >= 40.6.3", "wheel", "setuptools-scm >= 3.0.3"]
requires = ["setuptools >= 68.0.0", "wheel", "setuptools-scm >= 3.0.3"]
build-backend = "setuptools.build_meta"
2 changes: 1 addition & 1 deletion requirements/publish.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
setuptools-scm==7.0.5
twine==4.0.1
twine>=5.0.0
wheel>=0.37.0
14 changes: 9 additions & 5 deletions src/drf_yasg/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
# coding=utf-8
from pkg_resources import DistributionNotFound, get_distribution

__author__ = """Cristi V."""
__email__ = '[email protected]'

try:
__version__ = get_distribution(__name__).version
except DistributionNotFound: # pragma: no cover
# package is not installed
pass
from importlib.metadata import version
__version__ = version(__name__)
except ImportError: # Python < 3.8
try:
from pkg_resources import DistributionNotFound, get_distribution
__version__ = get_distribution(__name__).version
except DistributionNotFound: # pragma: no cover
# package is not installed
pass
2 changes: 2 additions & 0 deletions src/drf_yasg/app_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
'DEFAULT_API_URL': None,

'USE_SESSION_AUTH': True,
'CSRF_COOKIE_NAME': settings.CSRF_COOKIE_NAME,
'CSRF_HEADER_NAME': settings.CSRF_HEADER_NAME,
'SECURITY_DEFINITIONS': {
'Basic': {
'type': 'basic'
Expand Down
8 changes: 6 additions & 2 deletions src/drf_yasg/inspectors/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from decimal import Decimal
from inspect import signature as inspect_signature

import pkg_resources
import typing
from django.core import validators
from django.db import models
Expand All @@ -23,7 +22,12 @@
decimal_as_float, field_value_to_representation, filter_none, get_serializer_class, get_serializer_ref_name
)

drf_version = pkg_resources.get_distribution("djangorestframework").version
try:
from importlib import metadata
drf_version = metadata.version("djangorestframework")
except ImportError: # Python < 3.8
import pkg_resources
drf_version = pkg_resources.get_distribution("djangorestframework").version

logger = logging.getLogger(__name__)

Expand Down
3 changes: 3 additions & 0 deletions src/drf_yasg/renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ def get_swagger_ui_settings(self):
'refetchWithAuth': swagger_settings.REFETCH_SCHEMA_WITH_AUTH,
'refetchOnLogout': swagger_settings.REFETCH_SCHEMA_ON_LOGOUT,
'fetchSchemaWithQuery': swagger_settings.FETCH_SCHEMA_WITH_QUERY,
'csrfCookie': swagger_settings.CSRF_COOKIE_NAME,
# remove HTTP_ and convert underscores to dashes
'csrfHeader': swagger_settings.CSRF_HEADER_NAME[5:].replace('_', '-'),
}

data = filter_none(data)
Expand Down
17 changes: 16 additions & 1 deletion src/drf_yasg/static/drf-yasg/swagger-ui-init.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,26 @@ var swaggerUiConfig = {
],
layout: "StandaloneLayout",
filter: true,
csrfCookie: 'csrftoken',
csrfHeader: 'X-CSRFToken',
requestInterceptor: function (request) {
var headers = request.headers || {};
var csrftoken = document.querySelector("[name=csrfmiddlewaretoken]");
if (csrftoken) {
headers["X-CSRFToken"] = csrftoken.value;
csrftoken = csrftoken.value;
} else {
var cookies = document.cookie.split(/;\s+/);
var name = swaggerUiConfig.csrfCookie;
for (var i = 0; i < cookies.length; i++) {
if (cookies[i].indexOf(name) === 0) {
csrftoken = cookies[i].slice(cookies[i].indexOf('=') + 1);
break;
}
}
}

if (csrftoken) {
headers[swaggerUiConfig.csrfHeader] = csrftoken;
}

return request;
Expand Down
1 change: 0 additions & 1 deletion testproj/testproj/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True

# Static files (CSS, JavaScript, Images)
Expand Down
9 changes: 8 additions & 1 deletion testproj/testproj/settings/heroku.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@
# Simplified static file serving.
# https://warehouse.python.org/project/whitenoise/

STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
STORAGES = {
"default": {
"BACKEND": "django.core.files.storage.FileSystemStorage",
},
"staticfiles": {
"BACKEND": 'whitenoise.storage.CompressedManifestStaticFilesStorage',
},
}
MIDDLEWARE.insert(0, 'whitenoise.middleware.WhiteNoiseMiddleware')

# Database
Expand Down
2 changes: 1 addition & 1 deletion testproj/testproj/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def plain_view(request):


def root_redirect(request):
user_agent_string = request.META.get('HTTP_USER_AGENT', '')
user_agent_string = request.headers.get('user-agent', '')
user_agent = user_agents.parse(user_agent_string)

if user_agent.is_mobile:
Expand Down
Loading

0 comments on commit 49d41b0

Please sign in to comment.