Skip to content

Commit 5fdbdd3

Browse files
authored
DOP-3353: Change OpenAPI metadata source to be spec string (#428)
1 parent 144386d commit 5fdbdd3

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

snooty/postprocess.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -959,18 +959,15 @@ def enter_node(self, fileid_stack: FileIdStack, node: n.Node) -> None:
959959
return
960960

961961
source = ""
962-
argument = node.argument[0]
963962
# The parser determines the source_type based on the given argument and its
964963
# node structure. We echo that logic here to grab the source without needing
965964
# to worry about the argument's node structure.
966965
# The source_type cannot be manually set in rST as long as the option is not exposed
967966
# in the rstspec.
968-
if source_type == "local" or source_type == "atlas":
969-
assert isinstance(argument, n.Text)
970-
source = argument.get_text()
967+
if source_type == "local" or source_type == "url":
968+
source = node.children[0].get_text()
971969
else:
972-
assert isinstance(argument, n.Reference)
973-
source = argument.refuri
970+
source = node.argument[0].get_text()
974971

975972
self.openapi_pages[current_slug] = self.SourceData(source_type, source)
976973

snooty/test_postprocess.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2469,7 +2469,14 @@ def test_openapi_metadata() -> None:
24692469
24702470
.. openapi:: /openapi-admin-v3.yaml
24712471
""",
2472-
Path("source/openapi-admin-v3.yaml"): "",
2472+
Path(
2473+
"source/openapi-admin-v3.yaml"
2474+
): """
2475+
openapi: "3.0.1"
2476+
info:
2477+
description: ""
2478+
title: MongoDB Realm API
2479+
""",
24732480
Path(
24742481
"source/admin/api/url.txt"
24752482
): """
@@ -2487,17 +2494,15 @@ def test_openapi_metadata() -> None:
24872494
diagnostics for diagnostics in result.diagnostics.values() if diagnostics
24882495
], "Should not raise any diagnostics"
24892496
openapi_pages = cast(Dict[str, Any], result.metadata["openapi_pages"])
2497+
spec_title = "MongoDB Realm API"
24902498

24912499
local_file_page = openapi_pages["admin/api/v3"]
24922500
assert local_file_page["source_type"] == "local"
2493-
assert local_file_page["source"] == "/openapi-admin-v3.yaml"
2501+
assert spec_title in local_file_page["source"]
24942502

24952503
url_page = openapi_pages["admin/api/url"]
24962504
assert url_page["source_type"] == "url"
2497-
assert (
2498-
url_page["source"]
2499-
== "https://raw.githubusercontent.com/mongodb/snooty-parser/master/test_data/test_parser/openapi-admin-v3.yaml"
2500-
)
2505+
assert spec_title in url_page["source"]
25012506

25022507
atlas_page = openapi_pages["admin/api/atlas"]
25032508
assert atlas_page["source_type"] == "atlas"
@@ -2531,7 +2536,14 @@ def test_openapi_duplicates() -> None:
25312536
25322537
.. openapi:: https://raw.githubusercontent.com/mongodb/snooty-parser/master/test_data/test_parser/openapi-admin-v3.yaml
25332538
""",
2534-
Path("source/openapi-admin-v3.yaml"): "",
2539+
Path(
2540+
"source/openapi-admin-v3.yaml"
2541+
): """
2542+
openapi: "3.0.1"
2543+
info:
2544+
description: ""
2545+
title: MongoDB Realm API
2546+
""",
25352547
}
25362548
) as result:
25372549
diagnostics = result.diagnostics[FileId("admin/api/v3.txt")]
@@ -2542,4 +2554,4 @@ def test_openapi_duplicates() -> None:
25422554
# First openapi directive should be source of truth
25432555
file_metadata = openapi_pages["admin/api/v3"]
25442556
assert file_metadata["source_type"] == "local"
2545-
assert file_metadata["source"] == "/openapi-admin-v3.yaml"
2557+
assert "MongoDB Realm API" in file_metadata["source"]

0 commit comments

Comments
 (0)