Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit322ef8c

Browse files
committed
Added Deprecation Warnings for CoreAPI
1 parent35c0abf commit322ef8c

File tree

5 files changed

+91
-3
lines changed

5 files changed

+91
-3
lines changed

‎rest_framework/filters.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
returned by list views.
44
"""
55
importoperator
6+
importwarnings
67
fromfunctoolsimportreduce
78

89
fromdjango.core.exceptionsimportImproperlyConfigured
@@ -12,6 +13,7 @@
1213
fromdjango.utils.encodingimportforce_str
1314
fromdjango.utils.translationimportgettext_lazyas_
1415

16+
fromrest_frameworkimportRemovedInDRF314Warning
1517
fromrest_framework.compatimportcoreapi,coreschema,distinct
1618
fromrest_framework.settingsimportapi_settings
1719

@@ -29,6 +31,8 @@ def filter_queryset(self, request, queryset, view):
2931

3032
defget_schema_fields(self,view):
3133
assertcoreapiisnotNone,'coreapi must be installed to use `get_schema_fields()`'
34+
ifcoreapiisnotNone:
35+
warnings.warn('CoreAPI compatibility is deprecated and will be removed in DRF 3.14',RemovedInDRF314Warning)
3236
assertcoreschemaisnotNone,'coreschema must be installed to use `get_schema_fields()`'
3337
return []
3438

@@ -146,6 +150,8 @@ def to_html(self, request, queryset, view):
146150

147151
defget_schema_fields(self,view):
148152
assertcoreapiisnotNone,'coreapi must be installed to use `get_schema_fields()`'
153+
ifcoreapiisnotNone:
154+
warnings.warn('CoreAPI compatibility is deprecated and will be removed in DRF 3.14',RemovedInDRF314Warning)
149155
assertcoreschemaisnotNone,'coreschema must be installed to use `get_schema_fields()`'
150156
return [
151157
coreapi.Field(
@@ -296,6 +302,8 @@ def to_html(self, request, queryset, view):
296302

297303
defget_schema_fields(self,view):
298304
assertcoreapiisnotNone,'coreapi must be installed to use `get_schema_fields()`'
305+
ifcoreapiisnotNone:
306+
warnings.warn('CoreAPI compatibility is deprecated and will be removed in DRF 3.14',RemovedInDRF314Warning)
299307
assertcoreschemaisnotNone,'coreschema must be installed to use `get_schema_fields()`'
300308
return [
301309
coreapi.Field(

‎rest_framework/pagination.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Pagination serializers determine the structure of the output that should
33
be used for paginated responses.
44
"""
5+
importwarnings
56
frombase64importb64decode,b64encode
67
fromcollectionsimportOrderedDict,namedtuple
78
fromurllibimportparse
@@ -12,6 +13,7 @@
1213
fromdjango.utils.encodingimportforce_str
1314
fromdjango.utils.translationimportgettext_lazyas_
1415

16+
fromrest_frameworkimportRemovedInDRF314Warning
1517
fromrest_framework.compatimportcoreapi,coreschema
1618
fromrest_framework.exceptionsimportNotFound
1719
fromrest_framework.responseimportResponse
@@ -149,6 +151,8 @@ def get_results(self, data):
149151

150152
defget_schema_fields(self,view):
151153
assertcoreapiisnotNone,'coreapi must be installed to use `get_schema_fields()`'
154+
ifcoreapiisnotNone:
155+
warnings.warn('CoreAPI compatibility is deprecated and will be removed in DRF 3.14',RemovedInDRF314Warning)
152156
return []
153157

154158
defget_schema_operation_parameters(self,view):
@@ -307,6 +311,8 @@ def to_html(self):
307311

