Skip to content

Live API documentation #4755

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 36 commits into from
Mar 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
a0eeaa3
Add 'description' to Core API fields.
tomchristie Dec 2, 2016
c170754
Initial components for documentation
tomchristie Dec 9, 2016
aa6fb60
Merge branch 'add-field-descriptions' into docs
tomchristie Dec 9, 2016
9bff7af
Update tests and pep8 fixes
tomchristie Dec 12, 2016
7d32ddf
Include Field.input, Field.title and Field.choices
tomchristie Dec 15, 2016
9893665
Merge branch 'master' into docs
tomchristie Jan 5, 2017
db89a2e
Add 'description' to Core API fields.
tomchristie Dec 2, 2016
27903cb
Initial components for documentation
tomchristie Dec 9, 2016
210849c
Update tests and pep8 fixes
tomchristie Dec 12, 2016
0259c44
Include Field.input, Field.title and Field.choices
tomchristie Dec 15, 2016
fa9a88b
Adding docs templates. Refactoring to coreschema.
tomchristie Jan 25, 2017
9cb3c8e
Merge branch 'docs' of github.com:tomchristie/django-rest-framework i…
tomchristie Jan 27, 2017
49a2945
Work on DocumentationRenderer
tomchristie Feb 1, 2017
9f32372
Use coreschema in documentation generation.
tomchristie Feb 1, 2017
9dbdf34
DocumentationRenderer fixes
tomchristie Feb 1, 2017
75eebc3
New docs layout (alt) (#4879)
manosim Feb 8, 2017
6dc301b
Fix Docs Tests (#4885)
manosim Feb 8, 2017
dd18a3b
Setup codecov config (#4886)
manosim Feb 8, 2017
0b8cd36
Merge branch 'master' into docs
tomchristie Feb 8, 2017
7937745
Fix to 'get_docs_view'
tomchristie Feb 8, 2017
cc7ff97
More padding in the main container & Remove links from parents in sid…
manosim Feb 8, 2017
d379948
Docs - Improve UI (#4890)
manosim Feb 8, 2017
b9a9d02
Language Switcher (#4891)
manosim Feb 8, 2017
e0d4c45
Update to latest version of coreapi
tomchristie Feb 10, 2017
479ee05
Project coverage should not pas/fail a build
tomchristie Feb 10, 2017
bfeb1a5
Interact Modal (#4903)
manosim Feb 15, 2017
f539931
Docs Interact (#4904)
manosim Feb 16, 2017
e6018bb
Merge branch 'master' into docs
tomchristie Feb 27, 2017
1ed82aa
Docs Authentication (#4926)
manosim Feb 27, 2017
c412de9
Ensure fields in docs forms are ordered
tomchristie Feb 28, 2017
5c99e7e
API docs tweaks
tomchristie Mar 1, 2017
2287201
Move API explorer javascript into static file
tomchristie Mar 1, 2017
9fac04b
Remove usused assignment
tomchristie Mar 3, 2017
3ae35ae
Sort imports
tomchristie Mar 3, 2017
fd328df
Sort imports
tomchristie Mar 3, 2017
55269ea
Add support for top-level description in API docs
tomchristie Mar 3, 2017
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
7 changes: 7 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Loading