Skip to content

Commit

Permalink
chore: remove prefix in openapi merger
Browse files Browse the repository at this point in the history
  • Loading branch information
robcxyz committed Sep 30, 2024
1 parent 4b6bd19 commit 60bfcc7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
19 changes: 6 additions & 13 deletions icon_stats/api/v1/endpoints/openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,16 @@ async def get_merged_openapi_spec() -> dict:
now = datetime.now()
if _cache["data"] is not None and _cache["last_updated"] is not None:
elapsed_time = (now - _cache["last_updated"]).total_seconds()
if elapsed_time < config.CACHE_DURATION:
if elapsed_time < config.OPENAPI_CACHE_DURATION:
return _cache["data"]

endpoints_suffixes = [
'api/v1/docs/doc.json',
'api/v1/governance/docs/openapi.json',
'api/v1/contracts/docs/openapi.json',
'api/v1/statistics/docs/openapi.json',
schema_urls = [
config.OPENAPI_MAIN_ENDPOINT,
config.OPENAPI_CONTRACTS_ENDPOINT,
config.OPENAPI_GOVERNANCE_ENDPOINT,
config.OPENAPI_STATS_ENDPOINT,
]

schema_urls = get_openapi_urls(endpoint_suffixes=endpoints_suffixes,
base_url=config.OPENAPI_ENDPOINT_PREFIX)

output = get_merged_openapi(schema_urls=schema_urls)

# Update the cache
Expand All @@ -42,10 +39,6 @@ async def get_merged_openapi_spec() -> dict:
return output


def get_openapi_urls(endpoint_suffixes: List[str], base_url: str) -> List[str]:
return [f"{base_url}/{suffix}" for suffix in endpoint_suffixes]


def get_merged_openapi(schema_urls: List[str], title: str = _cache['title']) -> Dict:
schema_processor = OpenAPIProcessor(
fetch_schema=FetchSchema(),
Expand Down
7 changes: 5 additions & 2 deletions icon_stats/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,11 @@ class Settings(BaseSettings):
LOG_EXCLUDE_FIELDS: list[str] = []

# OpenAPI Merger
CACHE_DURATION: int = 300 # In seconds - 5 min
OPENAPI_ENDPOINT_PREFIX: str = "https://tracker.icon.community"
OPENAPI_CACHE_DURATION: int = 30 * 60 # In seconds
OPENAPI_MAIN_ENDPOINT: str = "https://tracker.icon.community/api/v1/docs/doc.json"
OPENAPI_CONTRACTS_ENDPOINT: str = "https://tracker.icon.community/api/v1/contracts/docs/openapi.json"
OPENAPI_GOVERNANCE_ENDPOINT: str = "https://tracker.icon.community/api/v1/governance/docs/openapi.json"
OPENAPI_STATS_ENDPOINT: str = "https://tracker.icon.community/api/v1/statistics/docs/openapi.json"

model_config = SettingsConfigDict(
case_sensitive=False,
Expand Down

0 comments on commit 60bfcc7

Please sign in to comment.