DRF OpenAPI
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.
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.
>1.0, <=2.0Support multiple response codes, not just
200All 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,
schemaandserializerare used interchangably
Versioned schema is supported by extending
VersionedSerializers.Metadata, i.e. versioning, response and request schema, are bound to a view method through the
view_configdecorator.Extra schema information such as response status codes and their descriptions are bound to the serializer
MetaclassAutomatic response validation is optionally provided
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
MIT
History
0.1.0 (2017-07-01)
First release on PyPI.
0.7.0 (2017-07-28)
Implement
VersionedSerializerImplement
view_configMake 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
VersionedSerializerintoVersionedSerializers
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)
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)
1.2.0 (2017-12-20)
Make serializer_class optional (Issue 57)
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file drf_openapi-1.3.0.tar.gz.
File metadata
- Download URL: drf_openapi-1.3.0.tar.gz
- Upload date:
- Size: 22.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1cd1164ac6262252cb629df4de2c1a3f9a738e608ec9b56f26545d45ed673c1f
|
|
| MD5 |
3ea15ac803070ea7d298cafd9c0ca1b7
|
|
| BLAKE2b-256 |
d162272f29af7e2bf38fe92897abf57f49c9674b5d3b1f9a1683a953c59b9859
|
File details
Details for the file drf_openapi-1.3.0-py2.py3-none-any.whl.
File metadata
- Download URL: drf_openapi-1.3.0-py2.py3-none-any.whl
- Upload date:
- Size: 16.2 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
21d28a0ea5b78243ee1b815041f715c1a7e9d60c063cbf9db5e4fa5535361460
|
|
| MD5 |
c521c470fc8a31eeacad32a05dfdb510
|
|
| BLAKE2b-256 |
2e5d35c9e1377461a83c798121e8fab3f920478010cd66026afce39a33fe28e7
|