Prepare release 1.0.4

openapi3 1.0.4
Cristi Vîjdea 2017-12-16 18:18:21 +01:00 committed by GitHub
parent 73bd7a136d
commit a2c21539f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 71 additions and 24 deletions

View File

@ -5,7 +5,7 @@
drf-yasg - Yet another Swagger generator
########################################
|travis| |nbsp| |codecov|
|travis| |nbsp| |codecov| |nbsp| |rtd-badge| |nbsp| |pypi-version|
Generate **real** Swagger/OpenAPI 2.0 specifications from a Django Rest Framework API.
@ -358,5 +358,13 @@ https://drf-yasg.readthedocs.io/en/latest/
:target: https://codecov.io/gh/axnsan12/drf-yasg
:alt: Codecov
.. |pypi-version| image:: https://img.shields.io/pypi/v/drf-yasg.svg
:target: https://pypi.org/project/drf-yasg/
:alt: PyPI
.. |rtd-badge| image:: https://img.shields.io/readthedocs/drf-yasg.svg
:target: https://drf-yasg.readthedocs.io/
:alt: ReadTheDocs
.. |nbsp| unicode:: 0xA0
:trim:

View File

@ -3,6 +3,14 @@ Changelog
#########
*********
**1.0.4**
*********
- **FIX:** fixed improper generation of YAML references
- **FEATURE:** added ``query_serializer`` parameter to
:func:`@swagger_auto_schema <.swagger_auto_schema>` (:issue:`16`, :pr:`17`)
*********
**1.0.3**
*********

View File

@ -196,7 +196,11 @@ nitpick_ignore = [
('py:obj', 'APIView'),
]
# even though the package should be already installed, the sphinx build on RTD
# for some reason needs the sources dir to be in the path in order for viewcode to work
sys.path.insert(0, os.path.abspath('../src'))
# activate the Django testproj to be able to succesfully import drf_yasg
sys.path.insert(0, os.path.abspath('../testproj'))
os.putenv('DJANGO_SETTINGS_MODULE', 'testproj.settings')
@ -204,11 +208,13 @@ from django.conf import settings # noqa: E402
settings.configure()
# instantiate a SchemaView in the views module to make it available to autodoc
import drf_yasg.views # noqa: E402
# instantiate a SchemaView in the views module to make it available to autodoc
drf_yasg.views.SchemaView = drf_yasg.views.get_schema_view(None)
# custom interpreted role for linking to GitHub issues and pull requests
# use as :issue:`14` or :pr:`17`
gh_issue_uri = "https://github.com/axnsan12/drf-yasg/issues/%d"
gh_pr_uri = "https://github.com/axnsan12/drf-yasg/pull/%d"

View File

@ -3,6 +3,7 @@
import io
import os
import sys
from setuptools import setup, find_packages
import distutils.core
@ -21,23 +22,24 @@ def _install_setup_requires(attrs):
dist.fetch_build_eggs(dist.setup_requires)
try:
# try to install setuptools_scm before setuptools does it, otherwise our monkey patch below will come too early
# (setuptools_scm adds find_files hooks into setuptools on install)
_install_setup_requires({'setup_requires': requirements_setup})
except Exception:
pass
if 'sdist' in sys.argv:
try:
# try to install setuptools_scm before setuptools does it, otherwise our monkey patch below will come too early
# (setuptools_scm adds find_files hooks into setuptools on install)
_install_setup_requires({'setup_requires': requirements_setup})
except Exception:
pass
try:
# see https://github.com/pypa/setuptools_scm/issues/190, setuptools_scm includes ALL versioned files from the git
# repo into the sdist by default, and there is no easy way to provide an opt-out;
# this hack is ugly but does the job; because this is not really a documented interface of the module,
# the setuptools_scm version should remain pinned to ensure it keeps working
import setuptools_scm.integration
try:
# see https://github.com/pypa/setuptools_scm/issues/190, setuptools_scm includes ALL versioned files from
# the git repo into the sdist by default, and there is no easy way to provide an opt-out;
# this hack is ugly but does the job; because this is not really a documented interface of the module,
# the setuptools_scm version should remain pinned to ensure it keeps working
import setuptools_scm.integration
setuptools_scm.integration.find_files = lambda _: []
except ImportError:
pass
setuptools_scm.integration.find_files = lambda _: []
except ImportError:
pass
def read_req(req_file):

View File

@ -101,6 +101,10 @@ class OpenAPICodecJson(_OpenAPICodec):
class SaneYamlDumper(yaml.SafeDumper):
"""YamlDumper class usable for dumping ``OrderedDict`` and list instances in a standard way."""
def ignore_aliases(self, data):
"""Disable YAML references."""
return True
def increase_indent(self, flow=False, indentless=False, **kwargs):
"""https://stackoverflow.com/a/39681672
@ -152,6 +156,7 @@ def yaml_sane_dump(data, binary):
* OrderedDicts are dumped as regular mappings instead of non-standard !!odict
* multi-line mapping style instead of json-like inline style
* list elements are indented into their parents
* YAML references/aliases are disabled
:param dict data: the data to be serializers
:param bool binary: True to return a utf-8 encoded binary object, False to return a string

View File

@ -115,15 +115,19 @@ class SwaggerDict(OrderedDict):
setattr(self, attr, val)
@staticmethod
def _as_odict(obj):
def _as_odict(obj, memo):
"""Implementation detail of :meth:`.as_odict`"""
if id(obj) in memo:
return memo[id(obj)]
if isinstance(obj, dict):
result = OrderedDict()
memo[id(obj)] = result
for attr, val in obj.items():
result[attr] = SwaggerDict._as_odict(val)
result[attr] = SwaggerDict._as_odict(val, memo)
return result
elif isinstance(obj, (list, tuple)):
return type(obj)(SwaggerDict._as_odict(elem) for elem in obj)
return type(obj)(SwaggerDict._as_odict(elem, memo) for elem in obj)
return obj
@ -132,7 +136,7 @@ class SwaggerDict(OrderedDict):
:rtype: OrderedDict
"""
return SwaggerDict._as_odict(self)
return SwaggerDict._as_odict(self, {})
def __reduce__(self):
# for pickle supprt; this skips calls to all SwaggerDict __init__ methods and relies

View File

@ -380,7 +380,7 @@ paths:
- name: data
in: body
required: true
schema: &id001
schema:
required:
- username
type: object
@ -390,7 +390,13 @@ paths:
responses:
'201':
description: ''
schema: *id001
schema:
required:
- username
type: object
properties:
username:
type: string
consumes:
- application/json
tags:

View File

@ -40,10 +40,18 @@ def test_json_codec_roundtrip(codec_json, generator, validate_schema):
def test_yaml_codec_roundtrip(codec_yaml, generator, validate_schema):
swagger = generator.get_schema(None, True)
yaml_bytes = codec_yaml.encode(swagger)
assert b'omap' not in yaml_bytes
assert b'omap' not in yaml_bytes # ensure no ugly !!omap is outputted
assert b'&id' not in yaml_bytes and b'*id' not in yaml_bytes # ensure no YAML references are generated
validate_schema(yaml.safe_load(yaml_bytes.decode('utf-8')))
def test_yaml_and_json_match(codec_yaml, codec_json, generator):
swagger = generator.get_schema(None, True)
yaml_schema = yaml.safe_load(codec_yaml.encode(swagger).decode('utf-8'))
json_schema = json.loads(codec_json.encode(swagger).decode('utf-8'))
assert yaml_schema == json_schema
def test_basepath_only():
generator = OpenAPISchemaGenerator(
info=openapi.Info(title="Test generator", default_version="v1"),