mirror of
https://github.com/correl/openapi-core.git
synced 2025-01-01 11:03:19 +00:00
Merge pull request #7 from p1c2u/fix/content-type-renamed-to-mimetype
Content_type renamed to mimetype
This commit is contained in:
commit
9d6a2e1956
5 changed files with 20 additions and 20 deletions
|
@ -5,8 +5,8 @@ from six import iteritems
|
||||||
class MediaType(object):
|
class MediaType(object):
|
||||||
"""Represents an OpenAPI MediaType."""
|
"""Represents an OpenAPI MediaType."""
|
||||||
|
|
||||||
def __init__(self, content_type, schema=None):
|
def __init__(self, mimetype, schema=None):
|
||||||
self.content_type = content_type
|
self.mimetype = mimetype
|
||||||
self.schema = schema
|
self.schema = schema
|
||||||
|
|
||||||
def unmarshal(self, value):
|
def unmarshal(self, value):
|
||||||
|
@ -23,11 +23,11 @@ class MediaTypeGenerator(object):
|
||||||
self.schemas_registry = schemas_registry
|
self.schemas_registry = schemas_registry
|
||||||
|
|
||||||
def generate(self, content):
|
def generate(self, content):
|
||||||
for content_type, media_type in iteritems(content):
|
for mimetype, media_type in iteritems(content):
|
||||||
schema_spec = media_type.get('schema')
|
schema_spec = media_type.get('schema')
|
||||||
|
|
||||||
schema = None
|
schema = None
|
||||||
if schema_spec:
|
if schema_spec:
|
||||||
schema, _ = self.schemas_registry.get_or_create(schema_spec)
|
schema, _ = self.schemas_registry.get_or_create(schema_spec)
|
||||||
|
|
||||||
yield content_type, MediaType(content_type, schema)
|
yield mimetype, MediaType(mimetype, schema)
|
||||||
|
|
|
@ -11,8 +11,8 @@ class RequestBody(object):
|
||||||
self.content = dict(content)
|
self.content = dict(content)
|
||||||
self.required = required
|
self.required = required
|
||||||
|
|
||||||
def __getitem__(self, content_type):
|
def __getitem__(self, mimetype):
|
||||||
return self.content[content_type]
|
return self.content[mimetype]
|
||||||
|
|
||||||
|
|
||||||
class RequestBodyFactory(object):
|
class RequestBodyFactory(object):
|
||||||
|
|
|
@ -95,10 +95,10 @@ class RequestBodyFactory(BaseRequestFactory):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
media_type = operation.request_body[request.content_type]
|
media_type = operation.request_body[request.mimetype]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise InvalidContentTypeError(
|
raise InvalidContentTypeError(
|
||||||
"Invalid Content-Type `{0}`".format(request.content_type))
|
"Invalid media type `{0}`".format(request.mimetype))
|
||||||
|
|
||||||
return media_type.unmarshal(request.data)
|
return media_type.unmarshal(request.data)
|
||||||
|
|
||||||
|
@ -117,7 +117,7 @@ class BaseOpenAPIRequest(object):
|
||||||
|
|
||||||
data = NotImplemented
|
data = NotImplemented
|
||||||
|
|
||||||
content_type = NotImplemented
|
mimetype = NotImplemented
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def full_url_pattern(self):
|
def full_url_pattern(self):
|
||||||
|
|
|
@ -21,7 +21,7 @@ class RequestMock(BaseOpenAPIRequest):
|
||||||
def __init__(
|
def __init__(
|
||||||
self, host_url, method, path, path_pattern=None, args=None,
|
self, host_url, method, path, path_pattern=None, args=None,
|
||||||
view_args=None, headers=None, cookies=None, data=None,
|
view_args=None, headers=None, cookies=None, data=None,
|
||||||
content_type='application/json'):
|
mimetype='application/json'):
|
||||||
self.host_url = host_url
|
self.host_url = host_url
|
||||||
self.path = path
|
self.path = path
|
||||||
self.path_pattern = path_pattern or path
|
self.path_pattern = path_pattern or path
|
||||||
|
@ -33,7 +33,7 @@ class RequestMock(BaseOpenAPIRequest):
|
||||||
self.cookies = cookies or {}
|
self.cookies = cookies or {}
|
||||||
self.data = data or ''
|
self.data = data or ''
|
||||||
|
|
||||||
self.content_type = content_type
|
self.mimetype = mimetype
|
||||||
|
|
||||||
|
|
||||||
class TestPetstore(object):
|
class TestPetstore(object):
|
||||||
|
@ -89,12 +89,12 @@ class TestPetstore(object):
|
||||||
assert bool(operation.request_body.required) ==\
|
assert bool(operation.request_body.required) ==\
|
||||||
request_body_spec.get('required', False)
|
request_body_spec.get('required', False)
|
||||||
|
|
||||||
for content_type, media_type in iteritems(
|
for mimetype, media_type in iteritems(
|
||||||
operation.request_body.content):
|
operation.request_body.content):
|
||||||
assert type(media_type) == MediaType
|
assert type(media_type) == MediaType
|
||||||
assert media_type.content_type == content_type
|
assert media_type.mimetype == mimetype
|
||||||
|
|
||||||
content_spec = request_body_spec['content'][content_type]
|
content_spec = request_body_spec['content'][mimetype]
|
||||||
schema_spec = content_spec.get('schema')
|
schema_spec = content_spec.get('schema')
|
||||||
assert bool(schema_spec) == bool(media_type.schema)
|
assert bool(schema_spec) == bool(media_type.schema)
|
||||||
|
|
||||||
|
@ -351,7 +351,7 @@ class TestPetstore(object):
|
||||||
with pytest.raises(InvalidValueType):
|
with pytest.raises(InvalidValueType):
|
||||||
request.get_body(spec)
|
request.get_body(spec)
|
||||||
|
|
||||||
def test_post_pets_raises_invalid_content_type(self, spec):
|
def test_post_pets_raises_invalid_mimetype(self, spec):
|
||||||
host_url = 'http://petstore.swagger.io/v1'
|
host_url = 'http://petstore.swagger.io/v1'
|
||||||
path_pattern = '/v1/pets'
|
path_pattern = '/v1/pets'
|
||||||
data_json = {
|
data_json = {
|
||||||
|
@ -362,7 +362,7 @@ class TestPetstore(object):
|
||||||
|
|
||||||
request = RequestMock(
|
request = RequestMock(
|
||||||
host_url, 'POST', '/pets',
|
host_url, 'POST', '/pets',
|
||||||
path_pattern=path_pattern, data=data, content_type='text/html',
|
path_pattern=path_pattern, data=data, mimetype='text/html',
|
||||||
)
|
)
|
||||||
|
|
||||||
parameters = request.get_parameters(spec)
|
parameters = request.get_parameters(spec)
|
||||||
|
@ -383,7 +383,7 @@ class TestPetstore(object):
|
||||||
|
|
||||||
request = RequestMock(
|
request = RequestMock(
|
||||||
host_url, 'POST', '/pets',
|
host_url, 'POST', '/pets',
|
||||||
path_pattern=path_pattern, data=data, content_type='text/html',
|
path_pattern=path_pattern, data=data, mimetype='text/html',
|
||||||
)
|
)
|
||||||
|
|
||||||
with pytest.raises(InvalidServerError):
|
with pytest.raises(InvalidServerError):
|
||||||
|
|
|
@ -16,6 +16,6 @@ class TestRequestBodies(object):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def test_iteritems(self, request_body):
|
def test_iteritems(self, request_body):
|
||||||
for content_type in request_body.content.keys():
|
for mimetype in request_body.content.keys():
|
||||||
assert request_body[content_type] ==\
|
assert request_body[mimetype] ==\
|
||||||
request_body.content[content_type]
|
request_body.content[mimetype]
|
||||||
|
|
Loading…
Reference in a new issue