308312
defget_schema_fields(self,view):
309313
assertcoreapiisnotNone,'coreapi must be installed to use `get_schema_fields()`'
314+
ifcoreapiisnotNone:
315+
warnings.warn('CoreAPI compatibility is deprecated and will be removed in DRF 3.14',RemovedInDRF314Warning)
310316
assertcoreschemaisnotNone,'coreschema must be installed to use `get_schema_fields()`'
311317
fields= [
312318
coreapi.Field(
@@ -525,6 +531,8 @@ def get_count(self, queryset):
525531

526532
defget_schema_fields(self,view):
527533
assertcoreapiisnotNone,'coreapi must be installed to use `get_schema_fields()`'
534+
ifcoreapiisnotNone:
535+
warnings.warn('CoreAPI compatibility is deprecated and will be removed in DRF 3.14',RemovedInDRF314Warning)
528536
assertcoreschemaisnotNone,'coreschema must be installed to use `get_schema_fields()`'
529537
return [
530538
coreapi.Field(
@@ -924,6 +932,8 @@ def to_html(self):
924932

925933
defget_schema_fields(self,view):
926934
assertcoreapiisnotNone,'coreapi must be installed to use `get_schema_fields()`'
935+
ifcoreapiisnotNone:
936+
warnings.warn('CoreAPI compatibility is deprecated and will be removed in DRF 3.14',RemovedInDRF314Warning)
927937
assertcoreschemaisnotNone,'coreschema must be installed to use `get_schema_fields()`'
928938
fields= [
929939
coreapi.Field(

‎rest_framework/schemas/coreapi.py‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
fromdjango.dbimportmodels
66
fromdjango.utils.encodingimportforce_str
77

8-
fromrest_frameworkimportexceptions,serializers
8+
fromrest_frameworkimportRemovedInDRF314Warning,exceptions,serializers
99
fromrest_framework.compatimportcoreapi,coreschema,uritemplate
1010
fromrest_framework.settingsimportapi_settings
1111

@@ -118,6 +118,8 @@ class SchemaGenerator(BaseSchemaGenerator):
118118

119119
def__init__(self,title=None,url=None,description=None,patterns=None,urlconf=None,version=None):
120120
assertcoreapi,'`coreapi` must be installed for schema support.'
121+
ifcoreapiisnotNone:
122+
warnings.warn('CoreAPI compatibility is deprecated and will be removed in DRF 3.14',RemovedInDRF314Warning)
121123
assertcoreschema,'`coreschema` must be installed for schema support.'
122124

123125
super(SchemaGenerator,self).__init__(title,url,description,patterns,urlconf)
@@ -347,6 +349,8 @@ def __init__(self, manual_fields=None):
347349
will be added to auto-generated fields, overwriting on `Field.name`
348350
"""
349351
super(AutoSchema,self).__init__()
352+
ifcoreapiisnotNone:
353+
warnings.warn('CoreAPI compatibility is deprecated and will be removed in DRF 3.14',RemovedInDRF314Warning)
350354
ifmanual_fieldsisNone:
351355
manual_fields= []
352356
self._manual_fields=manual_fields
@@ -588,6 +592,8 @@ def __init__(self, fields, description='', encoding=None):
588592
* `description`: String description for view. Optional.
589593
"""
590594
super(ManualSchema,self).__init__()
595+
ifcoreapiisnotNone:
596+
warnings.warn('CoreAPI compatibility is deprecated and will be removed in DRF 3.14',RemovedInDRF314Warning)
591597
assertall(isinstance(f,coreapi.Field)forfinfields),"`fields` must be a list of coreapi.Field instances"
592598
self._fields=fields
593599
self._description=description
@@ -609,4 +615,6 @@ def get_link(self, path, method, base_url):
609615

610616
defis_enabled():
611617
"""Is CoreAPI Mode enabled?"""
618+
ifcoreapiisnotNone:
619+
warnings.warn('CoreAPI compatibility is deprecated and will be removed in DRF 3.14',RemovedInDRF314Warning)
612620
returnissubclass(api_settings.DEFAULT_SCHEMA_CLASS,AutoSchema)

‎setup.cfg‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ license_file = LICENSE.md
44
[tool:pytest]
55
addopts=--tb=short --strict -ra
66
testspath = tests
7+
filterwarnings = ignore:CoreAPI compatibility is deprecated*:rest_framework.RemovedInDRF314Warning
78

89
[flake8]
910
ignore = E501,W504

‎tests/schemas/test_coreapi.py‎

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,24 @@
88
fromdjango.urlsimportpath
99

1010
fromrest_frameworkimport (
11-
filters,generics,pagination,permissions,serializers
11+
RemovedInDRF314Warning,filters,generics,pagination,permissions,
12+
serializers
1213
)
1314
fromrest_framework.compatimportcoreapi,coreschema
1415
fromrest_framework.decoratorsimportaction,api_view,schema
16+
fromrest_framework.filtersimport (
17+
BaseFilterBackend,OrderingFilter,SearchFilter
18+
)
19+
fromrest_framework.paginationimport (
20+
BasePagination,CursorPagination,LimitOffsetPagination,
21+
PageNumberPagination
22+
)
1523
fromrest_framework.requestimportRequest
1624
fromrest_framework.routersimportDefaultRouter,SimpleRouter
1725
fromrest_framework.schemasimport (
1826
AutoSchema,ManualSchema,SchemaGenerator,get_schema_view
1927
)
20-
fromrest_framework.schemas.coreapiimportfield_to_schema
28+
fromrest_framework.schemas.coreapiimportfield_to_schema,is_enabled
2129
fromrest_framework.schemas.generatorsimportEndpointEnumerator
2230
fromrest_framework.schemas.utilsimportis_list_view
2331
fromrest_framework.testimportAPIClient,APIRequestFactory
@@ -1374,3 +1382,56 @@ def test_schema_handles_exception():
13741382
response.render()
13751383
assertresponse.status_code==403
13761384
assertb"You do not have permission to perform this action."inresponse.content
1385+
1386+
1387+
deftest_coreapi_deprecation():
1388+
withpytest.warns(RemovedInDRF314Warning):
1389+
ifcoreapiisnotNone:
1390+
SchemaGenerator()
1391+
1392+
withpytest.warns(RemovedInDRF314Warning):
1393+
ifcoreapiisnotNone:
1394+
AutoSchema()
1395+
1396+
withpytest.warns(RemovedInDRF314Warning):
1397+
ifcoreapiisnotNone:
1398+
ManualSchema({})
1399+
1400+
withpytest.warns(RemovedInDRF314Warning):
1401+
ifcoreapiisnotNone:
1402+
deprecated_filter=OrderingFilter()
1403+
deprecated_filter.get_schema_fields({})
1404+
1405+
withpytest.warns(RemovedInDRF314Warning):
1406+
ifcoreapiisnotNone:
1407+
deprecated_filter=BaseFilterBackend()
1408+
deprecated_filter.get_schema_fields({})
1409+
1410+
withpytest.warns(RemovedInDRF314Warning):
1411+
ifcoreapiisnotNone:
1412+
deprecated_filter=SearchFilter()
1413+
deprecated_filter.get_schema_fields({})
1414+
1415+
withpytest.warns(RemovedInDRF314Warning):
1416+
ifcoreapiisnotNone:
1417+
paginator=BasePagination()
1418+
paginator.get_schema_fields({})
1419+
1420+
withpytest.warns(RemovedInDRF314Warning):
1421+
ifcoreapiisnotNone:
1422+
paginator=PageNumberPagination()
1423+
paginator.get_schema_fields({})
1424+
1425+
withpytest.warns(RemovedInDRF314Warning):
1426+
ifcoreapiisnotNone:
1427+
paginator=LimitOffsetPagination()
1428+
paginator.get_schema_fields({})
1429+
1430+
withpytest.warns(RemovedInDRF314Warning):
1431+
ifcoreapiisnotNone:
1432+
paginator=CursorPagination()
1433+
paginator.get_schema_fields({})
1434+
1435+
withpytest.warns(RemovedInDRF314Warning):
1436+
ifcoreapiisnotNone:
1437+
is_enabled()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp