Skip to content

Commit

Permalink
Set response_model_exclude_unset=True for all.
Browse files Browse the repository at this point in the history
  • Loading branch information
ways committed Jan 9, 2024
1 parent 418ec88 commit ece735a
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 13 deletions.
14 changes: 11 additions & 3 deletions app/routes/collections_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 4 additions & 2 deletions app/routes/conformance_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
6 changes: 5 additions & 1 deletion app/routes/instances_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
4 changes: 2 additions & 2 deletions app/routes/landing_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
10 changes: 8 additions & 2 deletions app/routes/position_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -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[
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 2 additions & 3 deletions app/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit ece735a

Please sign in to comment.