mirror of
https://github.com/correl/openapi-core.git
synced 2024-11-21 19:18:41 +00:00
Missing Info models
This commit is contained in:
parent
e553923d76
commit
d4ac0978d5
10 changed files with 107 additions and 4 deletions
0
openapi_core/schema/contacts/__init__.py
Normal file
0
openapi_core/schema/contacts/__init__.py
Normal file
15
openapi_core/schema/contacts/factories.py
Normal file
15
openapi_core/schema/contacts/factories.py
Normal file
|
@ -0,0 +1,15 @@
|
|||
"""OpenAPI core contacts factories module"""
|
||||
from openapi_core.schema.contacts.models import Contact
|
||||
|
||||
|
||||
class ContactFactory(object):
|
||||
|
||||
def __init__(self, dereferencer):
|
||||
self.dereferencer = dereferencer
|
||||
|
||||
def create(self, contact_spec):
|
||||
contact_deref = self.dereferencer.dereference(contact_spec)
|
||||
name = contact_deref.get('name')
|
||||
url = contact_deref.get('url')
|
||||
email = contact_deref.get('email')
|
||||
return Contact(name=name, url=url, email=email)
|
9
openapi_core/schema/contacts/models.py
Normal file
9
openapi_core/schema/contacts/models.py
Normal file
|
@ -0,0 +1,9 @@
|
|||
"""OpenAPI core contacts models module"""
|
||||
|
||||
|
||||
class Contact(object):
|
||||
|
||||
def __init__(self, name=None, url=None, email=None):
|
||||
self.name = name
|
||||
self.url = url
|
||||
self.email = email
|
|
@ -1,5 +1,8 @@
|
|||
"""OpenAPI core infos factories module"""
|
||||
from openapi_core.compat import lru_cache
|
||||
from openapi_core.schema.contacts.factories import ContactFactory
|
||||
from openapi_core.schema.infos.models import Info
|
||||
from openapi_core.schema.licenses.factories import LicenseFactory
|
||||
|
||||
|
||||
class InfoFactory(object):
|
||||
|
@ -11,4 +14,31 @@ class InfoFactory(object):
|
|||
info_deref = self.dereferencer.dereference(info_spec)
|
||||
title = info_deref['title']
|
||||
version = info_deref['version']
|
||||
return Info(title, version)
|
||||
description = info_deref.get('description')
|
||||
terms_of_service = info_deref.get('termsOfService')
|
||||
|
||||
contact = None
|
||||
if 'contact' in info_deref:
|
||||
contact_spec = info_deref.get('contact')
|
||||
contact = self.contact_factory.create(contact_spec)
|
||||
|
||||
license = None
|
||||
if 'license' in info_deref:
|
||||
license_spec = info_deref.get('license')
|
||||
license = self.license_factory.create(license_spec)
|
||||
|
||||
return Info(
|
||||
title, version,
|
||||
description=description, terms_of_service=terms_of_service,
|
||||
contact=contact, license=license,
|
||||
)
|
||||
|
||||
@property
|
||||
@lru_cache()
|
||||
def contact_factory(self):
|
||||
return ContactFactory(self.dereferencer)
|
||||
|
||||
@property
|
||||
@lru_cache()
|
||||
def license_factory(self):
|
||||
return LicenseFactory(self.dereferencer)
|
||||
|
|
|
@ -3,6 +3,13 @@
|
|||
|
||||
class Info(object):
|
||||
|
||||
def __init__(self, title, version):
|
||||
def __init__(
|
||||
self, title, version, description=None, terms_of_service=None,
|
||||
contact=None, license=None,
|
||||
):
|
||||
self.title = title
|
||||
self.version = version
|
||||
self.description = description
|
||||
self.terms_of_service = terms_of_service
|
||||
self.contact = contact
|
||||
self.license = license
|
||||
|
|
0
openapi_core/schema/licenses/__init__.py
Normal file
0
openapi_core/schema/licenses/__init__.py
Normal file
14
openapi_core/schema/licenses/factories.py
Normal file
14
openapi_core/schema/licenses/factories.py
Normal file
|
@ -0,0 +1,14 @@
|
|||
"""OpenAPI core licenses factories module"""
|
||||
from openapi_core.schema.licenses.models import License
|
||||
|
||||
|
||||
class LicenseFactory(object):
|
||||
|
||||
def __init__(self, dereferencer):
|
||||
self.dereferencer = dereferencer
|
||||
|
||||
def create(self, license_spec):
|
||||
license_deref = self.dereferencer.dereference(license_spec)
|
||||
name = license_deref['name']
|
||||
url = license_deref.get('url')
|
||||
return License(name, url=url)
|
8
openapi_core/schema/licenses/models.py
Normal file
8
openapi_core/schema/licenses/models.py
Normal file
|
@ -0,0 +1,8 @@
|
|||
"""OpenAPI core licenses models module"""
|
||||
|
||||
|
||||
class License(object):
|
||||
|
||||
def __init__(self, name, url=None):
|
||||
self.name = name
|
||||
self.url = url
|
|
@ -2,8 +2,15 @@ openapi: "3.0.0"
|
|||
info:
|
||||
version: 1.0.0
|
||||
title: Swagger Petstore
|
||||
description: Swagger Petstore API specification
|
||||
termsOfService: Fair use
|
||||
contact:
|
||||
name: Author
|
||||
url: http://petstore.swagger.io
|
||||
email: email@petstore.swagger.io
|
||||
license:
|
||||
name: MIT
|
||||
url: https://opensource.org/licenses/MIT
|
||||
servers:
|
||||
- url: http://petstore.swagger.io/{version}
|
||||
variables:
|
||||
|
|
|
@ -48,8 +48,21 @@ class TestPetstore(object):
|
|||
|
||||
def test_spec(self, spec, spec_dict):
|
||||
url = 'http://petstore.swagger.io/v1'
|
||||
assert spec.info.title == spec_dict['info']['title']
|
||||
assert spec.info.version == spec_dict['info']['version']
|
||||
|
||||
info_spec = spec_dict['info']
|
||||
assert spec.info.title == info_spec['title']
|
||||
assert spec.info.description == info_spec['description']
|
||||
assert spec.info.terms_of_service == info_spec['termsOfService']
|
||||
assert spec.info.version == info_spec['version']
|
||||
|
||||
contact_spec = info_spec['contact']
|
||||
assert spec.info.contact.name == contact_spec['name']
|
||||
assert spec.info.contact.url == contact_spec['url']
|
||||
assert spec.info.contact.email == contact_spec['email']
|
||||
|
||||
license_spec = info_spec['license']
|
||||
assert spec.info.license.name == license_spec['name']
|
||||
assert spec.info.license.url == license_spec['url']
|
||||
|
||||
assert spec.get_server_url() == url
|
||||
|
||||
|
|
Loading…
Reference in a new issue