Skip to content

Commit

Permalink
fix docs pathing
Browse files Browse the repository at this point in the history
Signed-off-by: Teo Koon Peng <[email protected]>
  • Loading branch information
Teo Koon Peng committed Feb 28, 2024
1 parent 0d4201d commit 8ef23d7
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ghpages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
- name: Extract docs
run: |
. /rmf_demos_ws/install/setup.bash
pipenv run python3 scripts/extract_docs.py -o docs
pnpm run generate-docs
- name: Upload artifact
uses: actions/upload-pages-artifact@v1
with:
Expand Down
6 changes: 3 additions & 3 deletions packages/api-server/api_server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@ async def custom_swagger_ui_html():
openapi_url=openapi_url,
title=app.title + " - Swagger UI",
oauth2_redirect_url=app.swagger_ui_oauth2_redirect_url,
swagger_js_url="/static/swagger-ui-bundle.js",
swagger_css_url="/static/swagger-ui.css",
swagger_js_url=f"{app_config.public_url.geturl()}/static/swagger-ui-bundle.js",
swagger_css_url=f"{app_config.public_url.geturl()}/static/swagger-ui.css",
)


Expand All @@ -238,7 +238,7 @@ async def redoc_html():
return get_redoc_html(
openapi_url=openapi_url,
title=app.title + " - ReDoc",
redoc_js_url="/static/redoc.standalone.js",
redoc_js_url=f"{app_config.public_url.geturl()}/static/redoc.standalone.js",
)


Expand Down
3 changes: 2 additions & 1 deletion packages/api-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"test:cov": "../../scripts/pipenv run python -m coverage run scripts/test.py",
"test:report": "../../scripts/pipenv run python -m coverage html && xdg-open htmlcov/index.html",
"lint": "../../scripts/pipenv run pyright && ../../scripts/pipenv run pylint api_server --ignore=ros_pydantic,rmf_api",
"generate-models": "./generate-models.sh"
"generate-models": "./generate-models.sh",
"generate-docs": "RMF_API_SERVER_CONFIG=scripts/docs_config.py ../../scripts/pipenv run python scripts/extract_docs.py -o docs"
},
"devDependencies": {
"pipenv-install": "workspace:*"
Expand Down
11 changes: 11 additions & 0 deletions packages/api-server/scripts/docs_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import os

from api_server.default_config import config

here = os.path.dirname(__file__)

config.update(
{
"public_url": "/rmf-web",
}
)
11 changes: 7 additions & 4 deletions packages/api-server/scripts/extract_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,22 @@ def cleanup():

atexit.register(cleanup)
server_proc = subprocess.Popen(
("pnpm", "start"), cwd=f"{os.path.dirname(__file__)}/..", start_new_session=True
("python", "-m", "api_server"),
cwd=f"{os.path.dirname(__file__)}/..",
start_new_session=True,
)

time.sleep(5) # wait for server to be ready
outdir = f"{args.output}"
os.makedirs(outdir, exist_ok=True)

with urlopen("http://localhost:8000/docs") as resp:
base_url = "http://localhost:8000/rmf-web"
with urlopen(f"{base_url}/docs") as resp:
html: bytes = resp.read()
with open(f"{outdir}/index.html", "bw") as f:
f.write(html)

with urlopen("http://localhost:8000/openapi.json") as resp:
with urlopen(f"{base_url}/openapi.json") as resp:
openapi = json.loads(resp.read())
openapi["servers"] = [
{
Expand All @@ -54,7 +57,7 @@ def cleanup():
]

for p in files_to_download:
with urlopen(f"http://localhost:8000{p}") as resp:
with urlopen(f"{base_url}{p}") as resp:
fp = f"{outdir}{p}"
os.makedirs(os.path.dirname(fp), exist_ok=True)
with open(fp, "bw") as f:
Expand Down

0 comments on commit 8ef23d7

Please sign in to comment.