Proposal to introduce drf_spectacular as a replacement for handwritten schemas #132
johncosta
started this conversation in
Show and tell
Replies: 2 comments 1 reply
-
|
This is great! You can do a pull request of your branch with that whenever you want, and I will create an issue and assign myself to move the documentation of Users app to this format as well! Thanks for your effort, and thanks for teaching me about this new tool. |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
Thanks @smattymatty! I'll clean up the PR and then submit. Did we want to keep the manually created docs for now or should we remove them? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi Folks!
The following is a proposal to address item 5, Consider setting up a more advanced API documentation tool: #23
Motivation
Problem Statement
The current implementation of API schemas in EduLite relies on handwritten schemas, which can be error-prone and
difficult to maintain over time. The proposal is to introduce
drf_spectacular, a library that automatically generatesOpenAPI 3.0 schemas for Django REST Framework (DRF) applications.
Proposed Solution
Introduce drf_spectacular as a way to automatically generate and maintain generally accurate OpenAPI 3.0 documentation
for the DRF APIs.
Objectives
Overview
DRF Spectacular is a library that provides:
Alternatives Considered
Implementation Plan
Install drf_spectacular:
Add
drf_spectacularto the project's requirements and install it.Update Django Settings:
then add drf-spectacular to installed apps in settings.py
register our spectacular AutoSchema with DRF
set drf-spectacular settings in settings.py
note: VERSION could be included in the settings, but since we don't have an automated versioning system in place, it is not included here.
note: SWAGGER and REDOC are two different ui tools for displaying the OpenAPI schema. We can choose to use one or both based on our preference.
note: A fully functional branch can be found in this branch here: johncosta#3
Use
@extend_schemadecorators to annotate views with additional metadata, such as descriptions, responses, and parameters.Example Impact
Recommendation
I recommend adopting
drf_spectacularto enhance the API documentation process in EduLite. This will not only improvethe quality and maintainability of the API documentation but also provide a better developer experience for both current
and future contributors. From a backend engineering perspective, the definitions feel easy to read and with some rigor straightforward to write. From a frontend perspective, having the live docs seems helpful.
That said,
drf_spectacularis not a silver bullet. It requires careful configuration and testing to ensure that thegenerated documentation is accurate and useful. It is important to follow best practices when annotating views and
serializers to ensure that the generated schema is comprehensive and self-explanatory.
Reference Documentation
Beta Was this translation helpful? Give feedback.
All reactions