mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-30 18:09:59 +03:00
Fix requestBody not wrapped in a schema in OpenAPI (#6565)
* Wrap requestBody contents in JSON schemas * Update unit test * Wrap response schemas in a schema object
This commit is contained in:
parent
fa40bfa278
commit
ac64c0a536
|
@ -770,7 +770,10 @@ class OpenAPIAutoSchema(ViewInspector):
|
||||||
del content['properties'][name]
|
del content['properties'][name]
|
||||||
|
|
||||||
return {
|
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):
|
def _get_responses(self, path, method):
|
||||||
|
@ -797,6 +800,9 @@ class OpenAPIAutoSchema(ViewInspector):
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'200': {
|
'200': {
|
||||||
'content': {ct: content for ct in self.content_types}
|
'content': {
|
||||||
|
ct: {'schema': content}
|
||||||
|
for ct in self.content_types
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,7 +59,7 @@ class TestOperationIntrospection(TestCase):
|
||||||
assert operation == {
|
assert operation == {
|
||||||
'operationId': 'ListExamples',
|
'operationId': 'ListExamples',
|
||||||
'parameters': [],
|
'parameters': [],
|
||||||
'responses': {'200': {'content': {'application/json': {}}}},
|
'responses': {'200': {'content': {'application/json': {'schema': {}}}}},
|
||||||
}
|
}
|
||||||
|
|
||||||
def test_path_with_id_parameter(self):
|
def test_path_with_id_parameter(self):
|
||||||
|
@ -105,8 +105,8 @@ class TestOperationIntrospection(TestCase):
|
||||||
inspector.view = view
|
inspector.view = view
|
||||||
|
|
||||||
request_body = inspector._get_request_body(path, method)
|
request_body = inspector._get_request_body(path, method)
|
||||||
assert request_body['content']['application/json']['required'] == ['text']
|
assert request_body['content']['application/json']['schema']['required'] == ['text']
|
||||||
assert list(request_body['content']['application/json']['properties'].keys()) == ['text']
|
assert list(request_body['content']['application/json']['schema']['properties'].keys()) == ['text']
|
||||||
|
|
||||||
def test_response_body_generation(self):
|
def test_response_body_generation(self):
|
||||||
path = '/'
|
path = '/'
|
||||||
|
@ -128,8 +128,8 @@ class TestOperationIntrospection(TestCase):
|
||||||
inspector.view = view
|
inspector.view = view
|
||||||
|
|
||||||
responses = inspector._get_responses(path, method)
|
responses = inspector._get_responses(path, method)
|
||||||
assert responses['200']['content']['application/json']['required'] == ['text']
|
assert responses['200']['content']['application/json']['schema']['required'] == ['text']
|
||||||
assert list(responses['200']['content']['application/json']['properties'].keys()) == ['text']
|
assert list(responses['200']['content']['application/json']['schema']['properties'].keys()) == ['text']
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skipif(uritemplate is None, reason='uritemplate not installed.')
|
@pytest.mark.skipif(uritemplate is None, reason='uritemplate not installed.')
|
||||||
|
|
Loading…
Reference in New Issue
Block a user