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

Commit 4d187b7

Browse files
authored
Merge pull request #116 from core-api/add-schemas
Add schemas, using `coreschema`
2 parents 59af885 + c391e62 commit 4d187b7

File tree

7 files changed

+19
-14
lines changed

7 files changed

+19
-14
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
language: python
2+
cache: pip
23

34
python:
45
- "2.7"

coreapi/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from coreapi.document import Array, Document, Link, Object, Error, Field
55

66

7-
__version__ = '2.1.1'
7+
__version__ = '2.2.0'
88
__all__ = [
99
'Array', 'Document', 'Link', 'Object', 'Error', 'Field',
1010
'Client',

coreapi/codecs/corejson.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,6 @@ def _document_to_primative(node, base_url=None):
156156
ret['required'] = node.required
157157
if node.location:
158158
ret['location'] = node.location
159-
if node.type:
160-
ret['type'] = node.type
161-
if node.description:
162-
ret['description'] = node.description
163159
return ret
164160

165161
elif isinstance(node, Object):
@@ -217,9 +213,7 @@ def _primative_to_document(data, base_url=None):
217213
name=_get_string(item, 'name'),
218214
required=_get_bool(item, 'required'),
219215
location=_get_string(item, 'location'),
220-
type=_get_string(item, 'type'),
221-
description=_get_string(item, 'description'),
222-
example=item.get('example')
216+
schema=item.get('schema', None)
223217
)
224218
for item in fields if isinstance(item, dict)
225219
]

coreapi/codecs/python.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ def _to_repr(node):
5959
args += ', required=True'
6060
if node.location:
6161
args += ', location=%s' % repr(node.location)
62-
if node.description:
63-
args += ', description=%s' % repr(node.description)
62+
if node.schema:
63+
args += ', schema=%s' % repr(node.schema)
6464
return 'Field(%s)' % args
6565

6666
return repr(node)

coreapi/document.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,26 @@ def _str(node):
2626
def _key_sorting(item):
2727
"""
2828
Document and Object sorting.
29-
Regular attributes sorted alphabetically, then links sorted alphabetically.
29+
Regular attributes sorted alphabetically.
30+
Links are sorted based on their URL and action.
3031
"""
3132
key, value = item
3233
if isinstance(value, Link):
33-
return (1, key)
34+
action_priority = {
35+
'get': 0,
36+
'post': 1,
37+
'put': 2,
38+
'patch': 3,
39+
'delete': 4
40+
}.get(value.action, 5)
41+
return (1, (value.url, action_priority))
3442
return (0, key)
3543

3644

3745
# The field class, as used by Link objects:
3846

39-
Field = namedtuple('Field', ['name', 'required', 'location', 'type', 'description', 'example'])
40-
Field.__new__.__defaults__ = (False, '', '', '', None)
47+
Field = namedtuple('Field', ['name', 'required', 'location', 'schema'])
48+
Field.__new__.__defaults__ = (False, '', None)
4149

4250

4351
# The Core API primatives:

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Package requirements
2+
coreschema
23
itypes
34
requests
45
uritemplate

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def get_package_data(package):
6363
packages=get_packages('coreapi'),
6464
package_data=get_package_data('coreapi'),
6565
install_requires=[
66+
'coreschema',
6667
'requests',
6768
'itypes',
6869
'uritemplate'

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy