diff --git a/cms/lib/spectacular.py b/cms/lib/spectacular.py index 3fec45af486a..34b740704b9d 100644 --- a/cms/lib/spectacular.py +++ b/cms/lib/spectacular.py @@ -14,6 +14,7 @@ "/api/contentstore/v0/youtube_transcripts/{course_id}/uploa", "/api/contentstore/v0/youtube_transcripts/{course_id}/upload", "/api/contentstore/v1/help_urls", + "/api/contentstore/v1/home", ) # Legacy addresses of APIs migrated to /api/authoring/, marked deprecated for diff --git a/cms/lib/tests/test_spectacular.py b/cms/lib/tests/test_spectacular.py index dcb380f339f3..3748226aad2e 100644 --- a/cms/lib/tests/test_spectacular.py +++ b/cms/lib/tests/test_spectacular.py @@ -80,9 +80,34 @@ def test_the_superseded_paths_are_exactly_these(self): "/api/contentstore/v0/youtube_transcripts/{course_id}/uploa", "/api/contentstore/v0/youtube_transcripts/{course_id}/upload", "/api/contentstore/v1/help_urls", + "/api/contentstore/v1/home", } assert len(SUPERSEDED_PATHS) == len(set(SUPERSEDED_PATHS)) + def test_v1_home_is_marked_deprecated_in_generated_schema(self): + """The URL router emits the path key without a trailing slash, matching SUPERSEDED_PATHS.""" + patterns = [url_path("api/contentstore/v1/home", _HomeViewSet.as_view({"get": "list"}))] + schema = SchemaGenerator(patterns=patterns).get_schema(request=None, public=True) + result = self._run(schema) + assert result["paths"]["/api/contentstore/v1/home"]["get"]["deprecated"] is True + + def test_a_path_under_v1_home_is_not_marked_deprecated(self): + """Exact-path lookup must not spill onto a path that starts with the superseded one.""" + home_path = "/api/contentstore/v1/home" + sibling_path = "/api/contentstore/v1/home/example" + result = self._run({"paths": { + home_path: {"get": {}}, + sibling_path: {"get": {}}, + }}) + assert result["paths"][home_path]["get"]["deprecated"] is True + assert "deprecated" not in result["paths"][sibling_path]["get"] + + def test_a_conforming_sibling_path_is_not_marked_deprecated(self): + """A real path near the replacement that no entry in SUPERSEDED_PATHS covers is unchanged.""" + sibling_path = "/api/authoring/v4/courses/" + result = self._run({"paths": {sibling_path: {"get": {}}}}) + assert "deprecated" not in result["paths"][sibling_path]["get"] + def test_the_conforming_paths_are_left_unmarked(self): conforming = "/api/authoring/v1/courses/{course_key}/youtube_transcript_checks/" result = self._run({"paths": {conforming: {"get": {"operationId": "x"}}}})