Skip to content

Commit e567134

Browse files
committed
[OpenAPI] - Address review feedback
1 parent db7cae6 commit e567134

File tree

3 files changed

+5
-33
lines changed

3 files changed

+5
-33
lines changed

rest_framework_json_api/django_filters/backends.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,8 @@ def get_schema_operation_parameters(self, view):
131131
132132
This is basically the reverse of `get_filterset_kwargs` above.
133133
"""
134-
result = []
135-
for res in super(DjangoFilterBackend, self).get_schema_operation_parameters(view):
134+
result = super(DjangoFilterBackend, self).get_schema_operation_parameters(view)
135+
for res in result:
136136
if 'name' in res:
137137
res['name'] = 'filter[{}]'.format(res['name']).replace('__', '.')
138-
result.append(res)
139138
return result

rest_framework_json_api/schemas/openapi.py

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -271,27 +271,14 @@ class SchemaGenerator(drf_openapi.SchemaGenerator):
271271
Extend DRF's SchemaGenerator to implement jsonapi-flavored generateschema command
272272
"""
273273
def __init__(self, *args, **kwargs):
274-
self.openapi_schema = {}
275274
super().__init__(*args, **kwargs)
276275

277276
def get_schema(self, request=None, public=False):
278277
"""
279278
Generate a JSONAPI OpenAPI schema.
280279
"""
281-
self._initialise_endpoints()
282-
283-
paths = self.get_paths(None if public else request)
284-
if not paths:
285-
return None
286-
287-
schema = {
288-
'openapi': '3.0.2',
289-
'info': self.get_info(),
290-
'paths': paths,
291-
'components': JSONAPI_COMPONENTS,
292-
}
293-
294-
return {**schema, **self.openapi_schema}
280+
schema = super().get_schema(request, public)
281+
return {**schema, 'components': JSONAPI_COMPONENTS}
295282

296283
def get_paths(self, request=None):
297284
"""
@@ -346,9 +333,6 @@ def get_paths(self, request=None):
346333

347334
result.setdefault(path, {})
348335
result[path][method.lower()] = operation
349-
if hasattr(view.schema, 'openapi_schema'):
350-
# TODO: shallow or deep merge?
351-
self.openapi_schema = {**self.openapi_schema, **view.schema.openapi_schema}
352336

353337
return result
354338

@@ -439,21 +423,11 @@ class AutoSchema(drf_openapi.AutoSchema):
439423
"""
440424
content_types = ['application/vnd.api+json']
441425

442-
def __init__(self, openapi_schema={}):
426+
def __init__(self):
443427
"""
444428
Initialize the JSONAPI OAS schema generator
445-
:param openapi_schema: dict: OAS 3.0 document with initial values.
446429
"""
447430
super().__init__()
448-
#: allow initialization of OAS schema doc
449-
self.openapi_schema = openapi_schema
450-
# static JSONAPI fields that get $ref'd to in the view mappings
451-
jsonapi_ref = {
452-
'components': JSONAPI_COMPONENTS
453-
}
454-
# merge in our reference data on top of anything provided by the init.
455-
# TODO: shallow or deep merge?
456-
self.openapi_schema = {**self.openapi_schema, **jsonapi_ref}
457431

458432
def get_operation(self, path, method, action=None):
459433
""" basically a copy of AutoSchema.get_operation """

tox.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ deps =
1515
drf310: djangorestframework>=3.10.2,<3.11
1616
drf311: djangorestframework>=3.11,<3.12
1717
drfmaster: https://github.com/encode/django-rest-framework/archive/master.zip
18-
coreapi>=2.3.1
1918
snapshottest>=0.5.1
2019
-rrequirements/requirements-testing.txt
2120
-rrequirements/requirements-optionals.txt

0 commit comments

Comments
 (0)