Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Travis job, mypy type checking #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
openapi.yaml
*.swp
*.pyc
.mypy_cache
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
language: python
python:
- "3.6"
install:
- pip install mypy
script:
- mypy openapi
2 changes: 1 addition & 1 deletion openapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
# that they may be referenced throughout the schema without issue
from . import info, servers, paths, general, schemas, components, security

__all__ = [OpenAPI]
__all__ = ["OpenAPI"]
6 changes: 4 additions & 2 deletions openapi/general.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import List

from .object_base import ObjectBase

class ExternalDocumentation(ObjectBase):
Expand All @@ -8,7 +10,7 @@ class ExternalDocumentation(ObjectBase):
.. _External Documentation Object: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#externalDocumentationObject
"""
__slos__ = ['description','url']
required_fields = 'url'
required_fields: List[str] = ['url']

def _parse_data(self):
self.description = self._get('description', str)
Expand All @@ -21,7 +23,7 @@ class Reference(ObjectBase):
.. _Reference Object: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#referenceObject
"""
__slots__ = ['ref'] # can't start a variable name with a $
required_fields = ['$ref']
required_fields: List[str] = ['$ref']

def _parse_data(self):
self.ref = self._get('$ref', str)
Expand Down
6 changes: 4 additions & 2 deletions openapi/info.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import List

from .object_base import ObjectBase

class Info(ObjectBase):
Expand All @@ -7,7 +9,7 @@ class Info(ObjectBase):
.. _the spec: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#infoObject
"""
__slots__ = ['title','description','termsOfService','contact','license','version']
required_fields = ['title','version']
required_fields: List[str] = ['title','version']

def _parse_data(self):
"""
Expand Down Expand Up @@ -43,7 +45,7 @@ class License(ObjectBase):
.. _here: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#license-object
"""
__slots__ = ['name','url']
required_fields = ['name']
required_fields: List[str] = ['name']

def _parse_data(self):
"""
Expand Down
4 changes: 3 additions & 1 deletion openapi/object_base.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import List

from .errors import SpecError

class ObjectBase:
Expand All @@ -7,7 +9,7 @@ class ObjectBase:
"""
__slots__ = ['path','raw_element','_accessed_members','strict','extensions',
'_root', '_original_ref']
required_fields = []
required_fields: List[str] = []

def __init__(self, path, raw_element, root):
"""
Expand Down
4 changes: 3 additions & 1 deletion openapi/openapi.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import List

from .object_base import ObjectBase, Map
from .errors import ReferenceResolutionError

Expand All @@ -10,7 +12,7 @@ class OpenAPI(ObjectBase):
"""
__slots__ = ['openapi','info','servers','paths','components','security','tags',
'externalDocs','_operation_map','_security']
required_fields=['openapi','info','paths']
required_fields: List[str] = ['openapi','info','paths']

def __init__(self, raw_document):
"""
Expand Down
11 changes: 5 additions & 6 deletions openapi/paths.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import requests
from typing import List
from urllib.parse import urlencode # TODO - this will break in python2

from .errors import SpecError
Expand Down Expand Up @@ -48,7 +49,7 @@ class Parameter(ObjectBase):
__slots__ = ['name','in','in_','description','required','deprecated',
'allowEmptyValue','style','explode','allowReserved','schema',
'example','examples']
required_fields = ['name','in']
required_fields: List[str] = ['name','in']


def _parse_data(self):
Expand Down Expand Up @@ -81,7 +82,7 @@ class Operation(ObjectBase):
__slots__ = ['tags','summary','description','externalDocs','operationId',
'parameters','requestBody','responses','callbacks','deprecated',
'security','servers']
required_fields = ['responses']
required_fields: List[str] = ['responses']

def _parse_data(self):
"""
Expand Down Expand Up @@ -252,7 +253,6 @@ class SecurityRequirement(ObjectBase):
"""
"""
___slots__ = ['name','types']
required_fields=[]

def _parse_data(self):
"""
Expand Down Expand Up @@ -280,7 +280,7 @@ class RequestBody(ObjectBase):
.. _RequestBody: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#requestBodyObject
"""
__slots__ = ['description','content','required']
required_fields = ['content']
required_fields: List[str] = ['content']

def _parse_data(self):
"""
Expand All @@ -300,7 +300,6 @@ class MediaType(ObjectBase):
.. _MediaType: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#mediaTypeObject
"""
__slots__ = ['schema','example','examples','encoding']
required_fields = []

def _parse_data(self):
"""
Expand All @@ -323,7 +322,7 @@ class Response(ObjectBase):
.. _Response Object: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#response-object
"""
__slots__ = ['description','headers','content','links']
required_fields = ['description']
required_fields: List[str] = ['description']

def _parse_data(self):
"""
Expand Down
3 changes: 2 additions & 1 deletion openapi/schemas.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import List

from .object_base import ObjectBase
from .general import Reference # need this for Model below

Expand All @@ -14,7 +16,6 @@ class Schema(ObjectBase):
'properties','additionalProperties','description','format',
'default','nullable','discriminator','readOnly','writeOnly',
'xml','externalDocs','example','deprecated','_model_type']
required_fields = []

def _parse_data(self):
"""
Expand Down