Skip to content

Commit

Permalink
API: Change media type of GeoJSON response
Browse files Browse the repository at this point in the history
The media type for GeoJSON text is "application/geo+json".
  • Loading branch information
matthiasschaub committed Oct 25, 2021
1 parent 4daf470 commit c8c75df
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 3 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## Current Main

### Other Changes

- API: Change media type of GeoJSON response ([#199])

[#199]: https://github.com/GIScience/ohsome-quality-analyst/pull/199


## 0.6.0

### Breaking Changes
Expand Down
15 changes: 12 additions & 3 deletions workers/ohsome_quality_analyst/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

import pydantic
from fastapi import FastAPI
from fastapi.encoders import jsonable_encoder
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import JSONResponse

from ohsome_quality_analyst import (
__author__,
Expand Down Expand Up @@ -140,7 +142,9 @@ async def _fetch_indicator(
)
response = empty_api_response()
response.update(geojson_object)
return response
return JSONResponse(
content=jsonable_encoder(response), media_type="application/geo+json"
)


@app.get("/report/{name}")
Expand Down Expand Up @@ -205,7 +209,9 @@ async def _fetch_report(name: str, parameters: ReportRequestModel):
)
response = empty_api_response()
response.update(geojson_object)
return response
return JSONResponse(
content=jsonable_encoder(response), media_type="application/geo+json"
)


@app.get("/regions")
Expand All @@ -219,9 +225,12 @@ async def get_available_regions(asGeoJSON: bool = False):
if asGeoJSON is True:
regions = await db_client.get_regions_as_geojson()
response.update(regions)
return JSONResponse(
content=jsonable_encoder(response), media_type="application/geo+json"
)
else:
response["result"] = await db_client.get_regions()
return response
return response


@app.get("/indicatorLayerCombinations")
Expand Down
1 change: 1 addition & 0 deletions workers/tests/integrationtests/test_api_indicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def setUp(self):

def run_tests(self, response) -> None:
self.assertEqual(response.status_code, 200)
self.assertEqual(response.headers["content-type"], "application/geo+json")
for schema in (self.general_schema, self.feature_schema):
self.validate(response.json(), schema)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def setUp(self):

def run_tests(self, response, schemata: Tuple[Schema]) -> None:
self.assertEqual(response.status_code, 200)
self.assertEqual(response.headers["content-type"], "application/geo+json")
for schema in schemata:
self.validate(response.json(), schema)

Expand Down
1 change: 1 addition & 0 deletions workers/tests/integrationtests/test_api_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def setUp(self):

def run_tests(self, response) -> None:
self.assertEqual(response.status_code, 200)
self.assertEqual(response.headers["content-type"], "application/geo+json")
response_content = geojson.loads(response.content)
self.assertTrue(response_content.is_valid) # Valid GeoJSON?
self.assertTrue(self.general_schema.is_valid(response_content))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def setUp(self):

def run_tests(self, response) -> None:
self.assertEqual(response.status_code, 200)
self.assertEqual(response.headers["content-type"], "application/geo+json")

response_content = geojson.loads(response.content)
self.assertTrue(response_content.is_valid) # Valid GeoJSON?
Expand Down

0 comments on commit c8c75df

Please sign in to comment.