Skip to content

Commit 1a173f8

Browse files
committed
add file formats and parse them into the api core
1 parent 4c3d0be commit 1a173f8

File tree

6 files changed

+119
-4
lines changed

6 files changed

+119
-4
lines changed

openeo_fastapi/api/app.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,21 @@ def register_get_conformance(self):
6464
endpoint=self.client.get_conformance,
6565
)
6666

67+
def register_get_file_formats(self):
68+
"""Register conformance page (GET /file_formats).
69+
Returns:
70+
None
71+
"""
72+
self.router.add_api_route(
73+
name="conformance",
74+
path=f"/{self.client.settings.OPENEO_VERSION}/file_formats",
75+
response_model=responses.FileFormatsGetResponse,
76+
response_model_exclude_unset=False,
77+
response_model_exclude_none=True,
78+
methods=["GET"],
79+
endpoint=self.client.get_file_formats,
80+
)
81+
6782
def register_get_collections(self):
6883
"""Register collection Endpoint (GET /collections).
6984
Returns:
@@ -352,6 +367,7 @@ def register_core(self):
352367
None
353368
"""
354369
self.register_get_conformance()
370+
self.register_get_file_formats()
355371
self.register_get_collections()
356372
self.register_get_collection()
357373
self.register_get_processes()

openeo_fastapi/api/responses.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import uuid
22
from enum import Enum
3-
from typing import Any, Optional, TypedDict, Union
3+
from typing import Any, Dict, List, Optional, TypedDict, Union
44

55
from pydantic import AnyUrl, BaseModel, Extra, Field, validator
66

77
from openeo_fastapi.api.types import (
88
Billing,
99
Endpoint,
1010
File,
11+
FileFormat,
1112
Link,
1213
Process,
1314
RFC3339Datetime,
@@ -457,3 +458,16 @@ class JobsGetEstimateGetResponse(BaseModel):
457458
class FilesGetResponse(BaseModel):
458459
files: list[File]
459460
links: list[Link]
461+
462+
463+
class FileFormatsGetResponse(BaseModel):
464+
input: dict[str, FileFormat] = Field(
465+
...,
466+
description="Map of supported input file formats, i.e. file formats a back-end can **read** from. The property keys are the file format names that are used by clients and users, for example in process graphs.",
467+
title="Input File Formats",
468+
)
469+
output: dict[str, FileFormat] = Field(
470+
...,
471+
description="Map of supported output file formats, i.e. file formats a back-end can **write** to. The property keys are the file format names that are used by clients and users, for example in process graphs.",
472+
title="Output File Formats",
473+
)

openeo_fastapi/api/types.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import datetime
22
from enum import Enum
33
from pathlib import Path
4-
from typing import Any, List, Optional, Union
4+
from typing import Any, Dict, List, Optional, Union
55

66
from pydantic import AnyUrl, BaseModel, Extra, Field, validator
77

@@ -57,6 +57,13 @@ class Level(Enum):
5757
debug = "debug"
5858

5959

60+
class GisDataType(Enum):
61+
raster = "raster"
62+
vector = "vector"
63+
table = "table"
64+
other = "other"
65+
66+
6067
class RFC3339Datetime(BaseModel):
6168
"""Class to consistently represent datetimes as strings compliant to RFC3339Datetime."""
6269

@@ -317,3 +324,23 @@ class Error(BaseModel):
317324
example="Parameter 'sample' is missing.",
318325
)
319326
links: Optional[list[Link]] = None
327+
328+
329+
class FileFormat(BaseModel):
330+
title: str
331+
description: Optional[str] = None
332+
gis_data_types: list[GisDataType] = Field(
333+
...,
334+
description="Specifies the supported GIS spatial data types for this format.\nIt is RECOMMENDED to specify at least one of the data types, which will likely become a requirement in a future API version.",
335+
)
336+
deprecated: Optional[bool] = None
337+
experimental: Optional[bool] = None
338+
parameters: dict[str, Any] = Field(
339+
...,
340+
description="Specifies the supported parameters for this file format.",
341+
title="File Format Parameters",
342+
)
343+
links: Optional[list[Link]] = Field(
344+
None,
345+
description="Links related to this file format, e.g. external documentation.\n\nFor relation types see the lists of\n[common relation types in openEO](#section/API-Principles/Web-Linking).",
346+
)

