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)
Metadata
Release files for drf-openapi 1.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| drf_openapi-1.3.0.tar.gz | 22.3 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| drf_openapi-1.3.0-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details |
Total release size: 38.5 kB
Release files / drf_openapi-1.3.0.tar.gz
| Download URL | drf_openapi-1.3.0.tar.gz |
|---|---|
| Size | 22.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1cd1164ac6262252cb629df4de2c1a3f9a738e608ec9b56f26545d45ed673c1f
|
|
BLAKE2b-256 checksum How to use checksums |
d162272f29af7e2bf38fe92897abf57f49c9674b5d3b1f9a1683a953c59b9859
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / drf_openapi-1.3.0-py2.py3-none-any.whl
| Download URL | drf_openapi-1.3.0-py2.py3-none-any.whl |
|---|---|
| Size | 16.2 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
21d28a0ea5b78243ee1b815041f715c1a7e9d60c063cbf9db5e4fa5535361460
|
|
BLAKE2b-256 checksum How to use checksums |
2e5d35c9e1377461a83c798121e8fab3f920478010cd66026afce39a33fe28e7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for drf-openapi 1.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.