Skip to content

Commit

Permalink
Live API documentation (#4755)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomchristie committed Mar 3, 2017
1 parent 7f59ce1 commit 68d2020
Show file tree
Hide file tree
Showing 52 changed files with 5,448 additions and 75 deletions.
7 changes: 7 additions & 0 deletions codecov.yml
@@ -0,0 +1,7 @@
coverage:
status:
project: false
patch: false
changes: false

comment: off
63 changes: 63 additions & 0 deletions docs/topics/3.6-announcement.md
@@ -0,0 +1,63 @@
<style>
.promo li a {
float: left;
width: 130px;
height: 20px;
text-align: center;
margin: 10px 30px;
padding: 150px 0 0 0;
background-position: 0 50%;
background-size: 130px auto;
background-repeat: no-repeat;
font-size: 120%;
color: black;
}
.promo li {
list-style: none;
}
</style>

# Django REST framework 3.6

---

## Funding

The 3.6 release would not have been possible without our [collaborative funding model][funding].
If you use REST framework commercially and would like to see this work continue,
we strongly encourage you to invest in its continued development by
**[signing up for a paid&nbsp;plan][funding]**.

<ul class="premium-promo promo">
<li><a href="http://jobs.rover.com/" style="background-image: url(https://fund-rest-framework.s3.amazonaws.com/rover_130x130.png)">Rover.com</a></li>
<li><a href="https://getsentry.com/welcome/" style="background-image: url(https://fund-rest-framework.s3.amazonaws.com/sentry130.png)">Sentry</a></li>
<li><a href="https://getstream.io/try-the-api/?utm_source=drf&utm_medium=banner&utm_campaign=drf" style="background-image: url(https://fund-rest-framework.s3.amazonaws.com/stream-130.png)">Stream</a></li>
<li><a href="https://hello.machinalis.co.uk/" style="background-image: url(https://fund-rest-framework.s3.amazonaws.com/Machinalis130.png)">Machinalis</a></li>
<li><a href="https://rollbar.com" style="background-image: url(https://fund-rest-framework.s3.amazonaws.com/rollbar.png)">Rollbar</a></li>
<li><a href="https://micropyramid.com/django-rest-framework-development-services/" style="background-image: url(https://fund-rest-framework.s3.amazonaws.com/mp-text-logo.png)">MicroPyramid</a></li>
</ul>
<div style="clear: both; padding-bottom: 20px;"></div>

*Many thanks to all our [sponsors][sponsors], and in particular to our premium backers, [Rover](http://jobs.rover.com/), [Sentry](https://getsentry.com/welcome/), [Stream](https://getstream.io/?utm_source=drf&utm_medium=banner&utm_campaign=drf), [Machinalis](https://hello.machinalis.co.uk/), [Rollbar](https://rollbar.com), and [MicroPyramid](https://micropyramid.com/django-rest-framework-development-services/).*


---

## API documentation

...

## JavaScript Client

...

---

## Deprecations

...

---

[sponsors]: https://fund.django-rest-framework.org/topics/funding/#our-sponsors
[funding]: funding.md
8 changes: 6 additions & 2 deletions docs/topics/documenting-your-api.md
Expand Up @@ -6,9 +6,13 @@
There are a variety of approaches to API documentation. This document introduces a few of the various tools and options you might choose from. The approaches should not be considered exclusive - you may want to provide more than one documentation style for you API, such as a self describing API that also includes static documentation of the various API endpoints.

## Endpoint documentation
##

The most common way to document Web APIs today is to produce documentation that lists the API endpoints verbatim, and describes the allowable operations on each. There are various tools that allow you to do this in an automated or semi-automated way.
... TODO ...

## Third party packages

There are a number of mature third-party packages for providing API documentation.

---

Expand Down
2 changes: 1 addition & 1 deletion docs/topics/jobs.md
Expand Up @@ -3,7 +3,7 @@
Looking for a new Django REST Framework related role? On this site we provide a list of job resources that may be helpful. It's also worth checking out if any of [our sponsors are hiring][drf-funding].


## Places to Look for Django REST Framework Jobs
## Places to look for Django REST Framework Jobs

* [https://www.djangoproject.com/community/jobs/][djangoproject-website]
* [https://www.python.org/jobs/][python-org-jobs]
Expand Down
22 changes: 22 additions & 0 deletions licenses/bootstrap.md
@@ -0,0 +1,22 @@
https://github.com/twbs/bootstrap/

The MIT License (MIT)

Copyright (c) 2011-2016 Twitter, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 changes: 22 additions & 0 deletions licenses/jquery.json-view.md
@@ -0,0 +1,22 @@
https://github.com/bazh/jquery.json-view/

The MIT License (MIT)

Copyright (c) 2014 bazh. (http://github.com/bazh)

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3 changes: 2 additions & 1 deletion mkdocs.yml
Expand Up @@ -62,14 +62,15 @@ pages:
- 'Tutorials and Resources': 'topics/tutorials-and-resources.md'
- 'Contributing to REST framework': 'topics/contributing.md'
- 'Project management': 'topics/project-management.md'
- 'Jobs': 'topics/jobs.md'
- '3.0 Announcement': 'topics/3.0-announcement.md'
- '3.1 Announcement': 'topics/3.1-announcement.md'
- '3.2 Announcement': 'topics/3.2-announcement.md'
- '3.3 Announcement': 'topics/3.3-announcement.md'
- '3.4 Announcement': 'topics/3.4-announcement.md'
- '3.5 Announcement': 'topics/3.5-announcement.md'
- '3.6 Announcement': 'topics/3.6-announcement.md'
- 'Kickstarter Announcement': 'topics/kickstarter-announcement.md'
- 'Mozilla Grant': 'topics/mozilla-grant.md'
- 'Funding': 'topics/funding.md'
- 'Release Notes': 'topics/release-notes.md'
- 'Jobs': 'topics/jobs.md'
3 changes: 2 additions & 1 deletion requirements/requirements-optionals.txt
Expand Up @@ -2,4 +2,5 @@
markdown==2.6.4
django-guardian==1.4.6
django-filter==1.0.0
coreapi==2.0.8
coreapi==2.2.4
coreschema==0.0.4
7 changes: 7 additions & 0 deletions rest_framework/compat.py
Expand Up @@ -175,6 +175,13 @@ def value_from_object(field, obj):
uritemplate = None


# coreschema is optional
try:
import coreschema
except ImportError:
coreschema = None


# django-filter is optional
try:
import django_filters
Expand Down
50 changes: 50 additions & 0 deletions rest_framework/documentation.py
@@ -0,0 +1,50 @@
from django.conf.urls import include, url

from rest_framework.renderers import (
CoreJSONRenderer, DocumentationRenderer, SchemaJSRenderer
)
from rest_framework.schemas import get_schema_view


def get_docs_view(title=None, description=None, schema_url=None, public=True):
renderer_classes = [DocumentationRenderer, CoreJSONRenderer]

return get_schema_view(
title=title,
url=schema_url,
description=description,
renderer_classes=renderer_classes,
public=public
)


def get_schemajs_view(title=None, description=None, schema_url=None, public=True):
renderer_classes = [SchemaJSRenderer]

return get_schema_view(
title=title,
url=schema_url,
description=description,
renderer_classes=renderer_classes,
public=public
)


def include_docs_urls(title=None, description=None, schema_url=None, public=True):
docs_view = get_docs_view(
title=title,
description=description,
schema_url=schema_url,
public=public
)
schema_js_view = get_schemajs_view(
title=title,
description=description,
schema_url=schema_url,
public=public
)
urls = [
url(r'^$', docs_view, name='docs-index'),
url(r'^schema.js$', schema_js_view, name='schema-js')
]
return include(urls, namespace='api-docs')
34 changes: 31 additions & 3 deletions rest_framework/filters.py
Expand Up @@ -13,10 +13,11 @@
from django.db.models.constants import LOOKUP_SEP
from django.template import loader
from django.utils import six
from django.utils.encoding import force_text
from django.utils.translation import ugettext_lazy as _

from rest_framework.compat import (
coreapi, distinct, django_filters, guardian, template_render
coreapi, coreschema, distinct, django_filters, guardian, template_render
)
from rest_framework.settings import api_settings

Expand All @@ -34,6 +35,7 @@ def filter_queryset(self, request, queryset, view):

def get_schema_fields(self, view):
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 []


Expand Down Expand Up @@ -82,6 +84,8 @@ class SearchFilter(BaseFilterBackend):
'@': 'search',
'$': 'iregex',
}
search_title = _('Search')
search_description = _('A search term.')

def get_search_terms(self, request):
"""
Expand Down Expand Up @@ -162,13 +166,26 @@ def to_html(self, request, queryset, view):

def get_schema_fields(self, view):
assert coreapi is not None, 'coreapi must be installed to use `get_schema_fields()`'
return [coreapi.Field(name=self.search_param, required=False, location='query')]
assert coreschema is not None, 'coreschema must be installed to use `get_schema_fields()`'
return [
coreapi.Field(
name=self.search_param,
required=False,
location='query',
schema=coreschema.String(
title=force_text(self.search_title),
description=force_text(self.search_description)
)
)
]


class OrderingFilter(BaseFilterBackend):
# The URL query parameter used for the ordering.
ordering_param = api_settings.ORDERING_PARAM
ordering_fields = None
ordering_title = _('Ordering')
ordering_description = _('Which field to use when ordering the results.')
template = 'rest_framework/filters/ordering.html'

def get_ordering(self, request, queryset, view):
Expand Down Expand Up @@ -280,7 +297,18 @@ def to_html(self, request, queryset, view):

def get_schema_fields(self, view):
assert coreapi is not None, 'coreapi must be installed to use `get_schema_fields()`'
return [coreapi.Field(name=self.ordering_param, required=False, location='query')]
assert coreschema is not None, 'coreschema must be installed to use `get_schema_fields()`'
return [
coreapi.Field(
name=self.ordering_param,
required=False,
location='query',
schema=coreschema.String(
title=force_text(self.ordering_title),
description=force_text(self.ordering_description)
)
)
]


class DjangoObjectPermissionsFilter(BaseFilterBackend):
Expand Down

0 comments on commit 68d2020

Please sign in to comment.