Skip to content

Commit 5ad6933

Browse files
authored
Fix rest_api spec being fetched from outdated link
On the time of the docs transitioning pulp-docs was using the legacy server as a source of the api.json, which were doomed to become outdated. This was mostly to keep CI working while the solution was being implemented. Now that the api schemas for docs are being generated in pulp-docs repo, we can use that as the up-to-date source. Closes: #84
1 parent 87a133c commit 5ad6933

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

src/pulp_docs/mkdocs_macros.py

+5-9
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
from pulp_docs.constants import SECTION_REPO
3232
from pulp_docs.navigation import get_navigation
3333
from pulp_docs.repository import Repo, Repos, SubPackage
34-
from pulp_docs.utils.general import get_git_ignored_files
3534

3635
# the name of the docs in the source repositories
3736
SRC_DOCS_DIRNAME = "staging_docs"
@@ -122,7 +121,7 @@ def prepare_repositories(TMPDIR: Path, repos: Repos, config: Config):
122121

123122
# restapi
124123
if has_restapi(repo_or_pkg):
125-
_download_api_json(api_src_dir, repo_or_pkg.name)
124+
_download_api_json(api_src_dir, repo_or_pkg.name, repo_or_pkg.app_label)
126125
_generate_rest_api_page(this_src_dir, repo_or_pkg.name, repo_or_pkg.title)
127126

128127
# install and post-process
@@ -145,20 +144,17 @@ def prepare_repositories(TMPDIR: Path, repos: Repos, config: Config):
145144
return (repo_docs, repo_sources)
146145

147146

148-
def _download_api_json(api_dir: Path, repo_name: str):
147+
def _download_api_json(api_dir: Path, repo_name: str, app_label: str):
149148
api_json_path = api_dir / f"{repo_name}/api.json"
150149
if api_json_path.exists():
151150
log.info(f"{repo_name} api.json already downloaded.")
152151
return
153152

154153
log.info(f"Downloading api.json for {repo_name}")
155-
api_url_1 = "https://pulpproject.org/{repo_name}/api.json"
156-
api_url_2 = "https://pulpproject.org/{repo_name}/_static/api.json"
157-
response = httpx.get(api_url_1.format(repo_name=repo_name))
154+
api_url = f"https://raw.githubusercontent.com/pulp/pulp-docs/docs-data/data/openapi_json/{app_label}-api.json"
155+
response = httpx.get(api_url)
158156
if response.is_error:
159-
response = httpx.get(api_url_2.format(repo_name=repo_name))
160-
if response.is_error:
161-
raise Exception("Couldnt get rest api page")
157+
raise Exception("Couldnt get rest api schema for {app_label}")
162158

163159
# Schema overrides for better display
164160
json_file_content = response.json()

src/pulp_docs/repository.py

+16
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ class Repo:
6767
type: t.Optional[str] = None
6868
dev_only: bool = False
6969
version: t.Optional[str] = None
70+
template_config: t.Optional[dict] = None
71+
app_label: t.Optional[str] = None
7072

7173
def __post_init__(self):
7274
self.branch_in_use = self.branch_in_use or self.branch
@@ -158,6 +160,19 @@ def download(
158160
.get("current_version")
159161
)
160162

163+
# update app_label for app plugins
164+
template_config_file = src_copy_path / "template_config.yml"
165+
if template_config_file.exists():
166+
self.template_config = yaml.load(
167+
template_config_file.read_bytes(), Loader=yaml.SafeLoader
168+
)
169+
app_label_map = {
170+
p["name"]: p["app_label"] for p in self.template_config["plugins"]
171+
}
172+
subpackages = self.subpackages or []
173+
for plugin in (self, *subpackages):
174+
plugin.app_label = app_label_map.get(plugin.name, None)
175+
161176
self.status.download_source = str(download_from)
162177
return self.status.download_source
163178

@@ -231,6 +246,7 @@ class SubPackage:
231246
owner = ""
232247
dev_only: bool = False
233248
version: t.Optional[str] = None
249+
app_label: t.Optional[str] = None
234250

235251

236252
@dataclass

0 commit comments

Comments
 (0)