Skip to content

Commit

Permalink
Advance master to release 1.21.7 (#815)
Browse files Browse the repository at this point in the history
* Add sample code to handle Base64 fields in drf-extra-fields project

* Fix format for .rst

* Update answer to the easier version as suggested in Hipo/drf-extra-fields#66 (comment)

* update readme.rst

`permission_classes` expects tuple but list was provided

* url from DEFAULT_API_URL now works

fix a bug: url from swagger_settings.DEFAULT_API_URL is not working

* Check for allow_null attribute

* Add utf-8 support for generated formats

* Added `many` support to example code.

* serialize pytz object as a string

* simplify if condition

* handle errors rendering with TemplateHTMLRenderer

This change fixes an `OPTIONS` request to the API page which will return
a successful response, but the `TemplateHTMLRender` will not be prepared
to render it since there is no template name provided in either the view
or response [1].

[1]: https://github.com/encode/django-rest-framework/blob/f0a5b958a134e8cd94e3ef3263e8fa623ac9b82f/rest_framework/renderers.py#L178-L189

* Allow specifying response as a reference

* [readme] Fix missing re_path import

* fix map source mapping

* Remove universal wheel, python 2 is unsupported

* Inline allow_unicode parameter

* Update changelog

* Update changelog typos

* Add cspell

* Fix old spelling errors

* Add ref_name to UserSerializer after removing suffix typo

* Set permission classes to a tuple

* Update chagnelog

* Add prepublish twine check

* Fix action version syntax

* Fix indentation in README.rst code blocks

* Add twine to publish dependencies

* Specify toxenv explicitly

* Specify all tox targets

* Add py prefix to toxenvs

* Update changelog

* Update changelog

* Declare Django 3.2 support in README, classifiers

This commit will make sure that `Django :: 3.2` will show up in the
classifiers list on PyPI: https://pypi.org/project/drf-yasg/

(The magic happens because we parse the README to get supported Django):
https://github.com/DavidCain/drf-yasg/blob/ee29412d3cdb311/setup.py#L36

3.2 support should already exist
================================
A closed pull request, #735,
noted support for Django 3.2 in both `tox.ini`, and the README.

That PR was closed in favor of
#741, which edited `tox.ini`
and switched to GitHub Actions.

#735 (comment)

This project has been testing on Django 3.2 for a long time (about a
year). I think we can declare it supported it the README!

* Fix `pip install` command for contributors on zsh

On `zsh` (a popular shell, and the default for macOS), install fails:

    $ pip install -U -e .[validation]
    zsh: no matches found: .[validation]

Quote the arguments so that `bash` or `zsh` will succeed.

* Dont use NullBooleanField if drf version >= 3.14.0

* Swap back BooleanField and NullBooleanField

* Update changelog

* Update README to use path instead of re_path in example

* Run tests with latest dependencies

- Django 4.0 & 4.1
- DRF 3.13 & 3.14
- Python 3.10

* Add python 3.10 in GH actions matrix

* Fix RecursiveField

* Change github actions runner from ubuntu-latest to ubuntu-20.04

* Change github actions runner from ubuntu-latest to ubuntu-20.04

* Remove python 3.6 tests since swagger-spec-validator no longer supports it

* Use a string literal for python versions such as "3.10"

* Add python 3.10 compatibility to README.md

* Update changelog

* Fix: Provide enums support for schema.

* Fix: Tests for Python 3.11.

* Refactoring: Removed old version code.

* Fix: Linting is now working.

* Fix: Provide usage of Enums as dict keys.

* Fix: Docs build with latest sphinx versions.

* keep path parameters in their given order

* Fix: Action build docs with latest tox version.

* Fix: Update python version for dj-master branch.

Django master branch bumped minimal python version
to Python 3.10. In latest version was added check for uniq basename.

* Feature: Migrate to PyYAML for yaml generator. (#845)

* Feature: Migrate to PyYAML for yaml generator.

Closes #833

* Chore: Update swagger ui and redoc dependencies.

* Fix: Remove required coreapi dependency. (#854)

* Feature: Migrate to PyYAML for yaml generator.

Closes #833

* Chore: Update swagger ui and redoc dependencies.

* Fix: Remove required coreapi dependency.

* Update Changelog

* Feature: Add ``drf_yasg.inspectors.query.DrfAPICompatInspector``. (#857)

* Feature: Provide to override default renderers via settings.

* Feature: Enable tests for django 4.2.

* Docs: Add information how to override ``DEFAULT_SPEC_RENDERERS``.

* Feature: Add ``drf_yasg.inspectors.query.DrfAPICompatInspector``.

This inspector should be main and replace ``CoreAPICompatInspector`` in the future.

* [fix] Fixed map source mapping (#859)

* Tests: Improve test coverage 95.91% -> 98.30%. (#862)

* Update Changelog

* Add python3.6 to the actions matrix but exclude it from tests

---------

Co-authored-by: Terry <wasin.th@gmail.com>
Co-authored-by: Sumit Singh <sumit.singh4613@gmail.com>
Co-authored-by: Core-Chan <i@coreja.com>
Co-authored-by: Krista Mae Rectra <krista.rectra@gmail.com>
Co-authored-by: mmurashov <m.murashov@ritm.media>
Co-authored-by: Christoph Beckmann <cbe@colibri-media.de>
Co-authored-by: MilanPecov <mpecov@yahoo.ca>
Co-authored-by: Terence D. Honles <terence@honles.com>
Co-authored-by: Cristi Vîjdea <cristi@cvjd.me>
Co-authored-by: Max Vorobev <vmax0770@gmail.com>
Co-authored-by: Damien Ramelet <damien.ramelet@protonmail.com>
Co-authored-by: Petr Dlouhý <petr.dlouhy@email.cz>
Co-authored-by: gopackgo90 <cbodendein@live.com>
Co-authored-by: David Cain <davidjosephcain@gmail.com>
Co-authored-by: Amir Andohkosh <4315615+amir-bio@users.noreply.github.com>
Co-authored-by: Nikolaos Michas <nikos.mixas@outlook.com>
Co-authored-by: Ignacio Orlandini <ignacioorlandini@gmail.com>
Co-authored-by: Sergey Klyuykov <onegreyonewhite@mail.ru>
Co-authored-by: Gagan Deep <the.one.above.all.titan@gmail.com>
  • Loading branch information
20 people authored Jul 20, 2023
1 parent 6557517 commit 78031f0
Show file tree
Hide file tree
Showing 77 changed files with 4,394 additions and 417 deletions.
176 changes: 176 additions & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
{
"language": "en",
"ignorePaths": [
"./app.json",
".gitignore",
"*.coverage",
"*.min.js",
"**/__pycache__/**",
"**/*.egg-info/**",
"**/*.git/**",
"**/build/**",
"**/coverage/**",
"**/dist/**",
"**/migrations/**",
"**/swagger-ui-dist/**",
"**/venv/**"
],
"dictionaries": [
"css",
"django",
"fonts",
"local",
"misc",
"python",
"softwareTerms"
],
"words": [
"addopts",
"apiview",
"askar",
"auths",
"authtoken",
"autoclass",
"autodata",
"automodule",
"avenir",
"barebones",
"basepath",
"beaugunderson",
"blueyed",
"builddir",
"bysource",
"cacheable",
"callabale",
"camelize",
"camelized",
"classdoc",
"codecov",
"codegen",
"coreapi",
"coreschema",
"corsheaders",
"coveragerc",
"cristi",
"cristian",
"cschema",
"csrfmiddlewaretoken",
"csrftoken",
"dascalescu",
"datadiff",
"deauth",
"deauthorize",
"deprecated",
"djangorestframework",
"djmaster",
"docstrings",
"documentclass",
"elnappo",
"envlist",
"eryk",
"exitfirst",
"extrahead",
"figwidth",
"filterset",
"formop",
"genindex",
"getdefault",
"ghuser",
"gunicorn",
"herokuapp",
"hirokawa",
"howto",
"htbp",
"htmlhelp",
"immutablehash",
"indentless",
"initkwargs",
"joellefkowitz",
"jsons",
"keepdb",
"keyframeprefix",
"letterpaper",
"levelname",
"linenos",
"maxdepth",
"minversion",
"modindex",
"monokai",
"myparent",
"napierała",
"nbsp",
"noscm",
"npmignore",
"odict",
"omap",
"paginators",
"papersize",
"passwordadmin",
"plugable",
"pointsize",
"popd",
"posargs",
"preauth",
"preauthorize",
"prepended",
"proxied",
"psycopg",
"pushd",
"putenv",
"pythonpath",
"pytz",
"qinsq",
"quickstart",
"rebilly",
"redoc",
"referenceable",
"reftest",
"refuri",
"regexes",
"representer",
"rsichny",
"rtype",
"ruamel",
"scrollbars",
"searchbox",
"serializers",
"setuptools",
"sidemenu",
"sourcedir",
"sphinxbuild",
"sphinxopts",
"sphinxproj",
"staticfiles",
"subclassing",
"swaggerapi",
"tenerowicz",
"testenv",
"testproj",
"therefromhere",
"toctree",
"undoc",
"unencrypted",
"uritemplate",
"urlconf",
"urlconfs",
"urlpatterns",
"versionadded",
"versionchanged",
"versionmodified",
"viewcode",
"viewset",
"viewsets",
"vigrond",
"vschema",
"whitenoise",
"wsgi",
"xdist",
"yasg",
"yasgdoc",
"yetanother",
"yetanothers",
"yourapp",
"yusupov",
"zbyszek"
]
}
29 changes: 29 additions & 0 deletions .github/actions/install/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Install
description: Install dependencies

inputs:
python-version:
description: Python version for installing dependencies
required: true

runs:
using: composite
steps:
- name: Checkout the source code
uses: actions/checkout@v2

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

- name: Set up pip package caching
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: ${{ runner.os }}-pip-

- name: Install dependencies
shell: bash
run: pip install -r requirements/ci.txt
16 changes: 10 additions & 6 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Publish

on:
push:
tags:
tags:
- "*.*.*"

jobs:
Expand All @@ -13,17 +13,21 @@ jobs:
- name: Checkout the source code
uses: actions/checkout@v2

- name: Set the python version
uses: actions/setup-python@v2

# 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
# 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
with:
python-version: 3.8

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

- name: Install pip dependencies
- name: Install builders for publishing
run: pip install -r requirements/publish.txt

- name: Build the distributions
Expand Down
43 changes: 29 additions & 14 deletions .github/workflows/review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,44 @@ on: [push, pull_request]
jobs:
review:
name: Run linters and tests
runs-on: ubuntu-latest
runs-on: "ubuntu-20.04"
strategy:
matrix:
python: [3.6, 3.7, 3.8, 3.9]
python: ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11"]

steps:
- name: Set up pip package caching
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: ${{ runner.os }}-pip-

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

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

- name: Install dependencies
uses: ./.github/actions/install
with:
python-version: ${{ matrix.python }}

- name: Install pip dependencies
run: pip install -r requirements/ci.txt
- 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 }}
run: |
pip install coverage
coverage report
- name: Run unit tests
run: tox
- name: Check for incompatibilities with publishing to PyPi
if: ${{ matrix.python == 3.8 }}
run: |
pip install -r requirements/publish.txt
python setup.py sdist
twine check dist/*
6 changes: 3 additions & 3 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ You want to contribute some code? Great! Here are a few steps to get you started
$ python -m venv venv
$ source venv/bin/activate
(venv) $ python -m pip install -U pip setuptools
(venv) $ pip install -U -e .[validation]
(venv) $ pip install -U -e '.[validation]'
(venv) $ pip install -U -r requirements/dev.txt
#. **Make your changes and check them against the test project**
Expand Down Expand Up @@ -78,7 +78,7 @@ You want to contribute some code? Great! Here are a few steps to get you started
#. **Update documentation**

If the change modifies behaviour or adds new features, you should update the documentation and ``README.rst``
If the change modifies behavior or adds new features, you should update the documentation and ``README.rst``
accordingly. Documentation is written in reStructuredText and built using Sphinx. You can find the sources in the
``docs`` directory.

Expand All @@ -96,7 +96,7 @@ You want to contribute some code? Great! Here are a few steps to get you started
#. **Your code must pass all the required CI jobs before it is merged**

As of now, this consists of running on the supported Python, Django, DRF version matrix (see README),
and building the docs succesfully.
and building the docs successfully.

******************
Maintainer's notes
Expand Down
43 changes: 36 additions & 7 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ Generate **real** Swagger/OpenAPI 2.0 specifications from a Django Rest Framewor

Compatible with

- **Django Rest Framework**: 3.10, 3.11, 3.12
- **Django**: 2.2, 3.0, 3.1
- **Python**: 3.6, 3.7, 3.8, 3.9
- **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

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

Expand Down Expand Up @@ -132,6 +132,7 @@ In ``urls.py``:
.. code:: python
...
from django.urls import re_path
from rest_framework import permissions
from drf_yasg.views import get_schema_view
from drf_yasg import openapi
Expand All @@ -148,13 +149,13 @@ In ``urls.py``:
license=openapi.License(name="BSD License"),
),
public=True,
permission_classes=[permissions.AllowAny],
permission_classes=(permissions.AllowAny,),
)
urlpatterns = [
re_path(r'^swagger(?P<format>\.json|\.yaml)$', schema_view.without_ui(cache_timeout=0), name='schema-json'),
re_path(r'^swagger/$', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
re_path(r'^redoc/$', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'),
path('swagger<format>/', schema_view.without_ui(cache_timeout=0), name='schema-json'),
path('swagger/', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
path('redoc/', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'),
...
]
Expand Down Expand Up @@ -357,3 +358,31 @@ provided out of the box - if you have ``djangorestframework-recursive`` installe

.. |nbsp| unicode:: 0xA0
:trim:

drf-extra-fields
=================

Integration with `drf-extra-fields <https://github.com/Hipo/drf-extra-fields>`_ has a problem with Base64 fields.
The drf-yasg will generate Base64 file or image fields as Readonly and not required. Here is a workaround code
for display the Base64 fields correctly.

.. code:: python
class PDFBase64FileField(Base64FileField):
ALLOWED_TYPES = ['pdf']
class Meta:
swagger_schema_fields = {
'type': 'string',
'title': 'File Content',
'description': 'Content of the file base64 encoded',
'read_only': False # <-- FIX
}
def get_file_extension(self, filename, decoded_file):
try:
PyPDF2.PdfFileReader(io.BytesIO(decoded_file))
except PyPDF2.utils.PdfReadError as e:
logger.warning(e)
else:
return 'pdf'
Loading

0 comments on commit 78031f0

Please sign in to comment.