Skip to content

Commit

Permalink
Revert "DOP-3353: Change OpenAPI metadata source to be spec string (#428
Browse files Browse the repository at this point in the history
)" (#436)
  • Loading branch information
rayangler authored Jan 4, 2023
1 parent 9985c32 commit 6d69b28
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 23 deletions.
9 changes: 6 additions & 3 deletions snooty/postprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
28 changes: 8 additions & 20 deletions snooty/test_postprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
): """
Expand All @@ -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"
Expand Down Expand Up @@ -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")]
Expand All @@ -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"

0 comments on commit 6d69b28

Please sign in to comment.