Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9ad55bac99 | |||
| 3d3b7899e5 | |||
| 6ea8711a1f |
@@ -3,6 +3,33 @@ Changelog
|
||||
#########
|
||||
|
||||
|
||||
*********
|
||||
**1.4.7**
|
||||
*********
|
||||
|
||||
*Release date: Mar 05, 2018*
|
||||
|
||||
- **FIXED:** prevent crashes caused by attempting to delete object attributes which do not exist in the first place
|
||||
(:issue:`76`)
|
||||
|
||||
*********
|
||||
**1.4.6**
|
||||
*********
|
||||
|
||||
*Release date: Mar 05, 2018*
|
||||
|
||||
- **IMPROVED:** updated ``swagger-ui`` to version 3.12.0
|
||||
- **IMPROVED:** updated ``ReDoc`` to version 1.21.2
|
||||
|
||||
*********
|
||||
**1.4.5**
|
||||
*********
|
||||
|
||||
*Release date: Mar 05, 2018*
|
||||
|
||||
- **FIXED:** fixed an issue with modification of ``swagger_auto_schema`` arguments in-place during introspection, which
|
||||
would sometimes cause an incomplete Swagger document to be generated after the first pass (:issue:`74`, :pr:`75`)
|
||||
|
||||
*********
|
||||
**1.4.4**
|
||||
*********
|
||||
|
||||
Generated
+10
-10
@@ -211,9 +211,9 @@
|
||||
"integrity": "sha512-MtEC1TqN0EU5nephaJ4rAtThHtC86dNN9qCuEhtshvpVBkAW5ZO7BASN9REnF9eoXGcRub+pFuKEpOHE+HbEMw=="
|
||||
},
|
||||
"readable-stream": {
|
||||
"version": "2.3.4",
|
||||
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.4.tgz",
|
||||
"integrity": "sha512-vuYxeWYM+fde14+rajzqgeohAI7YoJcHE7kXDAc4Nk0EbuKnJfqtY9YtRkLo/tqkuF7MsBQRhPnPeyjYITp3ZQ==",
|
||||
"version": "2.3.5",
|
||||
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.5.tgz",
|
||||
"integrity": "sha512-tK0yDhrkygt/knjowCUiWP9YdV7c5R+8cR0r/kt9ZhBU906Fs6RpQJCEilamRJj1Nx2rWI6LkW9gKqjTkshhEw==",
|
||||
"requires": {
|
||||
"core-util-is": "1.0.2",
|
||||
"inherits": "2.0.3",
|
||||
@@ -225,9 +225,9 @@
|
||||
}
|
||||
},
|
||||
"redoc": {
|
||||
"version": "1.21.0",
|
||||
"resolved": "https://registry.npmjs.org/redoc/-/redoc-1.21.0.tgz",
|
||||
"integrity": "sha1-RY8E7b7MqyVbQORhZA0eRG949N0=",
|
||||
"version": "1.21.2",
|
||||
"resolved": "https://registry.npmjs.org/redoc/-/redoc-1.21.2.tgz",
|
||||
"integrity": "sha1-uMeLfDxtwFjmeZniwvYbqFjewaY=",
|
||||
"requires": {
|
||||
"core-js": "2.5.3",
|
||||
"dropkickjs": "2.1.10",
|
||||
@@ -301,7 +301,7 @@
|
||||
"requires": {
|
||||
"builtin-status-codes": "3.0.0",
|
||||
"inherits": "2.0.3",
|
||||
"readable-stream": "2.3.4",
|
||||
"readable-stream": "2.3.5",
|
||||
"to-arraybuffer": "1.0.1",
|
||||
"xtend": "4.0.1"
|
||||
}
|
||||
@@ -315,9 +315,9 @@
|
||||
}
|
||||
},
|
||||
"swagger-ui-dist": {
|
||||
"version": "3.10.0",
|
||||
"resolved": "https://registry.npmjs.org/swagger-ui-dist/-/swagger-ui-dist-3.10.0.tgz",
|
||||
"integrity": "sha1-ilrzP/ImPHFaFD9z8qjUfVOZQ+8="
|
||||
"version": "3.12.0",
|
||||
"resolved": "https://registry.npmjs.org/swagger-ui-dist/-/swagger-ui-dist-3.12.0.tgz",
|
||||
"integrity": "sha1-Co80SXvGenZ3sTROzRDmGz8KLXA="
|
||||
},
|
||||
"tiny-emitter": {
|
||||
"version": "2.0.2",
|
||||
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
{
|
||||
"name": "drf-yasg",
|
||||
"dependencies": {
|
||||
"redoc": "^1.21.0",
|
||||
"swagger-ui-dist": "^3.10.0"
|
||||
"redoc": "^1.21.2",
|
||||
"swagger-ui-dist": "^3.12.0"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import copy
|
||||
import logging
|
||||
import re
|
||||
from collections import OrderedDict, defaultdict
|
||||
@@ -355,9 +356,9 @@ class OpenAPISchemaGenerator(object):
|
||||
|
||||
view_inspector = view_inspector_cls(view, path, method, components, request, overrides)
|
||||
operation = view_inspector.get_operation(operation_keys)
|
||||
if set(operation.consumes) == set(self.consumes):
|
||||
if 'consumes' in operation and set(operation.consumes) == set(self.consumes):
|
||||
del operation.consumes
|
||||
if set(operation.produces) == set(self.produces):
|
||||
if 'produces' in operation and set(operation.produces) == set(self.produces):
|
||||
del operation.produces
|
||||
return operation
|
||||
|
||||
@@ -388,7 +389,7 @@ class OpenAPISchemaGenerator(object):
|
||||
if method in overrides:
|
||||
overrides = overrides[method]
|
||||
|
||||
return overrides
|
||||
return copy.deepcopy(overrides)
|
||||
|
||||
def get_path_parameters(self, path, view_cls):
|
||||
"""Return a list of Parameter instances corresponding to any templated path variables.
|
||||
|
||||
@@ -89,9 +89,9 @@ class InlineSerializerInspector(SerializerInspector):
|
||||
properties=properties,
|
||||
required=required or None,
|
||||
)
|
||||
if not ref_name:
|
||||
if not ref_name and 'title' in result:
|
||||
# on an inline model, the title is derived from the field name
|
||||
# but is visually displayed like the model named, which is confusing
|
||||
# but is visually displayed like the model name, which is confusing
|
||||
# it is better to just remove title from inline models
|
||||
del result.title
|
||||
return result
|
||||
|
||||
+2
-2
File diff suppressed because one or more lines are too long
@@ -45,11 +45,18 @@
|
||||
oauth2.auth.code = qp.code;
|
||||
oauth2.callback({auth: oauth2.auth, redirectUrl: redirectUrl});
|
||||
} else {
|
||||
let oauthErrorMsg
|
||||
if (qp.error) {
|
||||
oauthErrorMsg = "["+qp.error+"]: " +
|
||||
(qp.error_description ? qp.error_description+ ". " : "no accessCode received from the server. ") +
|
||||
(qp.error_uri ? "More info: "+qp.error_uri : "");
|
||||
}
|
||||
|
||||
oauth2.errCb({
|
||||
authId: oauth2.auth.name,
|
||||
source: "auth",
|
||||
level: "error",
|
||||
message: "Authorization failed: no accessCode received from the server"
|
||||
message: oauthErrorMsg || "[Authorization failed]: no accessCode received from the server"
|
||||
});
|
||||
}
|
||||
} else {
|
||||
|
||||
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
@@ -11,10 +11,15 @@ from rest_framework.views import APIView
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
#: used to forcibly remove the body of a request via :func:`.swagger_auto_schema`
|
||||
no_body = object()
|
||||
|
||||
unset = object()
|
||||
class no_body(object):
|
||||
"""Used as a sentinel value to forcibly remove the body of a request via :func:`.swagger_auto_schema`."""
|
||||
pass
|
||||
|
||||
|
||||
class unset(object):
|
||||
"""Used as a sentinel value for function parameters not set by the caller where ``None`` would be a valid value."""
|
||||
pass
|
||||
|
||||
|
||||
def swagger_auto_schema(method=None, methods=None, auto_schema=unset, request_body=None, query_serializer=None,
|
||||
@@ -33,7 +38,7 @@ def swagger_auto_schema(method=None, methods=None, auto_schema=unset, request_bo
|
||||
:param .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 :data:`.no_body`. The value given here
|
||||
: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'``.
|
||||
|
||||
A Schema or SchemaRef is not valid if this request consumes form-data, because ``form`` and ``body`` parameters
|
||||
|
||||
@@ -2,11 +2,14 @@ import json
|
||||
from collections import OrderedDict
|
||||
|
||||
import pytest
|
||||
from rest_framework import routers, serializers, viewsets
|
||||
from rest_framework.response import Response
|
||||
|
||||
from drf_yasg import codecs, openapi
|
||||
from drf_yasg.codecs import yaml_sane_load
|
||||
from drf_yasg.errors import SwaggerGenerationError
|
||||
from drf_yasg.generators import OpenAPISchemaGenerator
|
||||
from drf_yasg.utils import swagger_auto_schema
|
||||
|
||||
|
||||
def test_schema_is_valid(swagger, codec_yaml):
|
||||
@@ -79,3 +82,34 @@ def test_securiy_requirements(swagger_settings, mock_schema_request):
|
||||
|
||||
swagger = generator.get_schema(mock_schema_request, public=True)
|
||||
assert swagger['security'] == []
|
||||
|
||||
|
||||
def test_replaced_serializer():
|
||||
class DetailSerializer(serializers.Serializer):
|
||||
detail = serializers.CharField()
|
||||
|
||||
class DetailViewSet(viewsets.ViewSet):
|
||||
serializer_class = DetailSerializer
|
||||
|
||||
@swagger_auto_schema(responses={404: openapi.Response("Not found or Not accessible", DetailSerializer)})
|
||||
def retrieve(self, request, pk=None):
|
||||
serializer = DetailSerializer({'detail': None})
|
||||
return Response(serializer.data)
|
||||
|
||||
router = routers.DefaultRouter()
|
||||
router.register(r'details', DetailViewSet, base_name='details')
|
||||
|
||||
generator = OpenAPISchemaGenerator(
|
||||
info=openapi.Info(title="Test generator", default_version="v1"),
|
||||
version="v2",
|
||||
url='',
|
||||
patterns=router.urls
|
||||
)
|
||||
|
||||
for _ in range(3):
|
||||
swagger = generator.get_schema(None, True)
|
||||
assert 'Detail' in swagger['definitions']
|
||||
assert 'detail' in swagger['definitions']['Detail']['properties']
|
||||
responses = swagger['paths']['/details/{id}/']['get']['responses']
|
||||
assert '404' in responses
|
||||
assert responses['404']['schema']['$ref'] == "#/definitions/Detail"
|
||||
|
||||
Reference in New Issue
Block a user