From 6d69b28646642113ec73bb3909ea97c38dc92801 Mon Sep 17 00:00:00 2001 From: rayangler <27821750+rayangler@users.noreply.github.com> Date: Wed, 4 Jan 2023 14:21:45 -0500 Subject: [PATCH] Revert "DOP-3353: Change OpenAPI metadata source to be spec string (#428)" (#436) --- snooty/postprocess.py | 9 ++++++--- snooty/test_postprocess.py | 28 ++++++++-------------------- 2 files changed, 14 insertions(+), 23 deletions(-) diff --git a/snooty/postprocess.py b/snooty/postprocess.py index 6707f467..b7e8736f 100644 --- a/snooty/postprocess.py +++ b/snooty/postprocess.py @@ -962,15 +962,18 @@ def enter_node(self, fileid_stack: FileIdStack, node: n.Node) -> None: return source = "" + argument = node.argument[0] # The parser determines the source_type based on the given argument and its # node structure. We echo that logic here to grab the source without needing # to worry about the argument's node structure. # The source_type cannot be manually set in rST as long as the option is not exposed # in the rstspec. - if source_type == "local" or source_type == "url": - source = node.children[0].get_text() + if source_type == "local" or source_type == "atlas": + assert isinstance(argument, n.Text) + source = argument.get_text() else: - source = node.argument[0].get_text() + assert isinstance(argument, n.Reference) + source = argument.refuri self.openapi_pages[current_slug] = self.SourceData(source_type, source) diff --git a/snooty/test_postprocess.py b/snooty/test_postprocess.py index f2e9f6bd..09a31f91 100644 --- a/snooty/test_postprocess.py +++ b/snooty/test_postprocess.py @@ -2526,14 +2526,7 @@ def test_openapi_metadata() -> None: .. openapi:: /openapi-admin-v3.yaml """, - Path( - "source/openapi-admin-v3.yaml" - ): """ -openapi: "3.0.1" -info: - description: "" - title: MongoDB Realm API -""", + Path("source/openapi-admin-v3.yaml"): "", Path( "source/admin/api/url.txt" ): """ @@ -2551,15 +2544,17 @@ def test_openapi_metadata() -> None: diagnostics for diagnostics in result.diagnostics.values() if diagnostics ], "Should not raise any diagnostics" openapi_pages = cast(Dict[str, Any], result.metadata["openapi_pages"]) - spec_title = "MongoDB Realm API" local_file_page = openapi_pages["admin/api/v3"] assert local_file_page["source_type"] == "local" - assert spec_title in local_file_page["source"] + assert local_file_page["source"] == "/openapi-admin-v3.yaml" url_page = openapi_pages["admin/api/url"] assert url_page["source_type"] == "url" - assert spec_title in url_page["source"] + assert ( + url_page["source"] + == "https://raw.githubusercontent.com/mongodb/snooty-parser/master/test_data/test_parser/openapi-admin-v3.yaml" + ) atlas_page = openapi_pages["admin/api/atlas"] assert atlas_page["source_type"] == "atlas" @@ -2593,14 +2588,7 @@ def test_openapi_duplicates() -> None: .. openapi:: https://raw.githubusercontent.com/mongodb/snooty-parser/master/test_data/test_parser/openapi-admin-v3.yaml """, - Path( - "source/openapi-admin-v3.yaml" - ): """ -openapi: "3.0.1" -info: - description: "" - title: MongoDB Realm API -""", + Path("source/openapi-admin-v3.yaml"): "", } ) as result: diagnostics = result.diagnostics[FileId("admin/api/v3.txt")] @@ -2611,4 +2599,4 @@ def test_openapi_duplicates() -> None: # First openapi directive should be source of truth file_metadata = openapi_pages["admin/api/v3"] assert file_metadata["source_type"] == "local" - assert "MongoDB Realm API" in file_metadata["source"] + assert file_metadata["source"] == "/openapi-admin-v3.yaml"