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) 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

View File

@ -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'