From d8213afbd1d3396304695879889a35a472f14265 Mon Sep 17 00:00:00 2001 From: SpicyGarlicAlbacoreRoll Date: Thu, 10 Jul 2025 13:44:51 -0800 Subject: [PATCH 1/7] feat: add json output support --- CHANGELOG.md | 8 ++++++++ src/SearchAPI/application/output.py | 11 +++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 67ec2c1..34a0f5b 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.5 + ------ ## [1.0.5](https://github.com/asfadmin/Discovery-SearchAPI-v3/compare/v1.0.4...v1.0.5) ### Added 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()), From d434683e2bc539a0de4cebf443bcd97e705c150d Mon Sep 17 00:00:00 2001 From: SpicyGarlicAlbacoreRoll Date: Thu, 10 Jul 2025 13:58:46 -0800 Subject: [PATCH 2/7] fix: actually commit requirements.txt --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 01b83c9..a864069 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.5 python-json-logger==2.0.7 asf_enumeration From 0b3a8bb05fb0663365e559fec3815b068baf91a6 Mon Sep 17 00:00:00 2001 From: SpicyGarlicAlbacoreRoll Date: Thu, 10 Jul 2025 14:29:30 -0800 Subject: [PATCH 3/7] update test cases --- tests/yml_tests/test_Baseline.yml | 2 +- tests/yml_tests/test_URLs.yml | 86 +++++++++++++++---------------- 2 files changed, 44 insertions(+), 44 deletions(-) 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: From 4310d674a824e811b198c34aadbf94db2abd1c61 Mon Sep 17 00:00:00 2001 From: SpicyGarlicAlbacoreRoll Date: Thu, 10 Jul 2025 14:43:51 -0800 Subject: [PATCH 4/7] fix: update partial url test cases --- tests/yml_tests/test_URLs_partial_pass.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) 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: From 6379d586db5ab29f1899cbb5be7ac7d451794195 Mon Sep 17 00:00:00 2001 From: SpicyGarlicAlbacoreRoll Date: Thu, 10 Jul 2025 15:11:34 -0800 Subject: [PATCH 5/7] fix: json test case --- tests/yml_tests/test_url_manager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/yml_tests/test_url_manager.py b/tests/yml_tests/test_url_manager.py index 6ec81e6..70032a1 100644 --- a/tests/yml_tests/test_url_manager.py +++ b/tests/yml_tests/test_url_manager.py @@ -233,7 +233,7 @@ def jsonToDict(json_data): ## JSON else: assert isinstance(file_content, type([])), self.error_msg.format("Response did not contain a list of results.\nContent (First 500 char):\n{0}\n".format(file_content)) - json_data = file_content[0] + json_data = file_content if json_data == []: content_type = "blank json" else: From 5bc437d86d5b474a5890b283a2106f9b5d5454c2 Mon Sep 17 00:00:00 2001 From: SpicyGarlicAlbacoreRoll Date: Thu, 10 Jul 2025 15:40:03 -0800 Subject: [PATCH 6/7] bump asf-search to 9.0.6 --- CHANGELOG.md | 2 +- requirements.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 34a0f5b..da36050 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,7 +31,7 @@ and uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - Added `json` output format support ### Changed -- bump asf-search to v9.0.5 +- bump asf-search to v9.0.6 ------ ## [1.0.5](https://github.com/asfadmin/Discovery-SearchAPI-v3/compare/v1.0.4...v1.0.5) diff --git a/requirements.txt b/requirements.txt index a864069..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.5 +asf_search==9.0.6 python-json-logger==2.0.7 asf_enumeration From 1bfd6a6ca94660c112da397168b974e2e9f8bdbe Mon Sep 17 00:00:00 2001 From: SpicyGarlicAlbacoreRoll Date: Thu, 10 Jul 2025 15:58:55 -0800 Subject: [PATCH 7/7] fix json test case typo --- tests/yml_tests/test_url_manager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/yml_tests/test_url_manager.py b/tests/yml_tests/test_url_manager.py index 70032a1..6ec81e6 100644 --- a/tests/yml_tests/test_url_manager.py +++ b/tests/yml_tests/test_url_manager.py @@ -233,7 +233,7 @@ def jsonToDict(json_data): ## JSON else: assert isinstance(file_content, type([])), self.error_msg.format("Response did not contain a list of results.\nContent (First 500 char):\n{0}\n".format(file_content)) - json_data = file_content + json_data = file_content[0] if json_data == []: content_type = "blank json" else: