Skip to content

Commit d4ac097

Browse files
committed
Missing Info models
1 parent e553923 commit d4ac097

File tree

10 files changed

+107
-4
lines changed

10 files changed

+107
-4
lines changed

openapi_core/schema/contacts/__init__.py

Whitespace-only changes.
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""OpenAPI core contacts factories module"""
2+
from openapi_core.schema.contacts.models import Contact
3+
4+
5+
class ContactFactory(object):
6+
7+
def __init__(self, dereferencer):
8+
self.dereferencer = dereferencer
9+
10+
def create(self, contact_spec):
11+
contact_deref = self.dereferencer.dereference(contact_spec)
12+
name = contact_deref.get('name')
13+
url = contact_deref.get('url')
14+
email = contact_deref.get('email')
15+
return Contact(name=name, url=url, email=email)
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"""OpenAPI core contacts models module"""
2+
3+
4+
class Contact(object):
5+
6+
def __init__(self, name=None, url=None, email=None):
7+
self.name = name
8+
self.url = url
9+
self.email = email

openapi_core/schema/infos/factories.py

+31-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
"""OpenAPI core infos factories module"""
2+
from openapi_core.compat import lru_cache
3+
from openapi_core.schema.contacts.factories import ContactFactory
24
from openapi_core.schema.infos.models import Info
5+
from openapi_core.schema.licenses.factories import LicenseFactory
36

47

58
class InfoFactory(object):
@@ -11,4 +14,31 @@ def create(self, info_spec):
1114
info_deref = self.dereferencer.dereference(info_spec)
1215
title = info_deref['title']
1316
version = info_deref['version']
14-
return Info(title, version)
17+
description = info_deref.get('description')
18+
terms_of_service = info_deref.get('termsOfService')
19+
20+
contact = None
21+
if 'contact' in info_deref:
22+
contact_spec = info_deref.get('contact')
23+
contact = self.contact_factory.create(contact_spec)
24+
25+
license = None
26+
if 'license' in info_deref:
27+
license_spec = info_deref.get('license')
28+
license = self.license_factory.create(license_spec)
29+
30+
return Info(
31+
title, version,
32+
description=description, terms_of_service=terms_of_service,
33+
contact=contact, license=license,
34+
)
35+
36+
@property
37+
@lru_cache()
38+
def contact_factory(self):
39+
return ContactFactory(self.dereferencer)
40+
41+
@property
42+
@lru_cache()
43+
def license_factory(self):
44+
return LicenseFactory(self.dereferencer)

openapi_core/schema/infos/models.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33

44
class Info(object):
55

6-
def __init__(self, title, version):
6+
def __init__(
7+
self, title, version, description=None, terms_of_service=None,
8+
contact=None, license=None,
9+
):
710
self.title = title
811
self.version = version
12+
self.description = description
13+
self.terms_of_service = terms_of_service
14+
self.contact = contact
15+
self.license = license

openapi_core/schema/licenses/__init__.py

Whitespace-only changes.
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"""OpenAPI core licenses factories module"""
2+
from openapi_core.schema.licenses.models import License
3+
4+
5+
class LicenseFactory(object):
6+
7+
def __init__(self, dereferencer):
8+
self.dereferencer = dereferencer
9+
10+
def create(self, license_spec):
11+
license_deref = self.dereferencer.dereference(license_spec)
12+
name = license_deref['name']
13+
url = license_deref.get('url')
14+
return License(name, url=url)
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
"""OpenAPI core licenses models module"""
2+
3+
4+
class License(object):
5+
6+
def __init__(self, name, url=None):
7+
self.name = name
8+
self.url = url

tests/integration/data/v3.0/petstore.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,15 @@ openapi: "3.0.0"
22
info:
33
version: 1.0.0
44
title: Swagger Petstore
5+
description: Swagger Petstore API specification
6+
termsOfService: Fair use
7+
contact:
8+
name: Author
9+
url: http://petstore.swagger.io
10+
511
license:
612
name: MIT
13+
url: https://opensource.org/licenses/MIT
714
servers:
815
- url: http://petstore.swagger.io/{version}
916
variables:

tests/integration/schema/test_spec.py

+15-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,21 @@ def response_validator(self, spec):
4848

4949
def test_spec(self, spec, spec_dict):
5050
url = 'http://petstore.swagger.io/v1'
51-
assert spec.info.title == spec_dict['info']['title']
52-
assert spec.info.version == spec_dict['info']['version']
51+
52+
info_spec = spec_dict['info']
53+
assert spec.info.title == info_spec['title']
54+
assert spec.info.description == info_spec['description']
55+
assert spec.info.terms_of_service == info_spec['termsOfService']
56+
assert spec.info.version == info_spec['version']
57+
58+
contact_spec = info_spec['contact']
59+
assert spec.info.contact.name == contact_spec['name']
60+
assert spec.info.contact.url == contact_spec['url']
61+
assert spec.info.contact.email == contact_spec['email']
62+
63+
license_spec = info_spec['license']
64+
assert spec.info.license.name == license_spec['name']
65+
assert spec.info.license.url == license_spec['url']
5366

5467
assert spec.get_server_url() == url
5568

0 commit comments

Comments
 (0)