8000 Version 3 by tomchristie · Pull Request #156 · core-api/python-client · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Mar 18, 2019. It is now read-only.

Version 3 #156

Open
wants to merge 61 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
9bc4fbb
Drop 'transform', and remove 'inplace' transformations.
tomchristie Jan 29, 2018
30e4cb1
Merge branch 'master' into remove-transform
tomchristie Jan 30, 2018
b9f9dd7
Drop action= and encoding= parameters on client, in favor of override
tomchristie Jan 30, 2018
4fb5e88
Drop HTTPTransport 'credentials' in favor of 'auth' 8000
tomchristie Jan 30, 2018
b0eb95c
Drop HTTP request_callback and response_callback in favor of custom s…
tomchristie Jan 30, 2018
ad00b0a
Drop unused import
tomchristie Jan 30, 2018
15dcdc9
Removing data from documents. Drop 'Array'.
tomchristie Jan 30, 2018
f3c8dde
Drop CallbackAdapater. We don't use it anywhere. Could later farm it …
tomchristie Jan 31, 2018
7d06d93
Drop DomainCredentials, now that we have proper auth classes
tomchristie Jan 31, 2018
ced53cf
Refactor to use session.request
tomchristie Jan 31, 2018
93946cd
Drop unneccessary default parameters
tomchristie Jan 31, 2018
e99f71b
Move _guess_extension out of utils and into codes/download
tomchristie Jan 31, 2018
61d4198
Drop 'Document.clone'
tomchristie Feb 13, 2018
bc6aa9e
Add typesys. Add OpenAPI, JSONSchema.
tomchristie Feb 14, 2018
df86966
.errors always a classmethod
tomchristie Feb 14, 2018
f106bd0
Create absolute URLs for Links from OpenAPI
tomchristie Feb 14, 2018
6b3296a
Drop coreschema
tomchristie Feb 14, 2018
8644689
Ordered schema representations. Support OpenAPI encoding.
tomchristie Feb 14, 2018
325d032
Include yaml in requirements
tomchristie Feb 14, 2018
5984a33
Drop coreschema
tomchristie Feb 14, 2018
9444bc0
Preserve ordering of OpenAPI 'paths' across python versions
tomchristie Feb 14, 2018
b3fa5c2
Default to JSON-flavoured OpenAPI
tomchristie Feb 15, 2018
235f50e
Schemas in tests should be bytestrings
tomchristie Feb 15, 2018
dc4edea
Ensure OpenAPI.encode returns bytestrings
tomchristie Feb 15, 2018
c85818c
dict is ordered in Python 3.6
tomchristie Feb 15, 2018
566abbe
Force ordering of document using in test case
tomchristie Feb 15, 2018
6530dc2
Enforced ordering in Object
tomchristie Feb 20, 2018
09518cd
Drop commented-out YAML code
tomchristie Feb 20, 2018
73c5015
Drop itypes from transports/codecs/client
tomchristie Feb 20, 2018
2d6e0bc
Drop BaseCodec dump/load/supports
tomchristie Feb 20, 2018
48784f4
Add document.version
tomchristie Feb 20, 2018
5e19106
Drop itypes from Error
tomchristie Feb 20, 2018
d1c006f
Drop itypes from Link
tomchristie Feb 20, 2018
b52553e
Drop itypes
tomchristie Feb 20, 2018
b1e3418
Drop client.reload
tomchristie Feb 20, 2018
7b0cf7d
_to_immutable -> _to_objects
tomchristie Feb 20, 2018
e663b9f
Drop reload from tests
tomchristie Feb 20, 2018
f09ca74
'enum' defined on types
tomchristie Feb 20, 2018
93482e9
Add openapi codec to setup
tomchristie Feb 20, 2018
54199e3
Add Field.title
tomchristie Feb 20, 2018
8c1748e
Use Link.method. Put .action towards deprecation.
tomchristie Feb 20, 2018
ae79ef5
Plain old classes for typesys
tomchristie Feb 21, 2018
01a0a51
Add typesys.Ref
tomchristie Feb 21, 2018
46a9559
assert types on __init__
tomchristie Feb 21, 2018
f772992
Tests and refinements to typesys
tomchristie Feb 21, 2018
a50e0e3
exact_items validation for Ar 8000 ray
tomchristie Feb 21, 2018
b56b1d6
Add allow_null to typesys
tomchristie Feb 21, 2018
c58ad81
Work on JSON Schema and typesys
tomchristie Mar 1, 2018
15f24dc
Work on Union and JSONSchema
tomchristie Mar 1, 2018
cb8e273
Cleanups on typesys
tomchristie Mar 1, 2018
f19c680
Uniqueness checking always that always uses set()
tomchristie Mar 5, 2018
a87f66a
Add Section, Add Link.id
tomchristie Mar 5, 2018
382eef8
Slugify tag names to get section ids
tomchristie Mar 5, 2018
4a5993a
Add path_links and query_links to Section
tomchristie Mar 6, 2018
5e3de6c
Add path_fields and query_fields to Link
tomchristie Mar 6, 2018
1d7a121
Tweak
tomchristie Mar 6, 2018
58ec296
Fix 'security' in OpenAPI
tomchristie Mar 6, 2018
947e03b
If no operationId then use summary for Link.id
tomchristie Mar 6, 2018
7486932
Building out OpenAPI v3 spec
tomchristie Mar 6, 2018
69a5a69
First pass at parsing OpenAPI requestBody schemas
tomchristie Mar 6, 2018
3a793b9
Add initial requestBody schema support
tomchristie Mar 6, 2018
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
Prev Previous commit
Next Next commit
assert types on __init__
  • Loading branch information
