Skip to content

Commit 6e07b0a

Browse files
committed
content_type renamed to mimetype
1 parent fc28729 commit 6e07b0a

File tree

5 files changed

+20
-20
lines changed

5 files changed

+20
-20
lines changed

openapi_core/media_types.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
class MediaType(object):
66
"""Represents an OpenAPI MediaType."""
77

8-
def __init__(self, content_type, schema=None):
9-
self.content_type = content_type
8+
def __init__(self, mimetype, schema=None):
9+
self.mimetype = mimetype
1010
self.schema = schema
1111

1212
def unmarshal(self, value):
@@ -23,11 +23,11 @@ def __init__(self, dereferencer, schemas_registry):
2323
self.schemas_registry = schemas_registry
2424

2525
def generate(self, content):
26-
for content_type, media_type in iteritems(content):
26+
for mimetype, media_type in iteritems(content):
2727
schema_spec = media_type.get('schema')
2828

2929
schema = None
3030
if schema_spec:
3131
schema, _ = self.schemas_registry.get_or_create(schema_spec)
3232

33-
yield content_type, MediaType(content_type, schema)
33+
yield mimetype, MediaType(mimetype, schema)

openapi_core/request_bodies.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ def __init__(self, content, required=False):
1111
self.content = dict(content)
1212
self.required = required
1313

14-
def __getitem__(self, content_type):
15-
return self.content[content_type]
14+
def __getitem__(self, mimetype):
15+
return self.content[mimetype]
1616

1717

1818
class RequestBodyFactory(object):

openapi_core/wrappers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,10 @@ def create(self, request, spec):
9595
return None
9696

9797
try:
98-
media_type = operation.request_body[request.content_type]
98+
media_type = operation.request_body[request.mimetype]
9999
except KeyError:
100100
raise InvalidContentTypeError(
101-
"Invalid Content-Type `{0}`".format(request.content_type))
101+
"Invalid media type `{0}`".format(request.mimetype))
102102

103103
return media_type.unmarshal(request.data)
104104

@@ -117,7 +117,7 @@ class BaseOpenAPIRequest(object):
117117

118118
data = NotImplemented
119119

120-
content_type = NotImplemented
120+
mimetype = NotImplemented
121121

122122
@property
123123
def full_url_pattern(self):

tests/integration/test_petstore.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class RequestMock(BaseOpenAPIRequest):
2121
def __init__(
2222
self, host_url, method, path, path_pattern=None, args=None,
2323
view_args=None, headers=None, cookies=None, data=None,
24-
content_type='application/json'):
24+
mimetype='application/json'):
2525
self.host_url = host_url
2626
self.path = path
2727
self.path_pattern = path_pattern or path
@@ -33,7 +33,7 @@ def __init__(
3333
self.cookies = cookies or {}
3434
self.data = data or ''
3535

36-
self.content_type = content_type
36+
self.mimetype = mimetype
3737

3838

3939
class TestPetstore(object):
@@ -89,12 +89,12 @@ def test_spec(self, spec, spec_dict):
8989
assert bool(operation.request_body.required) ==\
9090
request_body_spec.get('required', False)
9191

92-
for content_type, media_type in iteritems(
92+
for mimetype, media_type in iteritems(
9393
operation.request_body.content):
9494
assert type(media_type) == MediaType
95-
assert media_type.content_type == content_type
95+
assert media_type.mimetype == mimetype
9696

97-
content_spec = request_body_spec['content'][content_type]
97+
content_spec = request_body_spec['content'][mimetype]
9898
schema_spec = content_spec.get('schema')
9999
assert bool(schema_spec) == bool(media_type.schema)
100100

@@ -351,7 +351,7 @@ def test_get_pets_wrong_body_type(self, spec):
351351
with pytest.raises(InvalidValueType):
352352
request.get_body(spec)
353353

354-
def test_post_pets_raises_invalid_content_type(self, spec):
354+
def test_post_pets_raises_invalid_mimetype(self, spec):
355355
host_url = 'http://petstore.swagger.io/v1'
356356
path_pattern = '/v1/pets'
357357
data_json = {
@@ -362,7 +362,7 @@ def test_post_pets_raises_invalid_content_type(self, spec):
362362

363363
request = RequestMock(
364364
host_url, 'POST', '/pets',
365-
path_pattern=path_pattern, data=data, content_type='text/html',
365+
path_pattern=path_pattern, data=data, mimetype='text/html',
366366
)
367367

368368
parameters = request.get_parameters(spec)
@@ -383,7 +383,7 @@ def test_post_pets_raises_invalid_server_error(self, spec):
383383

384384
request = RequestMock(
385385
host_url, 'POST', '/pets',
386-
path_pattern=path_pattern, data=data, content_type='text/html',
386+
path_pattern=path_pattern, data=data, mimetype='text/html',
387387
)
388388

389389
with pytest.raises(InvalidServerError):

tests/unit/test_request_bodies.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ def request_body(self):
1616

1717
@property
1818
def test_iteritems(self, request_body):
19-
for content_type in request_body.content.keys():
20-
assert request_body[content_type] ==\
21-
request_body.content[content_type]
19+
for mimetype in request_body.content.keys():
20+
assert request_body[mimetype] ==\
21+
request_body.content[mimetype]

0 commit comments

Comments
 (0)