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
Closes: #84
  • Loading branch information
pedro-psb committed Sep 10, 2024
1 parent 87a133c commit b94853d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/pulp_docs/mkdocs_macros.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
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
from pulp_docs.utils.general import get_label

# the name of the docs in the source repositories
SRC_DOCS_DIRNAME = "staging_docs"
Expand Down Expand Up @@ -152,13 +152,11 @@ def _download_api_json(api_dir: Path, repo_name: str):
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))
app_label = get_label(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
11 changes: 11 additions & 0 deletions src/pulp_docs/utils/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@
from pathlib import Path


def get_label(repo_name: str):
"""Get app_label from repo_name.
E.g: 'pulp_ostree' -> 'ostree'.
"""
if repo_name == "pulpcore":
return "core"
# E.g: "pulp-ostree" -> "pulp_ostree" -> ("", "pulp_", "ostree")
return repo_name.replace("-", "_").rpartition("pulp_")[2]


def get_git_ignored_files(repo_path: Path) -> t.List[str]:
"""Get list of ignored files as defined in the repo .gitignore"""
repo_gitignore = Path(repo_path / ".gitignore")
Expand Down

0 comments on commit b94853d

Please sign in to comment.