tomchristie committed Feb 21, 2018
commit 46a95595a2a0d5b6c7bcbe27d1659d576a801d74
67 changes: 60 additions & 7 deletions coreapi/typesys.py
8000 4F71
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from coreapi.compat import dict_type, string_types
import re
# from typing import Any, Dict, List, Optional, Tuple, Union, overload # noqa


# TODO: Error on unknown attributes
Expand All @@ -17,18 +16,30 @@

class ValidationError(Exception):
def __init__(self, detail):
8000 assert isinstance(detail, (string_types, dict))
self.detail = detail
super(ValidationError, self).__init__(detail)


class NoDefault(object):
pass


class Validator(object):
errors = {}

def __init__(self, title='', description='', default=None, definitions=None):
def __init__(self, title='', description='', default=NoDefault, definitions=None):
definitions = {} if (definitions is None) else dict_type(definitions)

assert isinstance(title, string_types)
assert isinstance(description, string_types)
assert all(isinstance(k, string_types) for k in definitions.keys())
assert all(isinstance(v, Validator) for v in definitions.values())

self.title = title
self.description = description
self.default = default
self.definitions = {} if (definitions is None) else definitions
self.definitions = definitions

def validate(value, definitions=None):
raise NotImplementedError()
Expand All @@ -40,6 +51,9 @@ def error(self, code):
def error_message(self, code):
return self.errors[code].format(**self.__dict__)

def has_default(self):
return self.default is not NoDefault


class String(Validator):
errors = {
Expand All @@ -55,6 +69,13 @@ class String(Validator):

def __init__(self, max_length=None, min_length=None, pattern=None, enum=None, format=None, **kwargs):
super(String, self).__init__(**kwargs)

assert max_length is None or isinstance(max_length, int)
assert min_length is None or isinstance(min_length, int)
assert pattern is None or isinstance(pattern, string_types)
assert enum is None or isinstance(enum, list) and all([isinstance(i, string_types) for i in enum])
assert format is None or isinstance(format, string_types)

self.max_length = max_length
self.min_length = min_length
self.pattern = pattern
Expand Down Expand Up @@ -104,6 +125,15 @@ class NumericType(Validator):

def __init__(self, minimum=None, maximum=None, exclusive_minimum=False, exclusive_maximum=False, multiple_of=None, enum=None, format=None, **kwargs):
super(NumericType, self).__init__(**kwargs)

assert minimum is None or isinstance(minimum, self.numeric_type)
assert maximum is None or isinstance(maximum, self.numeric_type)
assert isinstance(exclusive_minimum, bool)
assert isinstance(exclusive_maximum, bool)
assert multiple_of is None or isinstance(multiple_of, self.numeric_type)
assert enum is None or isinstance(enum, list) and all([isinstance(i, string_types) for i in enum])
assert format is None or isinstance(format, string_types)

self.minimum = minimum
self.maximum = maximum
self.exclusive_minimum = exclusive_minimum
Expand Down Expand Up @@ -189,10 +219,21 @@ class Object(Validator):

def __init__(self, properties=None, pattern_properties=None, additional_properties=None, required=None, **kwargs):
super(Object, self).__init__(**kwargs)
self.properties = {} if (properties is None) else dict_type(properties)
self.pattern_properties = {} if (pattern_properties is None) else dict_type(pattern_properties)

properties = {} if (properties is None) else dict_type(properties)
pattern_properties = {} if (pattern_properties is None) else dict_type(pattern_properties)
required = list(required) if isinstance(required, (list, tuple)) else required
required = [] if (required is None) else required

assert all(isinstance(k, string_types) for k in properties.keys())
assert all(isinstance(v, Validator) for v in properties.values())
assert all(isinstance(k, string_types) for k in pattern_properties.keys())
assert all(isinstance(v, Validator) for v in pattern_properties.values())

self.properties = properties
self.pattern_properties = pattern_properties
self.additional_properties = additional_properties
self.required = [] if (required is None) else required
self.required = required

def validate(self, value, definitions=None):
if definitions is None:
Expand Down Expand Up @@ -260,6 +301,15 @@ class Array(Validator):

def __init__(self, items=None, additional_items=None, min_items=None, max_items=None, unique_items=False, **kwargs):
super(Array, self).__init__(**kwargs)

items = list(items) if isinstance(items, (list, tuple)) else items

assert items is None or isinstance(items, Validator) or isinstance(items, list) and all(isinstance(i, Validator) for i in items)
assert additional_items is None or isinstance(additional_items, (bool, Validator))
assert min_items is None or isinstance(min_items, int)
assert max_items is None or isinstance(max_items, int)
assert isinstance(unique_items, bool)

self.items = items
self.additional_items = additional_items
self.min_items = min_items
Expand All @@ -280,7 +330,7 @@ def validate(self, value, definitions=None):
if isinstance(self.items, list) and len(self.items) > 1:
if len(value) < len(self.items):
self.error('min_items')
elif len(value) > len(self.items) and not self.additional_items:
elif len(value) > len(self.items) and (self.additional_items is False):
self.error('max_items')

if self.min_items is not None and len(value) < self.min_items:
Expand All @@ -298,6 +348,8 @@ def validate(self, value, definitions=None):
if isinstance(self.items, list):
if pos < len(self.items):
item = self.items[pos].validate(item, definitions=definitions)
elif isinstance(self.additional_items, Validator):
item = self.additional_items.validate(item, definitions=definitions)
elif self.items is not None:
item = self.items.validate(item, definitions=definitions)

Expand Down Expand Up @@ -326,6 +378,7 @@ def validate(self, value, definitions=None):
class Ref(Validator):
def __init__(self, ref='', **kwargs):
super(Ref, self).__init__(**kwargs)
assert isinstance(ref, string_types)
self.ref = ref

def validate(self, value, definitions=None):
Expand Down
0