Skip to content

Commit ddc473d

Browse files
authored
Merge pull request #9 from Ensembl/resolver-homepage
Use APISpec doc instead of default
2 parents 063dcf1 + 691679e commit ddc473d

File tree

5 files changed

+41
-14
lines changed

5 files changed

+41
-14
lines changed

app/api/models/resolver.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class SearchPayload(BaseModel):
1515

1616
class SearchMatch(BaseModel):
1717
genome: str
18+
unversioned_stable_id: str
1819

1920

2021
class SearchResult(BaseModel):

app/api/resources/resolver_view.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ async def resolve(
5151
continue
5252

5353
if app == "entity-viewer":
54-
url = f"{ENSEMBL_URL}/{app}/{genome_id}/{type}:{stable_id}"
54+
url = f"{ENSEMBL_URL}/{app}/{genome_id}/{type}:{metadata['unversioned_stable_id']}"
5555
else:
56-
url = f"{ENSEMBL_URL}/{app}/{genome_id}?focus={type}:{stable_id}"
56+
url = f"{ENSEMBL_URL}/{app}/{genome_id}?focus={type}:{metadata['unversioned_stable_id']}"
5757

5858
metadata["resolved_url"] = url
5959
resolved_payload = ResolvedPayload(**metadata)

app/api/utils/metadata.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ def get_metadata(matches: List[SearchMatch] = []):
1818
) as response:
1919
response.raise_for_status()
2020
metadata_results[genome_id] = response.json()
21+
metadata_results[genome_id]["unversioned_stable_id"] = match.get(
22+
"unversioned_stable_id"
23+
)
2124
except requests.exceptions.HTTPError as HTTPError:
2225
logger.error(f"HTTPError: {HTTPError}")
2326
return None

app/main.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,21 @@
1818
from fastapi import FastAPI
1919
from starlette.middleware.cors import CORSMiddleware
2020
from fastapi.staticfiles import StaticFiles
21+
from fastapi.openapi.docs import get_swagger_ui_html
2122

2223
from api.resources.routes import router
2324
from core.config import API_PREFIX, ALLOWED_HOSTS, VERSION, PROJECT_NAME, DEBUG
2425

2526

2627
def get_application() -> FastAPI:
27-
application = FastAPI(title=PROJECT_NAME, debug=DEBUG, version=VERSION)
28+
application = FastAPI(
29+
title=PROJECT_NAME,
30+
debug=DEBUG,
31+
version=VERSION,
32+
openapi_url=None, # Disable the default OpenAPI spec generation
33+
docs_url=None, # Disable the default Swagger UI docs
34+
redoc_url=None, # Disable the default ReDoc UI
35+
)
2836

2937
application.add_middleware(
3038
CORSMiddleware,
@@ -41,3 +49,10 @@ def get_application() -> FastAPI:
4149

4250
app = get_application()
4351
app.mount("/static", StaticFiles(directory="static"), name="static_files")
52+
53+
54+
@app.get("/", include_in_schema=False)
55+
async def custom_swagger_ui_html():
56+
return get_swagger_ui_html(
57+
openapi_url="/static/APISpecification.yaml", title="API Docs"
58+
)

APISpecification.yaml renamed to app/static/APISpecification.yaml

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ tags:
1313
paths:
1414
/id/{stable_id}:
1515
get:
16+
tags:
17+
- resolver
1618
summary: Resolve stable ID with optional query params
1719
description: Resolves to a beta url when a stable id wih optional query params provided
1820
parameters:
@@ -39,9 +41,9 @@ paths:
3941
required: false
4042
schema:
4143
type: string
42-
enum: [genome_browser, entity_viewer]
44+
enum: [genome-browser, entity-viewer]
4345
example:
44-
genome_browser
46+
genome-browser
4547
- name: gca
4648
in: query
4749
description: GCA assembly accession id of the genome
@@ -64,18 +66,24 @@ paths:
6466
items:
6567
type: object
6668
properties:
67-
assembly_name:
69+
assembly:
70+
type: object
71+
properties:
72+
name:
73+
type: string
74+
description: Assembly name
75+
accession_id:
76+
type: string
77+
description: Assembly accession id
78+
scientific_name:
6879
type: string
69-
description: Assembly name
70-
accession_id:
80+
description: Species scientific name
81+
common_name:
7182
type: string
72-
description: Assembly accession id
73-
species_scientific_name:
83+
description: Species common name
84+
type:
7485
type: string
75-
description: Species scientific name
76-
taxonomy_id:
77-
type: integer
78-
description: Taxonomy id
86+
description: Genome type
7987
resolved_url:
8088
type: string
8189
description: Resolved url to Ensembl site

0 commit comments

Comments
 (0)