mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-22 09:36:49 +03:00
OpenAPI: Use 201 status code for POST requests. (#7206)
This commit is contained in:
parent
2a5c2f3f70
commit
94a09149b6
|
@ -558,9 +558,9 @@ class AutoSchema(ViewInspector):
|
||||||
response_schema = paginator.get_paginated_response_schema(response_schema)
|
response_schema = paginator.get_paginated_response_schema(response_schema)
|
||||||
else:
|
else:
|
||||||
response_schema = item_schema
|
response_schema = item_schema
|
||||||
|
status_code = '201' if method == 'POST' else '200'
|
||||||
return {
|
return {
|
||||||
'200': {
|
status_code: {
|
||||||
'content': {
|
'content': {
|
||||||
ct: {'schema': response_schema}
|
ct: {'schema': response_schema}
|
||||||
for ct in self.response_media_types
|
for ct in self.response_media_types
|
||||||
|
|
|
@ -275,9 +275,10 @@ 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']['schema']['required'] == ['text']
|
assert '201' in responses
|
||||||
assert list(responses['200']['content']['application/json']['schema']['properties'].keys()) == ['text']
|
assert responses['201']['content']['application/json']['schema']['required'] == ['text']
|
||||||
assert 'description' in responses['200']
|
assert list(responses['201']['content']['application/json']['schema']['properties'].keys()) == ['text']
|
||||||
|
assert 'description' in responses['201']
|
||||||
|
|
||||||
def test_response_body_nested_serializer(self):
|
def test_response_body_nested_serializer(self):
|
||||||
path = '/'
|
path = '/'
|
||||||
|
@ -302,7 +303,7 @@ class TestOperationIntrospection(TestCase):
|
||||||
inspector.view = view
|
inspector.view = view
|
||||||
|
|
||||||
responses = inspector._get_responses(path, method)
|
responses = inspector._get_responses(path, method)
|
||||||
schema = responses['200']['content']['application/json']['schema']
|
schema = responses['201']['content']['application/json']['schema']
|
||||||
assert sorted(schema['required']) == ['nested', 'text']
|
assert sorted(schema['required']) == ['nested', 'text']
|
||||||
assert sorted(list(schema['properties'].keys())) == ['nested', 'text']
|
assert sorted(list(schema['properties'].keys())) == ['nested', 'text']
|
||||||
assert schema['properties']['nested']['type'] == 'object'
|
assert schema['properties']['nested']['type'] == 'object'
|
||||||
|
|
Loading…
Reference in New Issue
Block a user