Skip to main content

Utilities to generate OpenAPI-compatible schema from API made with Django Rest Framework

Project description


.. image::

.. image::

.. image::
:alt: Documentation Status

.. image::
:alt: Updates

.. image::
:alt: Join the chat at

Generates OpenAPI-compatible schema from API made with Django Rest Framework. Use `ReDoc <>`_ as default interface instead of Swagger.
First-class support for API versioning changelog & method-specific schema definition.

.. figure::
:scale: 80%

.. contents::

1. Background

Django Rest Framework has an `API schema generation/declaration mechanism <>`_ provided by
`coreapi <>`_ standard. There are a couple of problems with the current ecosystem:

- CoreAPI is not compatible out of the box with `OpenAPI <>`_ which is a much more popular API standard with superior tooling support, i.e. Swagger et. al.
- The OpenAPI codec (compatibility layer) that CoreAPI team provides drops / doesn't support a number of useful OpenAPI features.
- There is no support for versioning or method-specific schema.

2. Requirements:

This project was born to bridge the gap between DRF and OpenAPI. The high-level requirements are as followed:

- Can be dropped into any existing DRF project without any code change necessary.
- Provide clear disctinction between request schema and response schema.
- Provide a versioning mechanism for each schema. Support defining schema by version range syntax, e.g. :code:`>1.0, <=2.0`
- Support multiple response codes, not just :code:`200`
- All this information should be bound to view methods, not view classes.

It's important to stress the non-intrusiveness requirement, not least because I want to minimize what I will have to change when
DRF itself decides to support OpenAPI officially, if at all.

3. Design

- Schema are automatically generated from `serializers <>`_
* From here onwards, :code:`schema` and :code:`serializer` are used interchangably
- Versioned schema is supported by extending :code:`VersionedSerializers`.
- Metadata, i.e. versioning, response and request schema, are bound to a view method through the :code:`view_config` decorator.
- Extra schema information such as response status codes and their descriptions are bound to the serializer :code:`Meta` class
- Automatic response validation is optionally provided :code:`view_config(response_serializer=FooSerializer, validate_response=True)`

4. Constraints

Currently DRF OpenAPI only supports DRF project that has `versioning <>`_ enabled.
I have only tested `URLPathVersioning <>`_ but I intend to suppor the full range of
versioning scheme supported by DRF.

5. Examples

Please read the `docs <>`_ for a quickstart.

Also I have recreated the example in `DRF tutorial <>`_ with OpenAPI schema enabled
in `<examples/>`_.

6. License


0.1.0 (2017-07-01)

* First release on PyPI.

0.7.0 (2017-07-28)

* Implement :code:`VersionedSerializer`
* Implement :code:`view_config`
* Make the library an installable Django app

0.8.0 (2017-07-28)

* Some minor fixes to make sure it works on generic project
* Add examples

0.8.1 (2017-07-28)

* Fix bug when parsing empty docstring of the serializer

0.9.0 (2017-07-28)

* Rename base :code:`VersionedSerializer` into :code:`VersionedSerializers`

0.9.1 (2017-07-28)

* Fix import issue after renaming

0.9.3 (2017-08-05)

* Add support for different response status codes (`Issue 27 <>`_)

0.9.5 (2017-08-12)

* Add Python 2.7 compatibility (thanks `tuffnatty <>`_)
* Add support for ModelViewSet (thanks `tuffnatty <>`_)

0.9.6 (2017-08-12)

* Fix type display for child of ListSerializer/ListField (`Issue 28 <>`_)

0.9.7 (2017-09-12)

* Improve permission for schema view (`Issue 31 <>`_)

0.9.8 (2017-10-01)

* Turn schema view into a class-based view for easier customization

0.9.9 (2017-10-01)

* Another fix for ListSerializer/ListField (`Issue 28 <>`_)

1.0.1 (2017-12-14)

* Fix DRF 3.7 compatibility issue
* Added (`werwty <>`_) as a maintainer

1.1.0 (2017-12-14)

* Fix viewset that doesn't have pagination_class (`Issue 84 <>`_) and (`Issue 92 <>`_)

1.2.0 (2017-12-20)

* Make serializer_class optional (`Issue 57 <>`_)

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
drf_openapi-1.3.0-py2.py3-none-any.whl (16.2 kB) Copy SHA256 hash SHA256 Wheel py2.py3
drf_openapi-1.3.0.tar.gz (22.3 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page