Skip to content

Commit 3d7b57d

Browse files
committed
fix: home API schema after testing with SDK
1 parent 427bb8e commit 3d7b57d

1 file changed

Lines changed: 17 additions & 16 deletions

File tree

  • cms/djangoapps/contentstore/rest_api/v3/views

cms/djangoapps/contentstore/rest_api/v3/views/home.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828

2929
import edx_api_doc_tools as apidocs
3030
from django.conf import settings
31-
from drf_spectacular.utils import extend_schema
31+
from drf_spectacular.openapi import AutoSchema
32+
from drf_spectacular.utils import OpenApiParameter, extend_schema
3233
from edx_rest_framework_extensions.auth.jwt.authentication import JwtAuthentication
3334
from edx_rest_framework_extensions.auth.session.authentication import SessionAuthenticationAllowInactiveUser
3435
from organizations import api as org_api
@@ -48,8 +49,17 @@
4849
from openedx.core.lib.api.mixins import StandardizedErrorMixin
4950

5051

52+
class _HomeAutoSchema(AutoSchema):
53+
"""Override _is_list_view so drf-spectacular treats 'list' as a single-object response."""
54+
def _is_list_view(self, serializer=None):
55+
if self.view.action == 'list':
56+
return False
57+
return super()._is_list_view(serializer)
58+
59+
5160
@extend_schema(tags=["openedx-platform-sdk"])
5261
class HomeViewSet(StandardizedErrorMixin, viewsets.ViewSet):
62+
schema = _HomeAutoSchema()
5363
"""
5464
ViewSet for the Studio home page. Registered via DefaultRouter (basename ``home``).
5565
@@ -75,19 +85,14 @@ def get_serializer(self, *args, **kwargs):
7585
"""Return a serializer instance using the action-appropriate class."""
7686
return self.get_serializer_class()(*args, **kwargs)
7787

78-
@apidocs.schema(
88+
@extend_schema(
89+
responses={(200, "application/json"): StudioHomeSerializer},
7990
parameters=[
80-
apidocs.string_parameter(
81-
"org",
82-
apidocs.ParameterLocation.QUERY,
83-
description="Query param to filter by course org",
84-
),
85-
# ADR 0036 decision #3 — document the ``?fields=`` variant so it's
86-
# discoverable by OpenAPI consumers. The 200 response below is the
87-
# full default shape; ``?fields=`` returns a subset of top-level keys.
88-
apidocs.string_parameter(
91+
OpenApiParameter("org", str, OpenApiParameter.QUERY, description="Filter by course org"),
92+
OpenApiParameter(
8993
"fields",
90-
apidocs.ParameterLocation.QUERY,
94+
str,
95+
OpenApiParameter.QUERY,
9196
description=(
9297
"ADR 0036 explicit field selection. Comma-separated list "
9398
"of top-level keys to include in the response (e.g. "
@@ -96,10 +101,6 @@ def get_serializer(self, *args, **kwargs):
96101
),
97102
),
98103
],
99-
responses={
100-
200: StudioHomeSerializer,
101-
401: "The requester is not authenticated.",
102-
},
103104
)
104105
def list(self, request: Request):
105106
"""

0 commit comments

Comments
 (0)