mirror of
https://github.com/correl/openapi-core.git
synced 2024-11-22 03:00:10 +00:00
Schema content refactor 2
This commit is contained in:
parent
f6efa8410d
commit
c900f63e7d
3 changed files with 39 additions and 35 deletions
|
@ -2,9 +2,9 @@
|
|||
from six import iteritems
|
||||
|
||||
from openapi_core.compat import lru_cache
|
||||
from openapi_core.schema.content.factories import ContentFactory
|
||||
from openapi_core.schema.extensions.generators import ExtensionsGenerator
|
||||
from openapi_core.schema.links.generators import LinksGenerator
|
||||
from openapi_core.schema.media_types.generators import MediaTypeGenerator
|
||||
from openapi_core.schema.parameters.generators import ParametersGenerator
|
||||
from openapi_core.schema.responses.models import Response
|
||||
|
||||
|
@ -20,15 +20,15 @@ class ResponsesGenerator(object):
|
|||
response_deref = self.dereferencer.dereference(response)
|
||||
description = response_deref['description']
|
||||
headers = response_deref.get('headers')
|
||||
content = response_deref.get('content')
|
||||
content_spec = response_deref.get('content')
|
||||
links_dict = response_deref.get('links', {})
|
||||
links = self.links_generator.generate(links_dict)
|
||||
|
||||
extensions = self.extensions_generator.generate(response_deref)
|
||||
|
||||
media_types = None
|
||||
if content:
|
||||
media_types = self.media_types_generator.generate(content)
|
||||
content = None
|
||||
if content_spec:
|
||||
content = self.content_factory.create(content_spec)
|
||||
|
||||
parameters = None
|
||||
if headers:
|
||||
|
@ -36,14 +36,14 @@ class ResponsesGenerator(object):
|
|||
|
||||
yield http_status, Response(
|
||||
http_status, description,
|
||||
content=media_types, headers=parameters, links=links,
|
||||
content=content, headers=parameters, links=links,
|
||||
extensions=extensions,
|
||||
)
|
||||
|
||||
@property
|
||||
@lru_cache()
|
||||
def media_types_generator(self):
|
||||
return MediaTypeGenerator(self.dereferencer, self.schemas_registry)
|
||||
def content_factory(self):
|
||||
return ContentFactory(self.dereferencer, self.schemas_registry)
|
||||
|
||||
@property
|
||||
@lru_cache()
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
"""OpenAPI core responses models module"""
|
||||
from openapi_core.schema.content.exceptions import MimeTypeNotFound
|
||||
from openapi_core.schema.content.models import Content
|
||||
from openapi_core.schema.media_types.exceptions import InvalidContentType
|
||||
|
||||
|
||||
|
@ -12,7 +11,7 @@ class Response(object):
|
|||
self.http_status = http_status
|
||||
self.description = description
|
||||
self.headers = headers and dict(headers) or {}
|
||||
self.content = content and Content(content) or Content()
|
||||
self.content = content
|
||||
self.links = links and dict(links) or {}
|
||||
|
||||
self.extensions = extensions and dict(extensions) or {}
|
||||
|
|
|
@ -181,31 +181,6 @@ class TestPetstore(object):
|
|||
|
||||
assert response.description == description_spec
|
||||
|
||||
for mimetype, media_type in iteritems(response.content):
|
||||
assert type(media_type) == MediaType
|
||||
assert media_type.mimetype == mimetype
|
||||
|
||||
content_spec = response_spec['content'][mimetype]
|
||||
|
||||
example_spec = content_spec.get('example')
|
||||
assert media_type.example == example_spec
|
||||
|
||||
schema_spec = content_spec.get('schema')
|
||||
assert bool(schema_spec) == bool(media_type.schema)
|
||||
|
||||
if not schema_spec:
|
||||
continue
|
||||
|
||||
# @todo: test with defererence
|
||||
if '$ref' in schema_spec:
|
||||
continue
|
||||
|
||||
assert type(media_type.schema) == Schema
|
||||
assert media_type.schema.type.value ==\
|
||||
schema_spec['type']
|
||||
assert media_type.schema.required == schema_spec.get(
|
||||
'required', [])
|
||||
|
||||
for parameter_name, parameter in iteritems(
|
||||
response.headers):
|
||||
assert type(parameter) == Parameter
|
||||
|
@ -261,6 +236,36 @@ class TestPetstore(object):
|
|||
assert media_type.schema.required == \
|
||||
schema_spec.get('required', False)
|
||||
|
||||
content_spec = response_spec.get('content')
|
||||
|
||||
if not content_spec:
|
||||
continue
|
||||
|
||||
for mimetype, media_type in iteritems(response.content):
|
||||
assert type(media_type) == MediaType
|
||||
assert media_type.mimetype == mimetype
|
||||
|
||||
content_spec = response_spec['content'][mimetype]
|
||||
|
||||
example_spec = content_spec.get('example')
|
||||
assert media_type.example == example_spec
|
||||
|
||||
schema_spec = content_spec.get('schema')
|
||||
assert bool(schema_spec) == bool(media_type.schema)
|
||||
|
||||
if not schema_spec:
|
||||
continue
|
||||
|
||||
# @todo: test with defererence
|
||||
if '$ref' in schema_spec:
|
||||
continue
|
||||
|
||||
assert type(media_type.schema) == Schema
|
||||
assert media_type.schema.type.value ==\
|
||||
schema_spec['type']
|
||||
assert media_type.schema.required == schema_spec.get(
|
||||
'required', [])
|
||||
|
||||
request_body_spec = operation_spec.get('requestBody')
|
||||
|
||||
assert bool(request_body_spec) == bool(operation.request_body)
|
||||
|
|
Loading…
Reference in a new issue