Skip to content
This repository was archived by the owner on Mar 18, 2019. It is now read-only.
Merged
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 .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
language: python
cache: pip

python:
- "2.7"
Expand Down
2 changes: 1 addition & 1 deletion coreapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from coreapi.document import Array, Document, Link, Object, Error, Field


__version__ = '2.1.1'
__version__ = '2.2.0'
__all__ = [
'Array', 'Document', 'Link', 'Object', 'Error', 'Field',
'Client',
Expand Down
8 changes: 1 addition & 7 deletions coreapi/codecs/corejson.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,6 @@ def _document_to_primative(node, base_url=None):
ret['required'] = node.required
if node.location:
ret['location'] = node.location
if node.type:
ret['type'] = node.type
if node.description:
ret['description'] = node.description
return ret

elif isinstance(node, Object):
Expand Down Expand Up @@ -217,9 +213,7 @@ def _primative_to_document(data, base_url=None):
name=_get_string(item, 'name'),
required=_get_bool(item, 'required'),
location=_get_string(item, 'location'),
type=_get_string(item, 'type'),
description=_get_string(item, 'description'),
example=item.get('example')
schema=item.get('schema', None)
)
for item in fields if isinstance(item, dict)
]
Expand Down
4 changes: 2 additions & 2 deletions coreapi/codecs/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ def _to_repr(node):
args += ', required=True'
if node.location:
args += ', location=%s' % repr(node.location)
if node.description:
args += ', description=%s' % repr(node.description)
if node.schema:
args += ', schema=%s' % repr(node.schema)
return 'Field(%s)' % args

return repr(node)
Expand Down
16 changes: 12 additions & 4 deletions coreapi/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,26 @@ def _str(node):
def _key_sorting(item):
"""
Document and Object sorting.
Regular attributes sorted alphabetically, then links sorted alphabetically.
Regular attributes sorted alphabetically.
Links are sorted based on their URL and action.
"""
key, value = item
if isinstance(value, Link):
return (1, key)
action_priority = {
'get': 0,
'post': 1,
'put': 2,
'patch': 3,
'delete': 4
}.get(value.action, 5)
return (1, (value.url, action_priority))
return (0, key)


# The field class, as used by Link objects:

Field = namedtuple('Field', ['name', 'required', 'location', 'type', 'description', 'example'])
Field.__new__.__defaults__ = (False, '', '', '', None)
Field = namedtuple('Field', ['name', 'required', 'location', 'schema'])
Field.__new__.__defaults__ = (False, '', None)


# The Core API primatives:
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Package requirements
coreschema
itypes
requests
uritemplate
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def get_package_data(package):
packages=get_packages('coreapi'),
package_data=get_package_data('coreapi'),
install_requires=[
'coreschema',
'requests',
'itypes',
'uritemplate'
Expand Down