Skip to content

Commit

Permalink
Fix rest_api spec being fetched from outdated link
Browse files Browse the repository at this point in the history
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
  • Loading branch information
pedro-psb committed Sep 10, 2024
1 parent 87a133c commit 5ad6933
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/pulp_docs/mkdocs_macros.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
from pulp_docs.constants import SECTION_REPO
from pulp_docs.navigation import get_navigation
from pulp_docs.repository import Repo, Repos, SubPackage
from pulp_docs.utils.general import get_git_ignored_files

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

# restapi
if has_restapi(repo_or_pkg):
_download_api_json(api_src_dir, repo_or_pkg.name)
_download_api_json(api_src_dir, repo_or_pkg.name, repo_or_pkg.app_label)
_generate_rest_api_page(this_src_dir, repo_or_pkg.name, repo_or_pkg.title)

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


def _download_api_json(api_dir: Path, repo_name: str):
def _download_api_json(api_dir: Path, repo_name: str, app_label: str):
api_json_path = api_dir / f"{repo_name}/api.json"
if api_json_path.exists():
log.info(f"{repo_name} api.json already downloaded.")
return

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

# Schema overrides for better display
json_file_content = response.json()
Expand Down
16 changes: 16 additions & 0 deletions src/pulp_docs/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ class Repo:
type: t.Optional[str] = None
dev_only: bool = False
version: t.Optional[str] = None
template_config: t.Optional[dict] = None
app_label: t.Optional[str] = None

def __post_init__(self):
self.branch_in_use = self.branch_in_use or self.branch
Expand Down Expand Up @@ -158,6 +160,19 @@ def download(
.get("current_version")
)

# update app_label for app plugins
template_config_file = src_copy_path / "template_config.yml"
if template_config_file.exists():
self.template_config = yaml.load(
template_config_file.read_bytes(), Loader=yaml.SafeLoader
)
app_label_map = {
p["name"]: p["app_label"] for p in self.template_config["plugins"]
}
subpackages = self.subpackages or []
for plugin in (self, *subpackages):
plugin.app_label = app_label_map.get(plugin.name, None)

self.status.download_source = str(download_from)
return self.status.download_source

Expand Down Expand Up @@ -231,6 +246,7 @@ class SubPackage:
owner = ""
dev_only: bool = False
version: t.Optional[str] = None
app_label: t.Optional[str] = None


@dataclass
Expand Down

0 comments on commit 5ad6933

Please sign in to comment.