This commit is contained in:
Carlton Gibson 2018-04-04 14:20:23 +00:00 committed by GitHub
commit aa3c13f1e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 137 additions and 129 deletions

View File

@ -0,0 +1,17 @@
attrs==17.4.0
certifi==2018.1.18
chardet==3.0.4
-e git+https://github.com/core-api/python-client.git@b56b1d64fcebd765d458f546b3c38762fd65f042#egg=coreapi
coverage==4.5.1
Django==2.0.2
idna==2.6
pluggy==0.6.0
py==1.5.2
pytest==3.4.0
pytest-cov==2.5.1
pytest-django==3.1.2
pytz==2018.3
requests==2.18.4
six==1.11.0
uritemplate==3.0.0
urllib3==1.22

View File

@ -4,5 +4,4 @@ psycopg2==2.7.3
markdown==2.6.4 markdown==2.6.4
django-guardian==1.4.9 django-guardian==1.4.9
django-filter==1.1.0 django-filter==1.1.0
coreapi==2.3.1 -e git+https://github.com/core-api/python-client.git@b56b1d64fcebd765d458f546b3c38762fd65f042#egg=coreapi
coreschema==0.0.4

View File

@ -1,5 +1,5 @@
import coreapi import coreapi
import coreschema from coreapi import typesys
from rest_framework import parsers, renderers from rest_framework import parsers, renderers
from rest_framework.authtoken.models import Token from rest_framework.authtoken.models import Token
from rest_framework.authtoken.serializers import AuthTokenSerializer from rest_framework.authtoken.serializers import AuthTokenSerializer
@ -20,7 +20,7 @@ class ObtainAuthToken(APIView):
name="username", name="username",
required=True, required=True,
location='form', location='form',
schema=coreschema.String( schema=typesys.String(
title="Username", title="Username",
description="Valid username for authentication", description="Valid username for authentication",
), ),
@ -29,7 +29,7 @@ class ObtainAuthToken(APIView):
name="password", name="password",
required=True, required=True,
location='form', location='form',
schema=coreschema.String( schema=typesys.String(
title="Password", title="Password",
description="Valid password for authentication", description="Valid password for authentication",
), ),

View File

@ -113,17 +113,11 @@ except ImportError:
try: try:
import coreapi import coreapi
import uritemplate import uritemplate
from coreapi import typesys
except ImportError: except ImportError:
coreapi = None coreapi = None
uritemplate = None uritemplate = None
typesys = None
# coreschema is optional
try:
import coreschema
except ImportError:
coreschema = None
# django-crispy-forms is optional # django-crispy-forms is optional
try: try:
@ -256,7 +250,7 @@ except ImportError:
try: try:
from django.urls import include, path, re_path, register_converter # noqa from django.urls import include, path, re_path, register_converter # noqa
except ImportError: except ImportError:
from django.conf.urls import include, url # noqa from django.conf.urls import include, url # noqa
path = None path = None
register_converter = None register_converter = None
re_path = url re_path = url

View File

