Skip to content

Commit 3b085ec

Browse files
Merge pull request #49 from asfadmin/dev
feat: add json output support
2 parents 6b51b99 + 1bfd6a6 commit 3b085ec

6 files changed

Lines changed: 70 additions & 55 deletions

File tree

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ and uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
2525
-
2626
2727
-->
28+
------
29+
## [1.0.5](https://github.com/asfadmin/Discovery-SearchAPI-v3/compare/v1.0.4...v1.0.5)
30+
### Added
31+
- Added `json` output format support
32+
33+
### Changed
34+
- bump asf-search to v9.0.6
35+
2836
------
2937
## [1.0.5](https://github.com/asfadmin/Discovery-SearchAPI-v3/compare/v1.0.4...v1.0.5)
3038
### Added

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ ujson==5.7.0
2222
uvicorn==0.21.1
2323
watchfiles==0.19.0
2424

25-
asf_search==9.0.4
25+
asf_search==9.0.6
2626
python-json-logger==2.0.7
2727
asf_enumeration
2828

src/SearchAPI/application/output.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,18 @@
6666

6767
def as_output(results: asf.ASFSearchResults, output: str) -> dict:
6868
output_format = output.lower()
69-
if output_format == "json":
70-
output_format = "jsonlite"
7169

7270
# Use a switch statement, so you only load the type of output you need:
7371
match output_format:
72+
case 'json':
73+
return {
74+
'content': ''.join(results.json()),
75+
'media_type': 'application/json; charset=utf-8',
76+
'headers': {
77+
**constants.DEFAULT_HEADERS,
78+
'Content-Disposition': f"attachment; filename={make_filename('json')}",
79+
}
80+
}
7481
case 'jsonlite':
7582
return {
7683
'content': ''.join(results.jsonlite()),

tests/yml_tests/test_Baseline.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ tests:
113113
output: json
114114
# use_maturity: True
115115

116-
expected file: jsonlite # dropping json output
116+
expected file: json # dropping json output
117117
expected code: 200
118118

119119
- no output specified:

0 commit comments

Comments
 (0)