openeo_fastapi/client/core.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ class OpenEOCore:
1818
"""Base client for the OpenEO Api."""
1919

2020
billing: str = field()
21+
input_formats: list = field()
22+
output_formats: list = field()
2123
links: list = field()
2224

2325
settings = AppSettings()
@@ -97,3 +99,10 @@ def get_conformance(self) -> responses.ConformanceGetResponse:
9799
return responses.ConformanceGetResponse(
98100
conformsTo=conformance.BASIC_CONFORMANCE_CLASSES
99101
)
102+
103+
def get_file_formats(self) -> responses.FileFormatsGetResponse:
104+
""" """
105+
return responses.FileFormatsGetResponse(
106+
input={_format.title: _format for _format in self.input_formats},
107+
output={_format.title: _format for _format in self.output_formats},
108+
)

tests/api/test_api.py

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,15 @@
55

66
from openeo_fastapi.api.app import OpenEOApi
77
from openeo_fastapi.api.responses import FilesGetResponse
8-
from openeo_fastapi.api.types import Billing, Endpoint, File, Link, Plan
8+
from openeo_fastapi.api.types import (
9+
Billing,
10+
Endpoint,
11+
File,
12+
FileFormat,
13+
GisDataType,
14+
Link,
15+
Plan,
16+
)
917
from openeo_fastapi.client.auth import Authenticator, User
1018
from openeo_fastapi.client.core import OpenEOCore
1119
from openeo_fastapi.client.files import FILE_ENDPOINTS, FilesRegister
@@ -42,6 +50,18 @@ def test_get_conformance(core_api, app_settings):
4250
assert len(BASIC_CONFORMANCE_CLASSES) == len(response.json()["conformsTo"])
4351

4452

53+
def test_get_file_formats(core_api, app_settings):
54+
"""Test the /conformance endpoint as intended."""
55+
56+
from openeo_fastapi.client.conformance import BASIC_CONFORMANCE_CLASSES
57+
58+
test_app = TestClient(core_api.app)
59+
60+
response = test_app.get(f"/{app_settings.OPENEO_VERSION}/file_formats")
61+
62+
assert response.status_code == 200
63+
64+
4565
def test_exception_handler(core_api):
4666
test_client = TestClient(core_api.app)
4767

@@ -98,7 +118,17 @@ def list_files(
98118

99119
extended_register = ExtendedFileRegister(app_settings, test_links)
100120

121+
formats = [
122+
FileFormat(
123+
title="json",
124+
gis_data_types=[GisDataType("vector")],
125+
parameters={},
126+
)
127+
]
128+
101129
client = OpenEOCore(
130+
input_formats=formats,
131+
output_formats=formats,
102132
links=[
103133
Link(
104134
href="https://eodc.eu/",
@@ -171,7 +201,17 @@ def get_file_headers(
171201
assert len(extended_register.endpoints) == 5
172202
assert new_endpoint in extended_register.endpoints
173203

204+
formats = [
205+
FileFormat(
206+
title="json",
207+
gis_data_types=[GisDataType("vector")],
208+
parameters={},
209+
)
210+
]
211+
174212
client = OpenEOCore(
213+
input_formats=formats,
214+
output_formats=formats,
175215
links=[
176216
Link(
177217
href="https://eodc.eu/",

tests/conftest.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
os.environ["OIDC_ROLES"] = "tester,developer"
4545

4646
from openeo_fastapi.api.app import OpenEOApi
47-
from openeo_fastapi.api.types import Billing, Link, Plan
47+
from openeo_fastapi.api.types import Billing, FileFormat, GisDataType, Link, Plan
4848
from openeo_fastapi.client import auth, settings
4949
from openeo_fastapi.client.core import CollectionRegister, OpenEOCore
5050

@@ -56,7 +56,16 @@ def app_settings():
5656

5757
@pytest.fixture()
5858
def core_api():
59+
formats = [
60+
FileFormat(
61+
title="json",
62+
gis_data_types=[GisDataType("vector")],
63+
parameters={},
64+
)
65+
]
5966
client = OpenEOCore(
67+
input_formats=formats,
68+
output_formats=formats,
6069
links=[
6170
Link(
6271
href="https://eodc.eu/",

0 commit comments

Comments
 (0)