@ -16,7 +16,7 @@ from django.utils import six
from django.utils.encoding import force_text from django.utils.encoding import force_text
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from rest_framework.compat import coreapi, coreschema, distinct, guardian from rest_framework.compat import coreapi, distinct, guardian, typesys
from rest_framework.settings import api_settings from rest_framework.settings import api_settings
@ -33,7 +33,6 @@ class BaseFilterBackend(object):
def get_schema_fields(self, view): def get_schema_fields(self, view):
assert coreapi is not None, 'coreapi must be installed to use `get_schema_fields()`' assert coreapi is not None, 'coreapi must be installed to use `get_schema_fields()`'
assert coreschema is not None, 'coreschema must be installed to use `get_schema_fields()`'
return [] return []
@ -131,13 +130,12 @@ class SearchFilter(BaseFilterBackend):
def get_schema_fields(self, view): def get_schema_fields(self, view):
assert coreapi is not None, 'coreapi must be installed to use `get_schema_fields()`' assert coreapi is not None, 'coreapi must be installed to use `get_schema_fields()`'
assert coreschema is not None, 'coreschema must be installed to use `get_schema_fields()`'
return [ return [
coreapi.Field( coreapi.Field(
name=self.search_param, name=self.search_param,
required=False, required=False,
location='query', location='query',
schema=coreschema.String( schema=typesys.String(
title=force_text(self.search_title), title=force_text(self.search_title),
description=force_text(self.search_description) description=force_text(self.search_description)
) )
@ -262,13 +260,12 @@ class OrderingFilter(BaseFilterBackend):
def get_schema_fields(self, view): def get_schema_fields(self, view):
assert coreapi is not None, 'coreapi must be installed to use `get_schema_fields()`' assert coreapi is not None, 'coreapi must be installed to use `get_schema_fields()`'
assert coreschema is not None, 'coreschema must be installed to use `get_schema_fields()`'
return [ return [
coreapi.Field( coreapi.Field(
name=self.ordering_param, name=self.ordering_param,
required=False, required=False,
location='query', location='query',
schema=coreschema.String( schema=typesys.String(
title=force_text(self.ordering_title), title=force_text(self.ordering_title),
description=force_text(self.ordering_description) description=force_text(self.ordering_description)
) )

View File

@ -16,7 +16,7 @@ from django.utils.encoding import force_text
from django.utils.six.moves.urllib import parse as urlparse from django.utils.six.moves.urllib import parse as urlparse
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from rest_framework.compat import coreapi, coreschema from rest_framework.compat import coreapi, typesys
from rest_framework.exceptions import NotFound from rest_framework.exceptions import NotFound
from rest_framework.response import Response from rest_framework.response import Response
from rest_framework.settings import api_settings from rest_framework.settings import api_settings
@ -279,13 +279,12 @@ class PageNumberPagination(BasePagination):
def get_schema_fields(self, view): def get_schema_fields(self, view):
assert coreapi is not None, 'coreapi must be installed to use `get_schema_fields()`' assert coreapi is not None, 'coreapi must be installed to use `get_schema_fields()`'
assert coreschema is not None, 'coreschema must be installed to use `get_schema_fields()`'
fields = [ fields = [
coreapi.Field( coreapi.Field(
name=self.page_query_param, name=self.page_query_param,
required=False, required=False,
location='query', location='query',
schema=coreschema.Integer( schema=typesys.Integer(
title='Page', title='Page',
description=force_text(self.page_query_description) description=force_text(self.page_query_description)
) )
@ -297,7 +296,7 @@ class PageNumberPagination(BasePagination):
name=self.page_size_query_param, name=self.page_size_query_param,
required=False, required=False,
location='query', location='query',
schema=coreschema.Integer( schema=typesys.Integer(
title='Page size', title='Page size',
description=force_text(self.page_size_query_description) description=force_text(self.page_size_query_description)
) )
@ -436,13 +435,12 @@ class LimitOffsetPagination(BasePagination):
def get_schema_fields(self, view): def get_schema_fields(self, view):
assert coreapi is not None, 'coreapi must be installed to use `get_schema_fields()`' assert coreapi is not None, 'coreapi must be installed to use `get_schema_fields()`'
assert coreschema is not None, 'coreschema must be installed to use `get_schema_fields()`'
return [ return [
coreapi.Field( coreapi.Field(
name=self.limit_query_param, name=self.limit_query_param,
required=False, required=False,
location='query', location='query',
schema=coreschema.Integer( schema=typesys.Integer(
title='Limit', title='Limit',
description=force_text(self.limit_query_description) description=force_text(self.limit_query_description)
) )
@ -451,7 +449,7 @@ class LimitOffsetPagination(BasePagination):
name=self.offset_query_param, name=self.offset_query_param,
required=False, required=False,
location='query', location='query',
schema=coreschema.Integer( schema=typesys.Integer(
title='Offset', title='Offset',
description=force_text(self.offset_query_description) description=force_text(self.offset_query_description)
) )
@ -796,13 +794,12 @@ class CursorPagination(BasePagination):
def get_schema_fields(self, view): def get_schema_fields(self, view):
assert coreapi is not None, 'coreapi must be installed to use `get_schema_fields()`' assert coreapi is not None, 'coreapi must be installed to use `get_schema_fields()`'
assert coreschema is not None, 'coreschema must be installed to use `get_schema_fields()`'
fields = [ fields = [
coreapi.Field( coreapi.Field(
name=self.cursor_query_param, name=self.cursor_query_param,
required=False, required=False,
location='query', location='query',
schema=coreschema.String( schema=typesys.String(
title='Cursor', title='Cursor',
description=force_text(self.cursor_query_description) description=force_text(self.cursor_query_description)
) )
@ -814,7 +811,7 @@ class CursorPagination(BasePagination):
name=self.page_size_query_param, name=self.page_size_query_param,
required=False, required=False,
location='query', location='query',
schema=coreschema.Integer( schema=typesys.Integer(
title='Page size', title='Page size',
description=force_text(self.page_size_query_description) description=force_text(self.page_size_query_description)
) )

View File

@ -897,4 +897,4 @@ class CoreJSONRenderer(BaseRenderer):
def render(self, data, media_type=None, renderer_context=None): def render(self, data, media_type=None, renderer_context=None):
indent = bool(renderer_context.get('indent', 0)) indent = bool(renderer_context.get('indent', 0))
codec = coreapi.codecs.CoreJSONCodec() codec = coreapi.codecs.CoreJSONCodec()
return codec.dump(data, indent=indent) return codec.encode(data, indent=indent)

View File

@ -16,7 +16,7 @@ from django.utils import six
from rest_framework import exceptions from rest_framework import exceptions
from rest_framework.compat import ( from rest_framework.compat import (
URLPattern, URLResolver, coreapi, coreschema, get_original_route URLPattern, URLResolver, coreapi, get_original_route
) )
from rest_framework.request import clone_request from rest_framework.request import clone_request
from rest_framework.settings import api_settings from rest_framework.settings import api_settings
@ -260,7 +260,6 @@ class SchemaGenerator(object):
def __init__(self, title=None, url=None, description=None, patterns=None, urlconf=None): def __init__(self, title=None, url=None, description=None, patterns=None, urlconf=None):
assert coreapi, '`coreapi` must be installed for schema support.' assert coreapi, '`coreapi` must be installed for schema support.'
assert coreschema, '`coreschema` must be installed for schema support.'
if url and not url.endswith('/'): if url and not url.endswith('/'):
url += '/' url += '/'

View File

@ -14,7 +14,7 @@ from django.utils.six.moves.urllib import parse as urlparse
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from rest_framework import exceptions, serializers from rest_framework import exceptions, serializers
from rest_framework.compat import coreapi, coreschema, uritemplate from rest_framework.compat import coreapi, typesys, uritemplate
from rest_framework.settings import api_settings from rest_framework.settings import api_settings
from rest_framework.utils import formatting from rest_framework.utils import formatting
@ -29,18 +29,18 @@ def field_to_schema(field):
if isinstance(field, (serializers.ListSerializer, serializers.ListField)): if isinstance(field, (serializers.ListSerializer, serializers.ListField)):
child_schema = field_to_schema(field.child) child_schema = field_to_schema(field.child)
return coreschema.Array( return typesys.Array(
items=child_schema, items=child_schema,
title=title, title=title,
description=description description=description
) )
elif isinstance(field, serializers.DictField): elif isinstance(field, serializers.DictField):
return coreschema.Object( return typesys.Object(
title=title, title=title,
description=description description=description
) )
elif isinstance(field, serializers.Serializer): elif isinstance(field, serializers.Serializer):
return coreschema.Object( return typesys.Object(
properties=OrderedDict([ properties=OrderedDict([
(key, field_to_schema(value)) (key, field_to_schema(value))
for key, value for key, value
@ -50,59 +50,59 @@ def field_to_schema(field):
description=description description=description
) )
elif isinstance(field, serializers.ManyRelatedField): elif isinstance(field, serializers.ManyRelatedField):
return coreschema.Array( return typesys.Array(
items=coreschema.String(), items=typesys.String(),
title=title, title=title,
description=description description=description
) )
elif isinstance(field, serializers.PrimaryKeyRelatedField): elif isinstance(field, serializers.PrimaryKeyRelatedField):
schema_cls = coreschema.String schema_cls = typesys.String
model = getattr(field.queryset, 'model', None) model = getattr(field.queryset, 'model', None)
if model is not None: if model is not None:
model_field = model._meta.pk model_field = model._meta.pk
if isinstance(model_field, models.AutoField): if isinstance(model_field, models.AutoField):
schema_cls = coreschema.Integer schema_cls = typesys.Integer
return schema_cls(title=title, description=description) return schema_cls(title=title, description=description)
elif isinstance(field, serializers.RelatedField): elif isinstance(field, serializers.RelatedField):
return coreschema.String(title=title, description=description) return typesys.String(title=title, description=description)
elif isinstance(field, serializers.MultipleChoiceField): elif isinstance(field, serializers.MultipleChoiceField):
return coreschema.Array( return typesys.Array(
items=coreschema.Enum(enum=list(field.choices)), items=typesys.Enum(enum=list(field.choices)),
title=title, title=title,
description=description description=description
) )
elif isinstance(field, serializers.ChoiceField): elif isinstance(field, serializers.ChoiceField):
return coreschema.Enum( return typesys.Enum(
enum=list(field.choices), enum=list(field.choices),
title=title, title=title,
description=description description=description
) )
elif isinstance(field, serializers.BooleanField): elif isinstance(field, serializers.BooleanField):
return coreschema.Boolean(title=title, description=description) return typesys.Boolean(title=title, description=description)
elif isinstance(field, (serializers.DecimalField, serializers.FloatField)): elif isinstance(field, (serializers.DecimalField, serializers.FloatField)):
return coreschema.Number(title=title, description=description) return typesys.Number(title=title, description=description)
elif isinstance(field, serializers.IntegerField): elif isinstance(field, serializers.IntegerField):
return coreschema.Integer(title=title, description=description) return typesys.Integer(title=title, description=description)
elif isinstance(field, serializers.DateField): elif isinstance(field, serializers.DateField):
return coreschema.String( return typesys.String(
title=title, title=title,
description=description, description=description,
format='date' format='date'
) )
elif isinstance(field, serializers.DateTimeField): elif isinstance(field, serializers.DateTimeField):
return coreschema.String( return typesys.String(
title=title, title=title,
description=description, description=description,
format='date-time' format='date-time'
) )
if field.style.get('base_template') == 'textarea.html': if field.style.get('base_template') == 'textarea.html':
return coreschema.String( return typesys.String(
title=title, title=title,
description=description, description=description,
format='textarea' format='textarea'
) )
return coreschema.String(title=title, description=description) return typesys.String(title=title, description=description)
def get_pk_description(model, model_field): def get_pk_description(model, model_field):
@ -266,7 +266,7 @@ class AutoSchema(ViewInspector):
for variable in uritemplate.variables(path): for variable in uritemplate.variables(path):
title = '' title = ''
description = '' description = ''
schema_cls = coreschema.String schema_cls = typesys.String
kwargs = {} kwargs = {}
if model is not None: if model is not None:
# Attempt to infer a field description if possible. # Attempt to infer a field description if possible.
@ -286,7 +286,7 @@ class AutoSchema(ViewInspector):
if hasattr(view, 'lookup_value_regex') and view.lookup_field == variable: if hasattr(view, 'lookup_value_regex') and view.lookup_field == variable:
kwargs['pattern'] = view.lookup_value_regex kwargs['pattern'] = view.lookup_value_regex
elif isinstance(model_field, models.AutoField): elif isinstance(model_field, models.AutoField):
schema_cls = coreschema.Integer schema_cls = typesys.Integer
field = coreapi.Field( field = coreapi.Field(
name=variable, name=variable,
@ -326,7 +326,7 @@ class AutoSchema(ViewInspector):
name='data', name='data',
location='body', location='body',
required=True, required=True,
schema=coreschema.Array() schema=typesys.Array()
) )
] ]

View File

@ -49,11 +49,16 @@ def with_location(fields, location):
] ]
# TOOD: Where to pull these helpers?
def render_to_form(schema):
assert False, "Can't rely on coreschema encodings here."
@register.simple_tag @register.simple_tag
def form_for_link(link): def form_for_link(link):
import coreschema from coreapi import typesys
properties = OrderedDict([ properties = OrderedDict([
(field.name, field.schema or coreschema.String()) (field.name, field.schema or typesys.String())
for field in link.fields for field in link.fields
]) ])
required = [ required = [
@ -61,8 +66,8 @@ def form_for_link(link):
for field in link.fields for field in link.fields
if field.required if field.required
] ]
schema = coreschema.Object(properties=properties, required=required) schema = typesys.Object(properties=properties, required=required)
return mark_safe(coreschema.render_to_form(schema)) return mark_safe(render_to_form(schema))
@register.simple_tag @register.simple_tag

View File

@ -8,7 +8,7 @@ from django.conf.urls import url
from django.http import HttpResponse from django.http import HttpResponse
from django.test import override_settings from django.test import override_settings
from rest_framework.compat import coreapi, coreschema from rest_framework.compat import coreapi, typesys
from rest_framework.parsers import FileUploadParser from rest_framework.parsers import FileUploadParser
from rest_framework.renderers import CoreJSONRenderer from rest_framework.renderers import CoreJSONRenderer
from rest_framework.response import Response from rest_framework.response import Response
@ -25,7 +25,7 @@ def get_schema():
'headers': coreapi.Link('/headers/'), 'headers': coreapi.Link('/headers/'),
'location': { 'location': {
'query': coreapi.Link('/example/', fields=[ 'query': coreapi.Link('/example/', fields=[
coreapi.Field(name='example', schema=coreschema.String(description='example field')) coreapi.Field(name='example', schema=typesys.String(description='example field'))
]), ]),
'form': coreapi.Link('/example/', action='post', fields=[ 'form': coreapi.Link('/example/', action='post', fields=[
coreapi.Field(name='example') coreapi.Field(name='example')

View File

@ -9,7 +9,7 @@ from django.test import TestCase, override_settings
from rest_framework import ( from rest_framework import (
filters, generics, pagination, permissions, serializers filters, generics, pagination, permissions, serializers
) )
from rest_framework.compat import coreapi, coreschema, get_regex_pattern, path from rest_framework.compat import coreapi, get_regex_pattern, path, typesys
from rest_framework.decorators import action, api_view, schema from rest_framework.decorators import action, api_view, schema
from rest_framework.request import Request from rest_framework.request import Request
from rest_framework.routers import DefaultRouter, SimpleRouter from rest_framework.routers import DefaultRouter, SimpleRouter
@ -134,9 +134,9 @@ class TestRouterGeneratedSchema(TestCase):
url='/example/', url='/example/',
action='get', action='get',
fields=[ fields=[
coreapi.Field('page', required=False, location='query', schema=coreschema.Integer(title='Page', description='A page number within the paginated result set.')), coreapi.Field('page', required=False, location='query', schema=typesys.Integer(title='Page', description='A page number within the paginated result set.')),
coreapi.Field('page_size', required=False, location='query', schema=coreschema.Integer(title='Page size', description='Number of results to return per page.')), coreapi.Field('page_size', required=False, location='query', schema=typesys.Integer(title='Page size', description='Number of results to return per page.')),
coreapi.Field('ordering', required=False, location='query', schema=coreschema.String(title='Ordering', description='Which field to use when ordering the results.')) coreapi.Field('ordering', required=False, location='query', schema=typesys.String(title='Ordering', description='Which field to use when ordering the results.'))
] ]
), ),
'custom_list_action': coreapi.Link( 'custom_list_action': coreapi.Link(
@ -153,8 +153,8 @@ class TestRouterGeneratedSchema(TestCase):
url='/example/{id}/', url='/example/{id}/',
action='get', action='get',
fields=[ fields=[
coreapi.Field('id', required=True, location='path', schema=coreschema.String()), coreapi.Field('id', required=True, location='path', schema=typesys.String()),
coreapi.Field('ordering', required=False, location='query', schema=coreschema.String(title='Ordering', description='Which field to use when ordering the results.')) coreapi.Field('ordering', required=False, location='query', schema=typesys.String(title='Ordering', description='Which field to use when ordering the results.'))
] ]
) )
} }
@ -176,9 +176,9 @@ class TestRouterGeneratedSchema(TestCase):
url='/example/', url='/example/',
action='get', action='get',
fields=[ fields=[
coreapi.Field('page', required=False, location='query', schema=coreschema.Integer(title='Page', description='A page number within the paginated result set.')), coreapi.Field('page', required=False, location='query', schema=typesys.Integer(title='Page', description='A page number within the paginated result set.')),
coreapi.Field('page_size', required=False, location='query', schema=coreschema.Integer(title='Page size', description='Number of results to return per page.')), coreapi.Field('page_size', required=False, location='query', schema=typesys.Integer(title='Page size', description='Number of results to return per page.')),
coreapi.Field('ordering', required=False, location='query', schema=coreschema.String(title='Ordering', description='Which field to use when ordering the results.')) coreapi.Field('ordering', required=False, location='query', schema=typesys.String(title='Ordering', description='Which field to use when ordering the results.'))
] ]
), ),
'create': coreapi.Link( 'create': coreapi.Link(
@ -186,16 +186,16 @@ class TestRouterGeneratedSchema(TestCase):
action='post', action='post',
encoding='application/json', encoding='application/json',
fields=[ fields=[
coreapi.Field('a', required=True, location='form', schema=coreschema.String(title='A', description='A field description')), coreapi.Field('a', required=True, location='form', schema=typesys.String(title='A', description='A field description')),
coreapi.Field('b', required=False, location='form', schema=coreschema.String(title='B')) coreapi.Field('b', required=False, location='form', schema=typesys.String(title='B'))
] ]
), ),
'read': coreapi.Link( 'read': coreapi.Link(
url='/example/{id}/', url='/example/{id}/',
action='get', action='get',
fields=[ fields=[
coreapi.Field('id', required=True, location='path', schema=coreschema.String()), coreapi.Field('id', required=True, location='path', schema=typesys.String()),
coreapi.Field('ordering', required=False, location='query', schema=coreschema.String(title='Ordering', description='Which field to use when ordering the results.')) coreapi.Field('ordering', required=False, location='query', schema=typesys.String(title='Ordering', description='Which field to use when ordering the results.'))
] ]
), ),
'custom_action': coreapi.Link( 'custom_action': coreapi.Link(
@ -204,9 +204,9 @@ class TestRouterGeneratedSchema(TestCase):
encoding='application/json', encoding='application/json',
description='A description of custom action.', description='A description of custom action.',
fields=[ fields=[
coreapi.Field('id', required=True, location='path', schema=coreschema.String()), coreapi.Field('id', required=True, location='path', schema=typesys.String()),
coreapi.Field('c', required=True, location='form', schema=coreschema.String(title='C')), coreapi.Field('c', required=True, location='form', schema=typesys.String(title='C')),
coreapi.Field('d', required=False, location='form', schema=coreschema.String(title='D')), coreapi.Field('d', required=False, location='form', schema=typesys.String(title='D')),
] ]
), ),
'custom_action_with_dict_field': coreapi.Link( 'custom_action_with_dict_field': coreapi.Link(
@ -215,8 +215,8 @@ class TestRouterGeneratedSchema(TestCase):
encoding='application/json', encoding='application/json',
description='A custom action using a dict field in the serializer.', description='A custom action using a dict field in the serializer.',
fields=[ fields=[
coreapi.Field('id', required=True, location='path', schema=coreschema.String()), coreapi.Field('id', required=True, location='path', schema=typesys.String()),
coreapi.Field('a', required=True, location='form', schema=coreschema.Object(title='A')), coreapi.Field('a', required=True, location='form', schema=typesys.Object(title='A')),
] ]
), ),
'custom_action_with_list_fields': coreapi.Link( 'custom_action_with_list_fields': coreapi.Link(
@ -225,9 +225,9 @@ class TestRouterGeneratedSchema(TestCase):
encoding='application/json', encoding='application/json',
description='A custom action using both list field and list serializer in the serializer.', description='A custom action using both list field and list serializer in the serializer.',
fields=[ fields=[
coreapi.Field('id', required=True, location='path', schema=coreschema.String()), coreapi.Field('id', required=True, location='path', schema=typesys.String()),
coreapi.Field('a', required=True, location='form', schema=coreschema.Array(title='A', items=coreschema.Integer())), coreapi.Field('a', required=True, location='form', schema=typesys.Array(title='A', items=typesys.Integer())),
coreapi.Field('b', required=True, location='form', schema=coreschema.Array(title='B', items=coreschema.String())), coreapi.Field('b', required=True, location='form', schema=typesys.Array(title='B', items=typesys.String())),
] ]
), ),
'custom_list_action': coreapi.Link( 'custom_list_action': coreapi.Link(
@ -249,10 +249,10 @@ class TestRouterGeneratedSchema(TestCase):
action='put', action='put',
encoding='application/json', encoding='application/json',
fields=[ fields=[
coreapi.Field('id', required=True, location='path', schema=coreschema.String()), coreapi.Field('id', required=True, location='path', schema=typesys.String()),
coreapi.Field('a', required=True, location='form', schema=coreschema.String(title='A', description=('A field description'))), coreapi.Field('a', required=True, location='form', schema=typesys.String(title='A', description=('A field description'))),
coreapi.Field('b', required=False, location='form', schema=coreschema.String(title='B')), coreapi.Field('b', required=False, location='form', schema=typesys.String(title='B')),
coreapi.Field('ordering', required=False, location='query', schema=coreschema.String(title='Ordering', description='Which field to use when ordering the results.')) coreapi.Field('ordering', required=False, location='query', schema=typesys.String(title='Ordering', description='Which field to use when ordering the results.'))
] ]
), ),
'partial_update': coreapi.Link( 'partial_update': coreapi.Link(
@ -260,18 +260,18 @@ class TestRouterGeneratedSchema(TestCase):
action='patch', action='patch',
encoding='application/json', encoding='application/json',
fields=[ fields=[
coreapi.Field('id', required=True, location='path', schema=coreschema.String()), coreapi.Field('id', required=True, location='path', schema=typesys.String()),
coreapi.Field('a', required=False, location='form', schema=coreschema.String(title='A', description='A field description')), coreapi.Field('a', required=False, location='form', schema=typesys.String(title='A', description='A field description')),
coreapi.Field('b', required=False, location='form', schema=coreschema.String(title='B')), coreapi.Field('b', required=False, location='form', schema=typesys.String(title='B')),
coreapi.Field('ordering', required=False, location='query', schema=coreschema.String(title='Ordering', description='Which field to use when ordering the results.')) coreapi.Field('ordering', required=False, location='query', schema=typesys.String(title='Ordering', description='Which field to use when ordering the results.'))
] ]
), ),
'delete': coreapi.Link( 'delete': coreapi.Link(
url='/example/{id}/', url='/example/{id}/',
action='delete', action='delete',
fields=[ fields=[
coreapi.Field('id', required=True, location='path', schema=coreschema.String()), coreapi.Field('id', required=True, location='path', schema=typesys.String()),
coreapi.Field('ordering', required=False, location='query', schema=coreschema.String(title='Ordering', description='Which field to use when ordering the results.')) coreapi.Field('ordering', required=False, location='query', schema=typesys.String(title='Ordering', description='Which field to use when ordering the results.'))
] ]
) )
} }
@ -362,7 +362,7 @@ class TestSchemaGenerator(TestCase):
url='/example/{id}/', url='/example/{id}/',
action='get', action='get',
fields=[ fields=[
coreapi.Field('id', required=True, location='path', schema=coreschema.String()) coreapi.Field('id', required=True, location='path', schema=typesys.String())
] ]
), ),
'sub': { 'sub': {
@ -370,7 +370,7 @@ class TestSchemaGenerator(TestCase):
url='/example/{id}/sub/', url='/example/{id}/sub/',
action='get', action='get',
fields=[ fields=[
coreapi.Field('id', required=True, location='path', schema=coreschema.String()) coreapi.Field('id', required=True, location='path', schema=typesys.String())
] ]
) )
} }
@ -415,7 +415,7 @@ class TestSchemaGeneratorDjango2(TestCase):
url='/example/{id}/', url='/example/{id}/',
action='get', action='get',
fields=[ fields=[
coreapi.Field('id', required=True, location='path', schema=coreschema.String()) coreapi.Field('id', required=True, location='path', schema=typesys.String())
] ]
), ),
'sub': { 'sub': {
@ -423,7 +423,7 @@ class TestSchemaGeneratorDjango2(TestCase):
url='/example/{id}/sub/', url='/example/{id}/sub/',
action='get', action='get',
fields=[ fields=[
coreapi.Field('id', required=True, location='path', schema=coreschema.String()) coreapi.Field('id', required=True, location='path', schema=typesys.String())
] ]
) )
} }
@ -468,7 +468,7 @@ class TestSchemaGeneratorNotAtRoot(TestCase):
url='/api/v1/example/{id}/', url='/api/v1/example/{id}/',
action='get', action='get',
fields=[ fields=[
coreapi.Field('id', required=True, location='path', schema=coreschema.String()) coreapi.Field('id', required=True, location='path', schema=typesys.String())
] ]
), ),
'sub': { 'sub': {
@ -476,7 +476,7 @@ class TestSchemaGeneratorNotAtRoot(TestCase):
url='/api/v1/example/{id}/sub/', url='/api/v1/example/{id}/sub/',
action='get', action='get',
fields=[ fields=[
coreapi.Field('id', required=True, location='path', schema=coreschema.String()) coreapi.Field('id', required=True, location='path', schema=typesys.String())
] ]
) )
} }
@ -513,9 +513,9 @@ class TestSchemaGeneratorWithMethodLimitedViewSets(TestCase):
url='/example1/', url='/example1/',
action='get', action='get',
fields=[ fields=[
coreapi.Field('page', required=False, location='query', schema=coreschema.Integer(title='Page', description='A page number within the paginated result set.')), coreapi.Field('page', required=False, location='query', schema=typesys.Integer(title='Page', description='A page number within the paginated result set.')),
coreapi.Field('page_size', required=False, location='query', schema=coreschema.Integer(title='Page size', description='Number of results to return per page.')), coreapi.Field('page_size', required=False, location='query', schema=typesys.Integer(title='Page size', description='Number of results to return per page.')),
coreapi.Field('ordering', required=False, location='query', schema=coreschema.String(title='Ordering', description='Which field to use when ordering the results.')) coreapi.Field('ordering', required=False, location='query', schema=typesys.String(title='Ordering', description='Which field to use when ordering the results.'))
] ]
), ),
'custom_list_action': coreapi.Link( 'custom_list_action': coreapi.Link(
@ -532,8 +532,8 @@ class TestSchemaGeneratorWithMethodLimitedViewSets(TestCase):
url='/example1/{id}/', url='/example1/{id}/',
action='get', action='get',
fields=[ fields=[
coreapi.Field('id', required=True, location='path', schema=coreschema.String()), coreapi.Field('id', required=True, location='path', schema=typesys.String()),
coreapi.Field('ordering', required=False, location='query', schema=coreschema.String(title='Ordering', description='Which field to use when ordering the results.')) coreapi.Field('ordering', required=False, location='query', schema=typesys.String(title='Ordering', description='Which field to use when ordering the results.'))
] ]
) )
} }
@ -612,8 +612,8 @@ class TestSchemaGeneratorWithForeignKey(TestCase):
action='post', action='post',
encoding='application/json', encoding='application/json',
fields=[ fields=[
coreapi.Field('name', required=True, location='form', schema=coreschema.String(title='Name')), coreapi.Field('name', required=True, location='form', schema=typesys.String(title='Name')),
coreapi.Field('target', required=True, location='form', schema=coreschema.Integer(description='Target', title='Target')), coreapi.Field('target', required=True, location='form', schema=typesys.Integer(description='Target', title='Target')),
] ]
) )
} }
@ -677,7 +677,7 @@ class TestAutoSchema(TestCase):
"my_field", "my_field",
required=True, required=True,
location="path", location="path",
schema=coreschema.String() schema=typesys.String()
), ),
]) ])
@ -690,7 +690,7 @@ class TestAutoSchema(TestCase):
"my_field", "my_field",
required=False, required=False,
location="path", location="path",
schema=coreschema.String() schema=typesys.String()
), ),
]) ])
@ -706,7 +706,7 @@ class TestAutoSchema(TestCase):
"my_extra_field", "my_extra_field",
required=True, required=True,
location="path", location="path",
schema=coreschema.String() schema=typesys.String()
), ),
]) ])
@ -728,19 +728,19 @@ class TestAutoSchema(TestCase):
"first_field", "first_field",
required=True, required=True,
location="path", location="path",
schema=coreschema.String() schema=typesys.String()
), ),
coreapi.Field( coreapi.Field(
"second_field", "second_field",
required=True, required=True,
location="path", location="path",
schema=coreschema.String() schema=typesys.String()
), ),
coreapi.Field( coreapi.Field(
"third_field", "third_field",
required=True, required=True,
location="path", location="path",
schema=coreschema.String() schema=typesys.String()
), ),
] ]
description = "A test endpoint" description = "A test endpoint"

View File

@ -5,7 +5,7 @@ import unittest
from django.test import TestCase from django.test import TestCase
from rest_framework.compat import coreapi, coreschema from rest_framework.compat import coreapi, typesys
from rest_framework.relations import Hyperlink from rest_framework.relations import Hyperlink
from rest_framework.templatetags import rest_framework from rest_framework.templatetags import rest_framework
from rest_framework.templatetags.rest_framework import ( from rest_framework.templatetags.rest_framework import (
@ -361,14 +361,14 @@ class SchemaLinksTests(TestCase):
url='/users/{id}/', url='/users/{id}/',
action='get', action='get',
fields=[ fields=[
coreapi.Field('id', required=True, location='path', schema=coreschema.String()) coreapi.Field('id', required=True, location='path', schema=typesys.String())
] ]
), ),
'update': coreapi.Link( 'update': coreapi.Link(
url='/users/{id}/', url='/users/{id}/',
action='patch', action='patch',
fields=[ fields=[
coreapi.Field('id', required=True, location='path', schema=coreschema.String()) coreapi.Field('id', required=True, location='path', schema=typesys.String())
] ]
) )
} }
@ -402,21 +402,21 @@ class SchemaLinksTests(TestCase):
url='/users/{id}/', url='/users/{id}/',
action='get', action='get',
fields=[ fields=[
coreapi.Field('id', required=True, location='path', schema=coreschema.String()) coreapi.Field('id', required=True, location='path', schema=typesys.String())
] ]
), ),
'update': coreapi.Link( 'update': coreapi.Link(
url='/users/{id}/', url='/users/{id}/',
action='patch', action='patch',
fields=[ fields=[
coreapi.Field('id', required=True, location='path', schema=coreschema.String()) coreapi.Field('id', required=True, location='path', schema=typesys.String())
] ]
), ),
'friends': coreapi.Link( 'friends': coreapi.Link(
url='/users/{id}/friends', url='/users/{id}/friends',
action='get', action='get',
fields=[ fields=[
coreapi.Field('id', required=True, location='path', schema=coreschema.String()) coreapi.Field('id', required=True, location='path', schema=typesys.String())
] ]
) )
} }
@ -451,14 +451,14 @@ class SchemaLinksTests(TestCase):
url='/users/{id}/', url='/users/{id}/',
action='get', action='get',
fields=[ fields=[
coreapi.Field('id', required=True, location='path', schema=coreschema.String()) coreapi.Field('id', required=True, location='path', schema=typesys.String())
] ]
), ),
'update': coreapi.Link( 'update': coreapi.Link(
url='/users/{id}/', url='/users/{id}/',
action='patch', action='patch',
fields=[ fields=[
coreapi.Field('id', required=True, location='path', schema=coreschema.String()) coreapi.Field('id', required=True, location='path', schema=typesys.String())
] ]
), ),
'friends': { 'friends': {
@ -466,14 +466,14 @@ class SchemaLinksTests(TestCase):
url='/users/{id}/friends', url='/users/{id}/friends',
action='get', action='get',
fields=[ fields=[
coreapi.Field('id', required=True, location='path', schema=coreschema.String()) coreapi.Field('id', required=True, location='path', schema=typesys.String())
] ]
), ),
'create': coreapi.Link( 'create': coreapi.Link(
url='/users/{id}/friends', url='/users/{id}/friends',
action='post', action='post',
fields=[ fields=[
coreapi.Field('id', required=True, location='path', schema=coreschema.String()) coreapi.Field('id', required=True, location='path', schema=typesys.String())
] ]
) )
} }
@ -502,7 +502,7 @@ class SchemaLinksTests(TestCase):
url='/animals/dog/{id}/vet', url='/animals/dog/{id}/vet',
action='get', action='get',
fields=[ fields=[
coreapi.Field('id', required=True, location='path', schema=coreschema.String()) coreapi.Field('id', required=True, location='path', schema=typesys.String())
] ]
) )
}, },
@ -510,7 +510,7 @@ class SchemaLinksTests(TestCase):
url='/animals/dog/{id}', url='/animals/dog/{id}',
action='get', action='get',
fields=[ fields=[
coreapi.Field('id', required=True, location='path', schema=coreschema.String()) coreapi.Field('id', required=True, location='path', schema=typesys.String())
] ]
) )
}, },
@ -519,7 +519,7 @@ class SchemaLinksTests(TestCase):
url='/animals/cat/', url='/animals/cat/',
action='get', action='get',
fields=[ fields=[
coreapi.Field('id', required=True, location='path', schema=coreschema.String()) coreapi.Field('id', required=True, location='path', schema=typesys.String())
] ]
), ),
'create': coreapi.Link( 'create': coreapi.Link(
@ -551,7 +551,7 @@ class SchemaLinksTests(TestCase):
url='/animals/dog/{id}/vet', url='/animals/dog/{id}/vet',
action='get', action='get',
fields=[ fields=[
coreapi.Field('id', required=True, location='path', schema=coreschema.String()) coreapi.Field('id', required=True, location='path', schema=typesys.String())
] ]
) )
}, },
@ -559,7 +559,7 @@ class SchemaLinksTests(TestCase):
url='/animals/dog/{id}', url='/animals/dog/{id}',
action='get', action='get',
fields=[ fields=[
coreapi.Field('id', required=True, location='path', schema=coreschema.String()) coreapi.Field('id', required=True, location='path', schema=typesys.String())
] ]
) )
}, },
@ -568,7 +568,7 @@ class SchemaLinksTests(TestCase):
url='/animals/cat/', url='/animals/cat/',
action='get', action='get',
fields=[ fields=[
coreapi.Field('id', required=True, location='path', schema=coreschema.String()) coreapi.Field('id', required=True, location='path', schema=typesys.String())
] ]
), ),
'create': coreapi.Link( 'create': coreapi.Link(
@ -585,7 +585,7 @@ class SchemaLinksTests(TestCase):
url='/farmers/silo/{id}/soy', url='/farmers/silo/{id}/soy',
action='get', action='get',
fields=[ fields=[
coreapi.Field('id', required=True, location='path', schema=coreschema.String()) coreapi.Field('id', required=True, location='path', schema=typesys.String())
] ]
) )
}, },
@ -593,7 +593,7 @@ class SchemaLinksTests(TestCase):
url='/farmers/silo', url='/farmers/silo',
action='get', action='get',
fields=[ fields=[
coreapi.Field('id', required=True, location='path', schema=coreschema.String()) coreapi.Field('id', required=True, location='path', schema=typesys.String())
] ]
) )
} }