Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix rest_api spec being fetched from outdated link #85

Merged
merged 2 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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