-
Notifications
You must be signed in to change notification settings - Fork 4.3k
[FC-0118] docs: add ADR for standardizing API documentation and schema coverage #38189
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
Open
Abdul-Muqadim-Arbisoft
wants to merge
3
commits into
openedx:docs/ADRs-axim_api_improvements
Choose a base branch
from
edly-io:docs/ADRs-axim_api_improvements
base: docs/ADRs-axim_api_improvements
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+204
−0
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
204 changes: 204 additions & 0 deletions
204
docs/decisions/0027-standardize-api-documentation-and-schema-coverage.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,204 @@ | ||
| Standardize API Documentation & Schema Coverage | ||
| ================================================================= | ||
|
|
||
| :Status: Proposed | ||
| :Date: 2026-03-18 | ||
| :Deciders: API Working Group | ||
| :Technical Story: Open edX REST API Standards - Documentation standardization for discoverability | ||
|
|
||
| Context | ||
| ------- | ||
|
|
||
| Many Open edX views lack proper OpenAPI schema decorators and machine-readable | ||
| documentation. This makes it difficult for AI and external tools to | ||
| auto-discover endpoints, creates integration challenges for external developers, | ||
| and leads to the emergence of duplicate or overlapping endpoints. | ||
|
|
||
| The platform currently uses `api-doc-tools`_ (``edx-api-doc-tools``), an | ||
| Open edX-maintained library that wraps `drf-yasg`_ and exposes the ``@schema``, | ||
| ``@schema_for``, ``parameter``, ``query_parameter``, and ``path_parameter`` | ||
| decorators, along with URL helpers (``make_api_info`` / ``make_docs_urls``) that | ||
| serve a Swagger UI at ``/api-docs``. drf-yasg only targets OpenAPI 2.0 and is | ||
| largely unmaintained upstream. Replacing drf-yasg inside api-doc-tools with | ||
| drf-spectacular was investigated and found infeasible due to the significant | ||
| divergence in their decorator contracts. Direct adoption of drf-spectacular is | ||
| therefore the right path forward. | ||
|
|
||
| .. _api-doc-tools: https://github.com/openedx/api-doc-tools/ | ||
| .. _drf-yasg: https://github.com/axnsan12/drf-yasg | ||
|
|
||
| Decision | ||
| -------- | ||
|
|
||
| We will standardize all Open edX REST APIs to use **drf-spectacular** with **@extend_schema decorators** for complete machine-readable documentation. | ||
|
|
||
| Implementation requirements: | ||
|
|
||
| * Use drf-spectacular for all API endpoints with @extend_schema decorators. | ||
| * Document request/response schemas, status codes, and error conditions. | ||
| * Include comprehensive descriptions and examples for complex endpoints. | ||
| * Ensure all endpoints have machine-readable OpenAPI coverage. | ||
| * Maintain consistent documentation patterns across services. | ||
|
|
||
| Relevance in edx-platform | ||
| ------------------------- | ||
|
|
||
| Current patterns that should be migrated: | ||
|
|
||
| * **Discussion topics API** (``^v0/course/{settings.COURSE_KEY_PATTERN}/sync_discussion_topics$``) lacks OpenAPI-compliant schema and has incomplete documentation. | ||
| * **Course content APIs** have missing or incomplete schema definitions. | ||
| * **User management endpoints** lack proper request/response documentation. | ||
|
|
||
| Code example (target documentation usage) | ||
| ----------------------------------------- | ||
|
|
||
| **Example APIView with comprehensive drf-spectacular documentation:** | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| # views.py | ||
| from drf_spectacular.utils import extend_schema, OpenApiRequest, OpenApiResponse | ||
| from rest_framework.views import APIView | ||
| from rest_framework.response import Response | ||
| from .serializers import TopicSerializer | ||
|
|
||
| class ExampleTopicAPIView(APIView): | ||
| """ | ||
| API endpoint for managing discussion topics. | ||
| """ | ||
|
|
||
| @extend_schema( | ||
| summary="List discussion topics", | ||
| description="Returns a paginated list of discussion topics for the specified course.", | ||
| responses={ | ||
| 200: OpenApiResponse( | ||
| response=TopicSerializer(many=True), | ||
| description="List of discussion topics retrieved successfully" | ||
| ), | ||
| 400: OpenApiResponse( | ||
| description="Bad request - invalid parameters" | ||
| ), | ||
| 403: OpenApiResponse( | ||
| description="Permission denied - user lacks access" | ||
| ), | ||
| 404: OpenApiResponse( | ||
| description="Course not found" | ||
| ), | ||
| }, | ||
| parameters=[ | ||
| { | ||
| "name": "course_id", | ||
| "in": "path", | ||
| "required": True, | ||
| "schema": {"type": "string"}, | ||
| "description": "Course identifier" | ||
| } | ||
| ] | ||
| ) | ||
| def get(self, request): | ||
| """Retrieve discussion topics for the current course.""" | ||
| return Response({"results": []}) | ||
|
|
||
| @extend_schema( | ||
| summary="Create discussion topic", | ||
| description="Creates a new discussion topic in the specified course.", | ||
| request=OpenApiRequest(request=TopicSerializer), | ||
| responses={ | ||
| 201: OpenApiResponse( | ||
| response=TopicSerializer, | ||
| description="Discussion topic created successfully" | ||
| ), | ||
| 400: OpenApiResponse( | ||
| description="Bad request - invalid data" | ||
| ), | ||
| 403: OpenApiResponse( | ||
| description="Permission denied" | ||
| ), | ||
| } | ||
| ) | ||
| def post(self, request): | ||
| """Create a new discussion topic.""" | ||
| return Response({"detail": "Topic created"}, status=201) | ||
|
|
||
| Consequences | ||
| ------------ | ||
|
|
||
| Positive | ||
| ~~~~~~~~ | ||
|
|
||
| * Provides machine-readable schemas for external systems integrations. | ||
| * Improves developer experience through standardized OpenAPI documentation. | ||
| * Enables automatic client SDK generation. | ||
| * Reduces duplicate endpoints through better discoverability. | ||
| * Facilitates API testing and validation. | ||
|
|
||
| Negative / Trade-offs | ||
| ~~~~~~~~~~~~~~~~~~~~~ | ||
|
|
||
| * Requires initial effort to document existing endpoints. | ||
| * Ongoing maintenance to keep documentation in sync with code changes. | ||
| * Learning curve for teams unfamiliar with drf-spectacular decorators. | ||
| * **api-doc-tools and drf-yasg will be deprecated and archived.** Existing | ||
| usages across edx-platform and downstream services must be migrated. See | ||
| the migration guide below. | ||
|
|
||
| Alternatives Considered | ||
| ----------------------- | ||
|
|
||
| * **Keep minimal documentation**: rejected due to poor discoverability and integration challenges. | ||
| * **Use separate documentation files**: rejected because inline decorators provide better maintainability. | ||
| * **Update api-doc-tools to use drf-spectacular internally**: investigated and | ||
| found infeasible — the decorator contracts of the two libraries diverge | ||
| significantly, making a compatibility shim as costly as a direct migration. | ||
|
|
||
| Migration: api-doc-tools to drf-spectacular | ||
| -------------------------------------------- | ||
|
|
||
| **What is api-doc-tools?** | ||
| ``api-doc-tools`` is the current Open edX documentation library, built on top of | ||
| ``drf-yasg``. It provides the ``@schema`` / ``@schema_for`` decorators and the | ||
| ``make_docs_urls`` URL helper used across edx-platform today. | ||
|
|
||
| **Decorator mapping:** | ||
|
|
||
| +----------------------------------------------+-------------------------------------------------------+ | ||
| | api-doc-tools (old) | drf-spectacular (new) | | ||
| +==============================================+=======================================================+ | ||
| | ``@schema(parameters=[...], responses={...})``| ``@extend_schema(parameters=[...], responses={...})`` | | ||
| +----------------------------------------------+-------------------------------------------------------+ | ||
| | ``@schema_for("list", "docstring", ...)`` | ``@extend_schema_view(list=extend_schema(...))`` | | ||
| +----------------------------------------------+-------------------------------------------------------+ | ||
| | ``parameter(name, type, desc)`` | ``OpenApiParameter(name, type, desc)`` | | ||
| +----------------------------------------------+-------------------------------------------------------+ | ||
| | ``query_parameter(name, type, desc)`` | ``OpenApiParameter(name, type, desc,`` | | ||
| | | ``location=OpenApiParameter.QUERY)`` | | ||
| +----------------------------------------------+-------------------------------------------------------+ | ||
| | ``path_parameter(name, type, desc)`` | ``OpenApiParameter(name, type, desc,`` | | ||
| | | ``location=OpenApiParameter.PATH)`` | | ||
| +----------------------------------------------+-------------------------------------------------------+ | ||
| | ``make_docs_urls(make_api_info(...))`` | ``SpectacularAPIView`` + ``SpectacularSwaggerView`` | | ||
| +----------------------------------------------+-------------------------------------------------------+ | ||
|
|
||
| Endpoints should be migrated incrementally. New endpoints must use | ||
| drf-spectacular directly. Once all usages are migrated, ``edx-api-doc-tools`` | ||
| and ``drf-yasg`` will be removed from requirements and the ``api-doc-tools`` | ||
| repository will be archived. | ||
|
|
||
| Rollout Plan | ||
| ------------ | ||
|
|
||
| 1. Configure drf-spectacular across all Open edX services. | ||
| 2. Create documentation templates and guidelines for common endpoint patterns. | ||
| 3. Audit existing endpoints and prioritize high-impact APIs for documentation. | ||
| 4. Implement automated testing to ensure schema completeness. | ||
| 5. Set up continuous integration to validate documentation quality. | ||
| 6. Publish and maintain OpenAPI specifications for all services. | ||
| 7. Once migration is complete, archive ``api-doc-tools`` and remove ``drf-yasg`` | ||
| from service requirements. | ||
|
|
||
| References | ||
| ---------- | ||
|
|
||
| * Open edX REST API Standards: "API Documentation & Schema Coverage" recommendations for discoverability. | ||
| * `api-doc-tools repository <https://github.com/openedx/api-doc-tools/>`_ | ||
| * `drf-spectacular documentation <https://drf-spectacular.readthedocs.io/>`_ | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently we use https://github.com/openedx/api-doc-tools/ as a shim over drf-yasg, which is currently being used to generate API docs in the platform. Another option here would be to update that tool to replace the underlying drf-yasg usage with drf-spectacular. This would mean that all the endpoints we have currently documented would not need new documentation or further updates. If that is not viable, then I think a consequence would be the deprecation and archival of api-doc-tools and drf-yasg and if that's the direction you want to move then you should document that here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for flagging this, you're right that the ADR doesn't address api-doc-tools
One concern with upgrading the shim to use drf-spectacular under the hood is that drf-yasg is largely unmaintained at this point and has notable limitations with OpenAPI 3.0 support, which is part of the motivation for moving to drf-spectacular in the first place. Also worth noting that even if we swap the internals, we'd still be committing to maintaining api-doc-tools as a wrapper indefinitely, it would need to keep up with drf-spectacular's API over time, which is ongoing effort with not a lot of upside once the migration is done.
That said, I want to make sure I'm not dismissing the upgrade path without properly investigating it. I'll do an R&D to check the feasibility of replacing drf-yasg inside api-doc-tools with drf-spectacular, and update the ADR based on findings. If it's viable and the maintenance burden is acceptable, that's clearly the lower-friction path. If not, I'll document the deprecation of api-doc-tools and drf-yasg explicitly as a consequence as you suggested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@feanil After doing some R&D, replacing drf-yasg inside api-doc-tools with drf-spectacular doesn't look viable, so I'll be updating the ADR to explicitly document the deprecation and archival of api-doc-tools and drf-yasg as a consequence of this decision.
That said, since we're already going through the effort of upgrading the APIs, I think this is actually a great opportunity to make a clean break. We can keep api-doc-tools and its existing docs maintained and functional during the transition period and phase it out gradually as endpoints get migrated over to drf-spectacular directly.
What are your thoughts on this approach?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Abdul-Muqadim-Arbisoft I think explicitly documenting the deprecation and archival of api-doc-tools makes sense to me as well. Please update the ADR and include context for what api-doc-tools is and how we will migrate current uses of it to use drf-spectacular instead.