Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide read_only=True nested serializers from data #824

Open
wants to merge 68 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
02cc192
Add sample code to handle Base64 fields in drf-extra-fields project
WasinTh Aug 25, 2019
b0f1906
Fix format for .rst
WasinTh Aug 25, 2019
67f5489
Update answer to the easier version as suggested in https://github.co…
WasinTh Aug 14, 2020
5b88e65
update readme.rst
sumit4613 Dec 12, 2020
426fb5d
url from DEFAULT_API_URL now works
CoreJa Dec 25, 2020
d2a2783
Check for allow_null attribute
krectra Jan 6, 2021
ecf1699
Merge pull request #1 from capslent/serpy_allow_null
krectra Jan 6, 2021
00f8838
Add utf-8 support for generated formats
Jan 14, 2021
364732a
Added `many` support to example code.
cbek Jan 22, 2021
cbdb713
serialize pytz object as a string
MilanPecov May 11, 2021
11fdb02
simplify if condition
krectra May 24, 2021
571cd00
Merge branch 'master' into add-support-for-timezone-field
JoelLefkowitz Sep 22, 2021
468d0b9
Merge branch 'master' into patch-1
JoelLefkowitz Sep 22, 2021
e6d0528
Merge branch 'master' into utf8-support
JoelLefkowitz Sep 22, 2021
be1f084
handle errors rendering with TemplateHTMLRenderer
terencehonles Sep 23, 2021
049c2ed
Merge branch 'master' into master
axnsan12 Dec 12, 2021
6670052
Allow specifying response as a reference
vmax Nov 28, 2021
e6c1aad
[readme] Fix missing re_path import
damien-ramelet Feb 15, 2022
0c14a4f
fix map source mapping
PetrDlouhy Feb 22, 2022
7230713
Merge branch 'master' into master
krectra Mar 6, 2022
ab7f37f
Remove universal wheel, python 2 is unsupported
gopackgo90 Mar 11, 2022
fc4d6a1
Merge pull request #778 from PetrDlouhy/master
JoelLefkowitz Jul 14, 2022
3f01252
Merge pull request #773 from damien-devpy/missing_import_readme
JoelLefkowitz Jul 14, 2022
55d2805
Inline allow_unicode parameter
JoelLefkowitz Jul 14, 2022
113be08
Merge pull request #692 from ProstoMaxim/utf8-support
JoelLefkowitz Jul 14, 2022
850ccf5
Update changelog
JoelLefkowitz Jul 14, 2022
8bc55e8
Update changelog typos
JoelLefkowitz Jul 14, 2022
78720c7
Merge pull request #782 from gopackgo90/patch-1
JoelLefkowitz Jul 15, 2022
f5f9b2a
Add cspell
JoelLefkowitz Jul 15, 2022
58d0cdf
Fix old spelling errors
JoelLefkowitz Jul 15, 2022
a577536
Add ref_name to UserSerializer after removing suffix typo
JoelLefkowitz Jul 15, 2022
1b03e72
Merge pull request #796 from axnsan12/cspell
JoelLefkowitz Jul 15, 2022
6745ddb
Merge pull request #757 from oppgjorskontoret/allow-inserting-arbitra…
JoelLefkowitz Jul 17, 2022
60ae05c
Merge branch '1.21.x' into pr/742
JoelLefkowitz Jul 17, 2022
4289361
Merge branch '1.21.x' into pr/717
JoelLefkowitz Jul 17, 2022
eebb245
Merge branch '1.21.x' into pr/695
JoelLefkowitz Jul 17, 2022
fe08c76
Merge branch '1.21.x' into pr/688
JoelLefkowitz Jul 17, 2022
4e6564a
Merge branch '1.21.x' into pr/682
JoelLefkowitz Jul 17, 2022
a088d32
Merge branch '1.21.x' into pr/678
JoelLefkowitz Jul 17, 2022
ba54faa
Merge branch '1.21.x' into pr/445
JoelLefkowitz Jul 17, 2022
1662fc8
Set permission classes to a tuple
JoelLefkowitz Jul 17, 2022
ea5c3b6
Merge pull request #695 from cbek/patch-1
JoelLefkowitz Jul 17, 2022
5774190
Merge pull request #445 from WasinTh/drf-extra-fields-base64-integration
JoelLefkowitz Jul 17, 2022
d3b14ab
Merge pull request #678 from sumit4613/patch-1
JoelLefkowitz Jul 17, 2022
124f2cd
Update chagnelog
JoelLefkowitz Jul 17, 2022
0ec7f89
Add prepublish twine check
JoelLefkowitz Jul 18, 2022
deb3994
Fix action version syntax
JoelLefkowitz Jul 18, 2022
8b76535
Fix indentation in README.rst code blocks
JoelLefkowitz Jul 18, 2022
3972472
Add twine to publish dependencies
JoelLefkowitz Jul 18, 2022
fe53426
Specify toxenv explicitly
JoelLefkowitz Jul 18, 2022
822f66d
Specify all tox targets
JoelLefkowitz Jul 18, 2022
d7314b6
Add py prefix to toxenvs
JoelLefkowitz Jul 18, 2022
a000102
Update changelog
JoelLefkowitz Jul 18, 2022
f4bf7ba
Merge pull request #797 from axnsan12/prepublish
JoelLefkowitz Jul 18, 2022
f87dbd5
Merge pull request #742 from terencehonles/handle-errors-rendering-wi…
JoelLefkowitz Jul 18, 2022
13f0af2
Merge pull request #717 from MilanPecov/add-support-for-timezone-field
JoelLefkowitz Jul 18, 2022
cb03608
Merge pull request #688 from krectra/master
JoelLefkowitz Jul 18, 2022
0e09cbe
Merge pull request #682 from CoreJa/master
JoelLefkowitz Jul 18, 2022
00b042b
Update changelog
JoelLefkowitz Jul 18, 2022
7adddf7
Declare Django 3.2 support in README, classifiers
DavidCain Aug 3, 2022
611594d
Fix `pip install` command for contributors on zsh
DavidCain Aug 3, 2022
44fed4b
Merge pull request #803 from DavidCain/dcain-django32
JoelLefkowitz Aug 9, 2022
d73cffc
Merge pull request #802 from DavidCain/dcain-contributing
JoelLefkowitz Aug 20, 2022
5420475
Dont use NullBooleanField if drf version >= 3.14.0
JoelLefkowitz Sep 24, 2022
2646dfa
Swap back BooleanField and NullBooleanField
JoelLefkowitz Sep 24, 2022
a58f098
Merge pull request #814 from axnsan12/fix/drf-3.14.0
JoelLefkowitz Sep 26, 2022
0cdc4bd
Update changelog
JoelLefkowitz Sep 26, 2022
44c8ba0
Use allOf property to combine $ref with local parameters such as read…
curiousKonstantin Nov 29, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
28 changes: 16 additions & 12 deletions .github/workflows/review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,27 @@ jobs:
python: [3.6, 3.7, 3.8, 3.9]

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

- 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
33 changes: 31 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ 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
- **Django**: 2.2, 3.0, 3.1, 3.2
- **Python**: 3.6, 3.7, 3.8, 3.9

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,7 +149,7 @@ In ``urls.py``:
license=openapi.License(name="BSD License"),
),
public=True,
permission_classes=[permissions.AllowAny],
permission_classes=(permissions.AllowAny,),
)

urlpatterns = [
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'
1 change: 1 addition & 0 deletions docs/_templates/layout.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% extends "!layout.html" %}
{% block extrahead %}
<!-- cspell:disable-next-line -->
<meta name="google-site-verification" content="saewLzcrUS1lAAgNVIikKWc3DUbFcE-TWtpyw3AW8CA" />
{% endblock %}
Loading