Skip to content
Snippets Groups Projects
Commit 1f91579a authored by Bastien Abadie's avatar Bastien Abadie
Browse files

Merge branch 'drf-3.11' into 'master'

Bump to DRF 3.11

See merge request !608
parents 2c726cc2 c4b4b67a
No related branches found
No related tags found
1 merge request!608Bump to DRF 3.11
from enum import Enum
from rest_framework import serializers
from rest_framework.schemas.openapi import AutoSchema as BaseAutoSchema
import warnings
......@@ -53,21 +52,6 @@ class AutoSchema(BaseAutoSchema):
return schema
def _map_field(self, field):
"""
Yet another temporary patch because HStoreField is not properly treated as `type: object`.
https://github.com/encode/django-rest-framework/issues/6913
https://github.com/encode/django-rest-framework/pull/6914
"""
schema = super()._map_field(field)
if isinstance(field, serializers.HStoreField):
assert schema['type'] == 'string' # Will crash when this is fixed upstream
return {
'type': 'object'
}
return schema
def _get_request_body(self, path, method):
"""
Add x-name to requestBody objects to allow APIStar to use `body={}` arguments on requests
......
......@@ -42,6 +42,7 @@ class TestOpenAPI(TestCase):
inspector.get_operation('/test/', 'GET'),
{
'operationId': 'RetrieveThing',
'description': '',
'parameters': [],
'responses': {
'200': {
......@@ -74,6 +75,7 @@ class TestOpenAPI(TestCase):
inspector.get_operation('/test/', 'GET'),
{
'operationId': 'RetrieveThing',
'description': '',
'parameters': [],
'responses': {
'200': {
......@@ -98,6 +100,7 @@ class TestOpenAPI(TestCase):
action = 'Retrieve'
openapi_overrides = {
'operationId': 'HaltAndCatchFire',
'description': '',
'tags': ['bad-ideas'],
'parameters': [
{
......@@ -119,6 +122,7 @@ class TestOpenAPI(TestCase):
inspector.get_operation('/test/{id}/', 'GET'),
{
'operationId': 'HaltAndCatchFire',
'description': '',
'parameters': [
{
'description': '',
......@@ -166,6 +170,7 @@ class TestOpenAPI(TestCase):
inspector.get_operation('/test/', 'GET'),
{
'operationId': 'ListThings',
'description': '',
'parameters': [],
'responses': {
'200': {
......@@ -183,21 +188,6 @@ class TestOpenAPI(TestCase):
}
)
def test_bugfix_hstorefield(self):
"""
Test the temporary fix for serializers.HStoreField being treated as a string
"""
inspector = AutoSchema()
self.assertDictEqual(
inspector._map_field(serializers.HStoreField()),
{'type': 'object'},
)
# Other fields should be unaffected
self.assertDictEqual(
inspector._map_field(serializers.CharField()),
{'type': 'string'},
)
def test_bugfix_callable_defaults(self):
"""
Test the temporary fix to convert callable defaults into their results
......@@ -302,39 +292,34 @@ class TestOpenAPI(TestCase):
inspector = AutoSchema()
inspector.view = create_view(ThingView, 'POST', create_request('/test/'))
expected_schema = {
'schema': {
'properties': {
'my_field': {
'type': 'string'
}
},
'required': ['my_field']
}
}
self.assertDictEqual(
inspector.get_operation('/test/', 'POST'),
{
'operationId': 'CreateThing',
'description': '',
'parameters': [],
'requestBody': {
'content': {
'application/json': {
'schema': {
'properties': {
'my_field': {
'type': 'string',
},
},
'required': ['my_field']
},
},
'application/json': expected_schema,
'application/x-www-form-urlencoded': expected_schema,
'multipart/form-data': expected_schema
},
'x-name': 'body',
},
'responses': {
'200': {
'content': {
'application/json': {
'schema': {
'properties': {
'my_field': {
'type': 'string',
},
},
'required': ['my_field']
},
},
'application/json': expected_schema,
},
'description': '',
}
......
......@@ -8,7 +8,7 @@ chardet==3.0.4
django-admin-hstore-widget==1.0.1
django-cors-headers==2.4.0
django-enumfields==1.0.0
djangorestframework==3.10.3
djangorestframework==3.11.0
elasticsearch-dsl>=6.0.0,<7.0.0
et-xmlfile==1.0.1
gitpython==2.1.11
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment