Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions rest_framework/schemas/inspectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,10 @@ def _get_request_body(self, path, method):
del content['properties'][name]

return {
'content': {ct: content for ct in self.content_types}
'content': {
ct: {'schema': content}
for ct in self.content_types
}
}

def _get_responses(self, path, method):
Expand All @@ -797,6 +800,9 @@ def _get_responses(self, path, method):

return {
'200': {
'content': {ct: content for ct in self.content_types}
'content': {
ct: {'schema': content}
for ct in self.content_types
}
}
}
10 changes: 5 additions & 5 deletions tests/schemas/test_openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def test_path_without_parameters(self):
assert operation == {
'operationId': 'ListExamples',
'parameters': [],
'responses': {'200': {'content': {'application/json': {}}}},
'responses': {'200': {'content': {'application/json': {'schema': {}}}}},
}

def test_path_with_id_parameter(self):
Expand Down Expand Up @@ -105,8 +105,8 @@ class View(generics.GenericAPIView):
inspector.view = view

request_body = inspector._get_request_body(path, method)
assert request_body['content']['application/json']['required'] == ['text']
assert list(request_body['content']['application/json']['properties'].keys()) == ['text']
assert request_body['content']['application/json']['schema']['required'] == ['text']
assert list(request_body['content']['application/json']['schema']['properties'].keys()) == ['text']

def test_response_body_generation(self):
path = '/'
Expand All @@ -128,8 +128,8 @@ class View(generics.GenericAPIView):
inspector.view = view

responses = inspector._get_responses(path, method)
assert responses['200']['content']['application/json']['required'] == ['text']
assert list(responses['200']['content']['application/json']['properties'].keys()) == ['text']
assert responses['200']['content']['application/json']['schema']['required'] == ['text']
assert list(responses['200']['content']['application/json']['schema']['properties'].keys()) == ['text']


@pytest.mark.skipif(uritemplate is None, reason='uritemplate not installed.')
Expand Down