Skip to content

Commit 79c8e3b

Browse files
committed
addd landing page
1 parent fabb398 commit 79c8e3b

File tree

3 files changed

+147
-0
lines changed

3 files changed

+147
-0
lines changed

ogc_api_processes_fastapi/main.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ def include_routers(
3737
fastapi.FastAPI
3838
FastAPI application including OGC API - Processes compliant routes.
3939
"""
40+
landing_page_router = routers.create_landing_page_router(client=client)
41+
app.include_router(landing_page_router)
42+
conformance_declaration_router = routers.create_conformance_declaration_router(
43+
client=client
44+
)
45+
app.include_router(conformance_declaration_router)
4046
processes_router = routers.create_processes_router(client=client)
4147
app.include_router(processes_router)
4248
jobs_router = routers.create_jobs_router(client=client)

ogc_api_processes_fastapi/models.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,23 @@ class Link(pydantic.BaseModel):
5151
title: Optional[str] = None
5252

5353

54+
class LandingPage(pydantic.BaseModel):
55+
title: Optional[str] = pydantic.Field(
56+
default=None, example="Example processing server"
57+
)
58+
description: Optional[str] = pydantic.Field(
59+
default=None,
60+
example="Example server implementing the OGC API - Processes 1.0 Standard",
61+
)
62+
links: List[Link]
63+
64+
65+
class ConfClass(pydantic.BaseModel):
66+
conformsTo: List[str] = pydantic.Field(
67+
example="http://www.opengis.net/spec/ogcapi-processes-1/1.0/conf/core"
68+
)
69+
70+
5471
class AdditionalParameters(Metadata):
5572
parameters: Optional[List[AdditionalParameter]] = None
5673

ogc_api_processes_fastapi/routers.py

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,84 @@ def make_links_to_job(
6262
return links
6363

6464

65+
def create_get_landing_page_endpoint(
66+
router: fastapi.APIRouter, client: clients.BaseClient
67+
) -> None:
68+
"""Add the `GET /` endpoint.
69+
70+
Parameters
71+
----------
72+
router : fastapi.APIRouter
73+
Router to which the endpoint should be added.
74+
client : clients.BaseClient
75+
Client implementing the `GET /processes` endpoint.
76+
"""
77+
78+
@router.get(
79+
"/",
80+
response_model=models.LandingPage,
81+
response_model_exclude_none=True,
82+
)
83+
def get_landing_page(request: fastapi.Request) -> models.LandingPage:
84+
"""Get the API landing page."""
85+
links = [
86+
models.Link(
87+
href=urllib.parse.urljoin(str(request.base_url), "openapi.json"),
88+
rel="service-desc",
89+
type="application/vnd.oai.openapi+json;version=3.0",
90+
title="OpenAPI service description",
91+
),
92+
models.Link(
93+
href=urllib.parse.urljoin(str(request.base_url), "conformance"),
94+
rel="http://www.opengis.net/def/rel/ogc/1.0/conformance",
95+
type="application/json",
96+
title="Conformance declaration",
97+
),
98+
models.Link(
99+
href=urllib.parse.urljoin(str(request.base_url), "processes"),
100+
rel="http://www.opengis.net/def/rel/ogc/1.0/processes",
101+
type="application/json",
102+
title="Metadata about the processes",
103+
),
104+
]
105+
landing_page = models.LandingPage(links=links)
106+
107+
return landing_page
108+
109+
110+
def create_get_conformance_endpoint(
111+
router: fastapi.APIRouter, client: clients.BaseClient
112+
) -> None:
113+
"""Add the `GET /conformance` endpoint.
114+
115+
Parameters
116+
----------
117+
router : fastapi.APIRouter
118+
Router to which the endpoint should be added.
119+
client : clients.BaseClient
120+
Client implementing the `GET /conformance` endpoint.
121+
"""
122+
123+
@router.get(
124+
"",
125+
response_model=models.ConfClass,
126+
response_model_exclude_none=True,
127+
)
128+
def get_conformance(request: fastapi.Request) -> models.ConfClass:
129+
"""Get the API conformance declaration page."""
130+
conformance = models.ConfClass(
131+
conformsTo=[
132+
"http://www.opengis.net/spec/ogcapi-processes-1/1.0/conf/core",
133+
"http://www.opengis.net/spec/ogcapi-processes-1/1.0/conf/ogc-process-description",
134+
"http://www.opengis.net/spec/ogcapi-processes-1/1.0/conf/job-list",
135+
"http://www.opengis.net/spec/ogcapi-processes-1/1.0/conf/json",
136+
"http://www.opengis.net/spec/ogcapi-processes-1/1.0/conf/oas30",
137+
]
138+
)
139+
140+
return conformance
141+
142+
65143
def create_get_processes_endpoint(
66144
router: fastapi.APIRouter, client: clients.BaseClient
67145
) -> None:
@@ -332,6 +410,52 @@ def get_job_results(job_id: str) -> Dict[str, Any]:
332410
return response
333411

334412

413+
def create_landing_page_router(client: clients.BaseClient) -> fastapi.APIRouter:
414+
"""Register the API router exposing the `/` endpoint.
415+
416+
Parameters
417+
----------
418+
client : clients.BaseClient
419+
Client implementing the API endpoints.
420+
421+
Returns
422+
-------
423+
fastapi.APIRouter
424+
Router exposing the `/` API endpoint.
425+
"""
426+
router = fastapi.APIRouter(
427+
prefix="",
428+
tags=["Capabilities"],
429+
)
430+
create_get_landing_page_endpoint(router=router, client=client)
431+
432+
return router
433+
434+
435+
def create_conformance_declaration_router(
436+
client: clients.BaseClient,
437+
) -> fastapi.APIRouter:
438+
"""Register the API router exposing the `/conformance` endpoint.
439+
440+
Parameters
441+
----------
442+
client : clients.BaseClient
443+
Client implementing the API endpoints.
444+
445+
Returns
446+
-------
447+
fastapi.APIRouter
448+
Router exposing the `/conformance` API endpoint.
449+
"""
450+
router = fastapi.APIRouter(
451+
prefix="/conformance",
452+
tags=["ConformanceDeclaration"],
453+
)
454+
create_get_conformance_endpoint(router=router, client=client)
455+
456+
return router
457+
458+
335459
def create_processes_router(client: clients.BaseClient) -> fastapi.APIRouter:
336460
"""Register the API router collecting the `/processes/...` endpoints.
337461

0 commit comments

Comments
 (0)