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/openapi endpoints #361

Merged
merged 5 commits into from
Jun 2, 2022
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
3 changes: 2 additions & 1 deletion aiida_optimade/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"page_limit": 15,
"page_limit_max": 500,
"base_url": null,
"root_path": null,
"provider": {
"prefix": "aiida",
"name": "AiiDA",
Expand All @@ -27,7 +28,7 @@
"type": "node_type",
"relationships": "attributes.something.non.existing",
"links": "attributes.something.non.existing",
"meta": "attributes.someting.non.existing"
"meta": "attributes.something.non.existing"
}
}
}
11 changes: 6 additions & 5 deletions aiida_optimade/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
links,
structures,
)
from aiida_optimade.utils import get_custom_base_url_path, OPEN_API_ENDPOINTS
from aiida_optimade.utils import OPEN_API_ENDPOINTS


if not Path(os.getenv("OPTIMADE_CONFIG_FILE", DEFAULT_CONFIG_FILE_PATH)).exists():
Expand All @@ -63,8 +63,9 @@
if CONFIG.debug:
LOGGER.info("DEBUG MODE")

DOCS_ENDPOINT_PREFIX = f"{get_custom_base_url_path()}{BASE_URL_PREFIXES['major']}"
APP = FastAPI(
base_url=CONFIG.base_url,
root_path=CONFIG.root_path,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we'd remove this it should read from CONFIG or we also explicitly set base_url.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removing root_path didn't work. So i added also base_url to be consistent

title="OPTIMADE API for AiiDA",
description=(
"The [Open Databases Integration for Materials Design (OPTIMADE) consortium]"
Expand All @@ -75,9 +76,9 @@
"reproducible."
),
version=__api_version__,
docs_url=f"{DOCS_ENDPOINT_PREFIX}{OPEN_API_ENDPOINTS['docs']}",
redoc_url=f"{DOCS_ENDPOINT_PREFIX}{OPEN_API_ENDPOINTS['redoc']}",
openapi_url=f"{DOCS_ENDPOINT_PREFIX}{OPEN_API_ENDPOINTS['openapi']}",
docs_url=f"{BASE_URL_PREFIXES['major']}{OPEN_API_ENDPOINTS['docs']}",
redoc_url=f"{BASE_URL_PREFIXES['major']}{OPEN_API_ENDPOINTS['redoc']}",
openapi_url=f"{BASE_URL_PREFIXES['major']}{OPEN_API_ENDPOINTS['openapi']}",
)


Expand Down
15 changes: 0 additions & 15 deletions aiida_optimade/utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from typing import Tuple
import urllib.parse

from optimade.models import DataType
from optimade.server.config import CONFIG


OPEN_API_ENDPOINTS = {
Expand Down Expand Up @@ -52,16 +50,3 @@ def retrieve_queryable_properties(
)

return properties, all_properties


def get_custom_base_url_path():
"""Return path part of custom base URL"""
if CONFIG.base_url is not None:
res = urllib.parse.urlparse(CONFIG.base_url).path
else:
res = urllib.parse.urlparse(CONFIG.base_url).path.decode()

while res.endswith("/"):
res = res[:-1]

return res