diff --git a/CHANGELOG.md b/CHANGELOG.md index 67ec2c1..da36050 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,14 @@ and uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - --> +------ +## [1.0.5](https://github.com/asfadmin/Discovery-SearchAPI-v3/compare/v1.0.4...v1.0.5) +### Added +- Added `json` output format support + +### Changed +- bump asf-search to v9.0.6 + ------ ## [1.0.5](https://github.com/asfadmin/Discovery-SearchAPI-v3/compare/v1.0.4...v1.0.5) ### Added diff --git a/requirements.txt b/requirements.txt index 01b83c9..6a1e18c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -22,7 +22,7 @@ ujson==5.7.0 uvicorn==0.21.1 watchfiles==0.19.0 -asf_search==9.0.4 +asf_search==9.0.6 python-json-logger==2.0.7 asf_enumeration diff --git a/src/SearchAPI/application/output.py b/src/SearchAPI/application/output.py index 4101991..37d3c39 100644 --- a/src/SearchAPI/application/output.py +++ b/src/SearchAPI/application/output.py @@ -66,11 +66,18 @@ def as_output(results: asf.ASFSearchResults, output: str) -> dict: output_format = output.lower() - if output_format == "json": - output_format = "jsonlite" # Use a switch statement, so you only load the type of output you need: match output_format: + case 'json': + return { + 'content': ''.join(results.json()), + 'media_type': 'application/json; charset=utf-8', + 'headers': { + **constants.DEFAULT_HEADERS, + 'Content-Disposition': f"attachment; filename={make_filename('json')}", + } + } case 'jsonlite': return { 'content': ''.join(results.jsonlite()), diff --git a/tests/yml_tests/test_Baseline.yml b/tests/yml_tests/test_Baseline.yml index b6b7ab4..8adeccb 100644 --- a/tests/yml_tests/test_Baseline.yml +++ b/tests/yml_tests/test_Baseline.yml @@ -113,7 +113,7 @@ tests: output: json # use_maturity: True - expected file: jsonlite # dropping json output + expected file: json # dropping json output expected code: 200 - no output specified: diff --git a/tests/yml_tests/test_URLs.yml b/tests/yml_tests/test_URLs.yml index a2cb564..4ec019b 100644 --- a/tests/yml_tests/test_URLs.yml +++ b/tests/yml_tests/test_URLs.yml @@ -258,7 +258,7 @@ tests: maxresults: 100 output: json - expected file: jsonlite + expected file: json expected code: 200 - collectionName Big Island 100: @@ -266,7 +266,7 @@ tests: maxresults: 100 output: json - expected file: jsonlite + expected file: json expected code: 200 - collectionName Cascade 100: @@ -274,7 +274,7 @@ tests: maxresults: 100 output: json - expected file: jsonlite + expected file: json expected code: 200 - end csv: @@ -375,7 +375,7 @@ tests: maxresults: 10 output: json - expected file: jsonlite + expected file: json expected code: 200 - flightLine Bonanza Creek: @@ -383,7 +383,7 @@ tests: maxresults: 10 output: json - expected file: jsonlite + expected file: json expected code: 200 - frame list range: @@ -444,7 +444,7 @@ tests: granule_list: S1B_S6_GRDH_1SDV_20190911T214309_20190911T214338_017995_021E10_5CCB output: json - expected file: jsonlite + expected file: json expected code: 200 - granule_list single geojson: @@ -463,42 +463,42 @@ tests: groupid: S1B_S1DV_0492_0497_017567_041 output: json - expected file: jsonlite + expected file: json expected code: 200 - groupid S1 Insar: groupid: S1-GUNW-D-R-087-tops-20190816_20190804-161614-19149N_17138N-PP-fee7-v2_0_2 output: json - expected file: jsonlite + expected file: json expected code: 200 - groupid SMAP: groupid: SP_24535_A_006 output: json - expected file: jsonlite + expected file: json expected code: 200 - groupid UAVSAR: groupid: UA_ChiVol_00700_15030_010_150330_L090_CX_01 output: json - expected file: jsonlite + expected file: json expected code: 200 - groupid ALOS PALSAR: groupid: ALPSRP279071100 output: json - expected file: jsonlite + expected file: json expected code: 200 - groupid AIRSAR: groupid: ts1899 output: json - expected file: jsonlite + expected file: json expected code: 200 - instrument alos palsar: @@ -506,7 +506,7 @@ tests: maxResults: 20 output: json - expected file: jsonlite + expected file: json expected code: 200 - instrument alos avnir: @@ -514,7 +514,7 @@ tests: maxResults: 20 output: json - expected file: jsonlite + expected file: json expected code: 200 - instrument alos avnir jsonlite: @@ -693,7 +693,7 @@ tests: maxResults: 10 output: json - expected file: jsonlite + expected file: json expected code: 200 - lookDirection L: @@ -701,7 +701,7 @@ tests: maxResults: 10 output: json - expected file: jsonlite + expected file: json expected code: 200 - lookDirection RIGHT: @@ -709,15 +709,15 @@ tests: maxResults: 10 output: json - expected file: jsonlite + expected file: json expected code: 200 - lookDirection R: lookDirection: R maxResults: 10 - output: JSON + output: json - expected file: jsonlite + expected file: json expected code: 200 - maxBaselinePerp: @@ -830,7 +830,7 @@ tests: maxResults: 1 output: json - expected file: jsonlite + expected file: json expected code: 200 - maxResults 2 json: @@ -838,7 +838,7 @@ tests: maxResults: 2 output: json - expected file: jsonlite + expected file: json expected code: 200 - maxResults 1 geojson: @@ -983,7 +983,7 @@ tests: maxResults: 100 output: json - expected file: jsonlite + expected file: json expected code: 200 - output jsonlite: @@ -1098,9 +1098,9 @@ tests: - platform R1: platform: R1 maxResults: 10 - output: jSoN + output: json - expected file: jsonlite + expected file: json expected code: 200 - platform R1 2: @@ -1783,7 +1783,7 @@ tests: maxResults: 10 output: json - expected file: jsonlite + expected file: json expected code: 200 - polarization VV: @@ -1792,7 +1792,7 @@ tests: maxResults: 10 output: json - expected file: jsonlite + expected file: json expected code: 200 - polarization HH HV: @@ -1800,7 +1800,7 @@ tests: maxResults: 10 output: json - expected file: jsonlite + expected file: json expected code: 200 - polarization Dual VV: @@ -1808,7 +1808,7 @@ tests: maxResults: 10 output: json - expected file: jsonlite + expected file: json expected code: 200 - polarization QUADRATURE: @@ -1816,7 +1816,7 @@ tests: maxResults: 10 output: json - expected file: jsonlite + expected file: json expected code: 200 - polarization VV VH: @@ -1832,7 +1832,7 @@ tests: maxResults: 10 output: json - expected file: jsonlite + expected file: json expected code: 200 - polarization Dual VH: @@ -1840,7 +1840,7 @@ tests: maxResults: 10 output: json - expected file: jsonlite + expected file: json expected code: 200 - polarization hH: @@ -1848,7 +1848,7 @@ tests: maxResults: 10 output: json - expected file: jsonlite + expected file: json expected code: 200 - polarization Vv: @@ -1856,7 +1856,7 @@ tests: maxResults: 10 output: json - expected file: jsonlite + expected file: json expected code: 200 - polarization Hh hV: @@ -1864,7 +1864,7 @@ tests: maxResults: 10 output: json - expected file: jsonlite + expected file: json expected code: 200 - polarization Dual vv: @@ -1872,7 +1872,7 @@ tests: maxResults: 10 output: json - expected file: jsonlite + expected file: json expected code: 200 - polarization quadrature: @@ -1880,7 +1880,7 @@ tests: maxResults: 10 output: json - expected file: jsonlite + expected file: json expected code: 200 - polarization vv VH: @@ -1888,7 +1888,7 @@ tests: maxResults: 10 output: json - expected file: jsonlite + expected file: json expected code: 200 - polarization Dual hv: @@ -1896,7 +1896,7 @@ tests: maxResults: 10 output: json - expected file: jsonlite + expected file: json expected code: 200 - polarization dual VH: @@ -1904,7 +1904,7 @@ tests: maxResults: 10 output: json - expected file: jsonlite + expected file: json expected code: 200 - polarization dual vh: @@ -2130,7 +2130,7 @@ tests: product_list: S1B_IW_GRDH_1SDV_20190410T153301_20190410T153328_015746_01D8D2_0E9B-GRD_HD,S1B_S6_GRDH_1SDV_20190911T214309_20190911T214338_017995_021E10_5CCB-GRD_HD,S1B_IW_SLC__1SDV_20180517T005744_20180517T005757_010954_0140DF_9891-SLC,S1B_WV_OCN__2SSV_20180513T055028_20180513T062610_010898_013F0C_059A-METADATA_OCN output: json - expected file: jsonlite + expected file: json expected code: 200 - product_list mix: @@ -2139,7 +2139,7 @@ tests: - ts1902-PSTOKES,ts1902-PTIF,ts1888-LTIF output: json - expected file: jsonlite + expected file: json expected code: 200 - product_list multi: @@ -2151,7 +2151,7 @@ tests: - ts1899 output: json - expected file: jsonlite + expected file: json expected code: 200 - product_list multi list: @@ -2160,7 +2160,7 @@ tests: - ts726-CSTOKES,ts726-DEM,ts726-LSTOKES,ts726-LTIF,ts726-CTIF,ts1721-LTIF,ts1733-PTIF output: json - expected file: jsonlite + expected file: json expected code: 200 - relativeOrbit single: diff --git a/tests/yml_tests/test_URLs_partial_pass.yml b/tests/yml_tests/test_URLs_partial_pass.yml index eac96c4..fd4baf1 100644 --- a/tests/yml_tests/test_URLs_partial_pass.yml +++ b/tests/yml_tests/test_URLs_partial_pass.yml @@ -172,14 +172,14 @@ tests: groupid: 12345 output: json - expected file: blank jsonlite + expected file: blank json expected code: 200 - groupid hash blank: groupid: sdfkhgsdfkhgsdf output: json - expected file: blank jsonlite + expected file: blank json expected code: 200 - groupid TEST blank: @@ -200,35 +200,35 @@ tests: groupid: R1_57704_ST7_F173 output: json - expected file: blank jsonlite + expected file: blank json expected code: 200 - groupid ERS blank not in CMR: groupid: E2_84699_STD_F309 output: json - expected file: blank jsonlite + expected file: blank json expected code: 200 - groupid JERS blank not in CMR: groupid: J1_36439_STD_F268 output: json - expected file: blank jsonlite + expected file: blank json expected code: 200 - groupid Seasat blank not in CMR: groupid: SS_01502_STD output: json - expected file: blank jsonlite + expected file: blank json expected code: 200 - instrument test: instrument: test output: json - expected file: blank jsonlite + expected file: blank json expected code: 200 - instrument notvalid: @@ -245,7 +245,7 @@ tests: output: json maxResults: 100 - expected file: blank jsonlite + expected file: blank json expected code: 200 - output test: