From ece735ae3203847e4b7b7d6c17d8d3a08e595070 Mon Sep 17 00:00:00 2001 From: Lars Falk-Petersen Date: Tue, 9 Jan 2024 15:28:23 +0100 Subject: [PATCH] Set response_model_exclude_unset=True for all. --- app/routes/collections_page.py | 14 +++++++++++--- app/routes/conformance_page.py | 6 ++++-- app/routes/instances_page.py | 6 +++++- app/routes/landing_page.py | 4 ++-- app/routes/position_page.py | 10 ++++++++-- app/test_app.py | 5 ++--- 6 files changed, 32 insertions(+), 13 deletions(-) diff --git a/app/routes/collections_page.py b/app/routes/collections_page.py index 117dfe7..3bcb4b7 100644 --- a/app/routes/collections_page.py +++ b/app/routes/collections_page.py @@ -159,20 +159,28 @@ def create_collection(collection_id: str = "", instance_id: str = "") -> dict: return isobaric_col.model_dump(exclude_none=True) -@router.get("/collections/", response_model=Collections) +@router.get( + "/collections/", response_model=Collections, response_model_exclude_unset=True +) async def get_collections_page() -> dict: """List collections as JSON. Isobaric is the only one available. No data is returned, only info about the collection.""" return create_collection() -@router.get("/collections/{collection_id}/", response_model=Collection) +@router.get( + "/collections/{collection_id}/", + response_model=Collection, + response_model_exclude_unset=True, +) async def get_collection_page(collection_id: CollectionID) -> dict: """List a specific collection as JSON. Isobaric is the only one available. No data is returned, only info about the collection..""" return create_collection(collection_id) @router.get( - "/collections/{collection_id}/instances/{instance_id}/", response_model=Collection + "/collections/{collection_id}/instances/{instance_id}/", + response_model=Collection, + response_model_exclude_unset=True, ) async def get_instance_collection_page( collection_id: CollectionID, diff --git a/app/routes/conformance_page.py b/app/routes/conformance_page.py index 588057c..2cbe0ca 100644 --- a/app/routes/conformance_page.py +++ b/app/routes/conformance_page.py @@ -22,7 +22,9 @@ def create_conformance_page() -> dict: router = APIRouter() -@router.get("/conformance/", response_model=ConformanceModel) -async def get_conformance_page(): +@router.get( + "/conformance/", response_model=ConformanceModel, response_model_exclude_unset=True +) +async def get_conformance_page() -> dict: """Returns the conformance page as JSON.""" return create_conformance_page() diff --git a/app/routes/instances_page.py b/app/routes/instances_page.py index 1a3dd62..114ad72 100644 --- a/app/routes/instances_page.py +++ b/app/routes/instances_page.py @@ -123,7 +123,11 @@ def create_instances() -> dict: return isobaric_inst.model_dump(exclude_none=True) -@router.get("/collections/isobaric/instances/", response_model=Instances) +@router.get( + "/collections/isobaric/instances/", + response_model=Instances, + response_model_exclude_unset=True, +) async def get_isobaric_instances_page() -> dict: """Return list of available instances as JSON.""" return create_instances() diff --git a/app/routes/landing_page.py b/app/routes/landing_page.py index 37c902a..fdd73d2 100644 --- a/app/routes/landing_page.py +++ b/app/routes/landing_page.py @@ -54,7 +54,7 @@ def create_landing_page(base_url) -> dict: router = APIRouter() -@router.get("/", response_model=LandingPageModel) -async def get_landing_page(): +@router.get("/", response_model=LandingPageModel, response_model_exclude_unset=True) +async def get_landing_page() -> dict: """Returns the landing page as JSON.""" return create_landing_page(base_url=BASE_URL) diff --git a/app/routes/position_page.py b/app/routes/position_page.py index 55a7424..66e8405 100644 --- a/app/routes/position_page.py +++ b/app/routes/position_page.py @@ -253,7 +253,11 @@ def check_coords_within_bounds(ds: xr.Dataset, point: Point) -> Tuple[bool, dict return True, {} -@router.get("/collections/isobaric/position/", response_model=Coverage) +@router.get( + "/collections/isobaric/position/", + response_model=Coverage, + response_model_exclude_unset=True, +) async def get_isobaric_page( request: Request, coords: Annotated[ @@ -290,7 +294,9 @@ async def get_isobaric_page( @router.get( - "/collections/isobaric/instances/{instance_id}/position", response_model=Coverage + "/collections/isobaric/instances/{instance_id}/position", + response_model=Coverage, + response_model_exclude_unset=True, ) async def get_instance_isobaric_page( request: Request, diff --git a/app/test_app.py b/app/test_app.py index 1fb3a1e..3eb06d3 100644 --- a/app/test_app.py +++ b/app/test_app.py @@ -18,9 +18,8 @@ def test_landingpage(self) -> None: def test_conformance(self) -> None: response = client.get("/conformance") self.assertEqual(response.status_code, 200) - self.assertIn( - '{"conformsTo":["http://www.opengis.net/spec/ogcapi-common-1/1.0/conf/core",', - response.text, + self.assertTrue( + "http://www.opengis.net/spec/ogcapi-edr-1/1.0/conf/core" in response.text, ) def test_collections(self) -> None: