OpenAPI: Use 201 status code for POST requests. (#7206)

This commit is contained in:
Mateusz Legięcki 2020-03-02 16:32:26 +01:00 committed by GitHub
parent 2a5c2f3f70
commit 94a09149b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 6 deletions

View File

@ -558,9 +558,9 @@ class AutoSchema(ViewInspector):
response_schema = paginator.get_paginated_response_schema(response_schema)
else:
response_schema = item_schema
status_code = '201' if method == 'POST' else '200'
return {
'200': {
status_code: {
'content': {
ct: {'schema': response_schema}
for ct in self.response_media_types

View File

@ -275,9 +275,10 @@ class TestOperationIntrospection(TestCase):
inspector.view = view
responses = inspector._get_responses(path, method)
assert responses['200']['content']['application/json']['schema']['required'] == ['text']
assert list(responses['200']['content']['application/json']['schema']['properties'].keys()) == ['text']
assert 'description' in responses['200']
assert '201' in responses
assert responses['201']['content']['application/json']['schema']['required'] == ['text']
assert list(responses['201']['content']['application/json']['schema']['properties'].keys()) == ['text']
assert 'description' in responses['201']
def test_response_body_nested_serializer(self):
path = '/'
@ -302,7 +303,7 @@ class TestOperationIntrospection(TestCase):
inspector.view = view
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(list(schema['properties'].keys())) == ['nested', 'text']
assert schema['properties']['nested']['type'] == 'object'