Skip to content

Commit d2ace93

Browse files
authored
Merge pull request #910 from Sage-Bionetworks/develop-ValidationJsonEndpoint
allow users to upload csv or json file when validating manifest using API endpoints
2 parents 9d4fcd1 + 5b12c64 commit d2ace93

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

api/openapi/api.yaml

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,10 @@ paths:
152152
schema:
153153
type: object
154154
properties:
155-
# csv_file will be the field name in
155+
# file_name will be the field name in
156156
# this multipart request
157-
csv_file:
157+
file_name:
158+
description: Upload a json or a csv file.
158159
type: string
159160
format: binary
160161
parameters:
@@ -174,6 +175,23 @@ paths:
174175
description: Data Model Component
175176
example: Patient
176177
required: true
178+
- in: query
179+
name: json_str
180+
required: false
181+
schema:
182+
type: string
183+
nullable: false
184+
description: A JSON object
185+
example: '[{
186+
"Patient ID": 123,
187+
"Sex": "Female",
188+
"Year of Birth": "",
189+
"Diagnosis": "Healthy",
190+
"Component": "Patient",
191+
"Cancer Type": "Breast",
192+
"Family History": "Breast, Lung",
193+
}]'
194+
177195
operationId: api.routes.validate_manifest_route
178196
responses:
179197
"200":

api/routes.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,12 +272,17 @@ def create_single_manifest(data_type, dataset_id=None):
272272
return all_results
273273

274274

275-
def validate_manifest_route(schema_url, data_type):
275+
def validate_manifest_route(schema_url, data_type, json_str=None):
276276
# call config_handler()
277277
config_handler()
278278

279279
#Get path to temp file where manifest file contents will be saved
280-
temp_path = save_file()
280+
jsc = JsonConverter()
281+
282+
if json_str:
283+
temp_path = jsc.convert_json_str_to_csv(json_str = json_str, file_name = "example_json")
284+
else:
285+
temp_path = jsc.convert_json_file_to_csv("file_name")
281286

282287
# get path to temporary JSON-LD file
283288
jsonld = get_temp_jsonld(schema_url)

0 commit comments

Comments
 (0)