diff --git a/dd-api-spec.yaml b/dd-api-spec.yaml index fbf26ad..2cedec6 100644 --- a/dd-api-spec.yaml +++ b/dd-api-spec.yaml @@ -864,11 +864,14 @@ paths: example: UBERON - name: context in: query - required: true - description: A UBKG context to which to limit the response. Possible values are base_context, data_distillery_context, hubmap_sennet_context + required: false + description: A UBKG context to which to limit the response. Possible values are base_context, data_distillery_context, hubmap_sennet_context. Sources from base_context are included with other contexts. schema: type: string - example: base_context + enum: + - base_context + - hubmap_sennet_context + - data_distillery_context responses: '200': description: An array of Concepts with preferred terms that exactly match the specified string @@ -1527,9 +1530,11 @@ components: description: citation reference properties: PMID: + type: string description: PubMedID, if applicable example: 37953324 url: + type: string description: full URL to the citation example: "https://pubmed.ncbi.nlm.nih.gov/37953324" contexts: @@ -1539,9 +1544,11 @@ components: type: string example: base_context description: + type: string description: longform description of the source example: "An ontology for describing the classification of human diseases organized by etiology." download_date: + type: string description: Date when the source was obtained, in format YYYY_MM_DD example: "2024_02_24" home_urls: @@ -1558,26 +1565,34 @@ components: description: license properties: type: + type: string description: the type of license example: Creative Commons license (creativecommons.org) subtype: + type: string description: the subtype of license example: CCO version: - description: the versoin of the license + type: string + description: the version of the license example: version 4 name: + type: string description: name of the source example: Human Disease Ontology sab: + type: string description: acronym for Source ABbreviation example: DOID source_etl: + type: string description: the parameter provided to the UBKG generation framework ETL script. For sources that are from OWL files, source_etl is the URL to the OWL; for other sources, source_etl is a command for one of the python scripts that the generation framework uses to import the source. example: "http://purl.obolibrary.org/obo/doid.owl" source_type: + type: string description: The type of source file. Possible values are owl, api, ftp, ubkg_edge_node, umls, and simpleknowledge. example: owl source_version: + type: string description: A reference to the version of the source. If the source is an OWL file, the usual version is the date extracted from the VersionIRI of the file; if from a website, the file date. Dates are in format YYYY_MM_DD. example: "2024_04_22" \ No newline at end of file diff --git a/src/ubkg_api/common_routes/common_neo4j_logic.py b/src/ubkg_api/common_routes/common_neo4j_logic.py index a2ca0c4..2978695 100644 --- a/src/ubkg_api/common_routes/common_neo4j_logic.py +++ b/src/ubkg_api/common_routes/common_neo4j_logic.py @@ -1062,10 +1062,11 @@ def sources_get_logic(neo4j_instance, sab=None, context=None) -> dict: querytxt = querytxt.replace('$sabfilter', f" AND t.name IN {sab}") # Filter by ubkg context. + # JAS 24 May 2024 bug fix - replace t.name with tContext.name if len(context) == 0: querytxt = querytxt.replace('$contextfilter', '') else: - querytxt = querytxt.replace('$contextfilter', f" AND t.name IN {context}") + querytxt = querytxt.replace('$contextfilter', f" AND tContext.name IN {context}") # Set timeout for query based on value in app.cfg. query = neo4j.Query(text=querytxt, timeout=neo4j_instance.timeout) diff --git a/src/ubkg_api/common_routes/sources/sources_controller.py b/src/ubkg_api/common_routes/sources/sources_controller.py index be05f4b..1a38d51 100644 --- a/src/ubkg_api/common_routes/sources/sources_controller.py +++ b/src/ubkg_api/common_routes/sources/sources_controller.py @@ -23,6 +23,16 @@ def sources_get(): sab = parameter_as_list(param_name='sab') context = parameter_as_list(param_name='context') + # JAS 24 May 2024 + # Validate context parameter against enum. + val_enum = ['base_context', 'data_distillery_context', 'hubmap_sennet_context'] + if context is not None: + for c in context: + c = c.lower() + err = validate_parameter_value_in_enum(param_name='context', param_value=c, + enum_list=val_enum) + if err != 'ok': + return make_response(err, 400) result = sources_get_logic(neo4j_instance, sab=sab, context=context) iserr = result is None or result == [] diff --git a/tests/test_dd_api.sh b/tests/test_dd_api.sh index ec3e23e..22bb6de 100755 --- a/tests/test_dd_api.sh +++ b/tests/test_dd_api.sh @@ -1240,7 +1240,15 @@ curl --request GET \ echo | tee -a test.out echo | tee -a test.out -echo "4. /sources?sab=HPOMP GET => valid SAB; should return 200" | tee -a test.out +echo "4. /sources?context=x GET => invalid context; should return custom 404" | tee -a test.out +curl --request GET \ + --url "${UBKG_URL}/sources?context=x" \ + --header "Accept: application/json" \ + --header "X-API-KEY:$apikey" | cut -c1-60 | tee -a test.out +echo | tee -a test.out +echo | tee -a test.out + +echo "5. /sources?sab=HPOMP GET => valid SAB; should return 200" | tee -a test.out curl --request GET \ --url "${UBKG_URL}/sources?sab=HPOMP" \ --header "Accept: application/json" \ @@ -1248,7 +1256,7 @@ curl --request GET \ echo | tee -a test.out echo | tee -a test.out -echo "5. /sources?context=base_context GET => valid context; should return 200" | tee -a test.out +echo "6. /sources?context=base_context GET => valid context; should return 200" | tee -a test.out curl --request GET \ --url "${UBKG_URL}/sources?context=base_context" \ --header "Accept: application/json" \ diff --git a/tests/test_ubkg_api.sh b/tests/test_ubkg_api.sh index eeb7666..e9fb0a5 100755 --- a/tests/test_ubkg_api.sh +++ b/tests/test_ubkg_api.sh @@ -1103,17 +1103,24 @@ curl --request GET \ echo | tee -a test.out echo | tee -a test.out -echo "4. /sources?sab=HPOMP GET => valid SAB; should return 200" | tee -a test.out +echo "4. /sources?context=x GET => invalid context; should return custom 400" | tee -a test.out curl --request GET \ - --url "${UBKG_URL}/sources?sab=HPOMP" \ + --url "${UBKG_URL}/sources?context=x" \ --header "Accept: application/json" | tee -a test.out echo | tee -a test.out echo | tee -a test.out -echo "5. /sources?context=base_context GET => valid context; should return 200" | tee -a test.out +echo "5. /sources?sab=HPOMP GET => valid SAB; should return 200" | tee -a test.out +curl --request GET \ + --url "${UBKG_URL}/sources?sab=HPOMP" \ + --header "Accept: application/json" | cut -c1-60 | tee -a test.out +echo | tee -a test.out +echo | tee -a test.out + +echo "6. /sources?context=base_context GET => valid context; should return 200" | tee -a test.out curl --request GET \ --url "${UBKG_URL}/sources?context=base_context" \ - --header "Accept: application/json" | tee -a test.out + --header "Accept: application/json" | cut -c1-60 | tee -a test.out echo | tee -a test.out echo | tee -a test.out diff --git a/ubkg-api-spec.yaml b/ubkg-api-spec.yaml index feaeeee..c20fbb5 100644 --- a/ubkg-api-spec.yaml +++ b/ubkg-api-spec.yaml @@ -845,7 +845,7 @@ paths: description: No Concepts with terms matching the specified string. '5XX': description: Unknown error -/sources: + /sources: get: operationId: sources_get summary: Returns a list of Concept nodes with preferred terms that exactly match the specified string. @@ -859,11 +859,14 @@ paths: example: UBERON - name: context in: query - required: true - description: A UBKG context to which to limit the response. Possible values are base_context, data_distillery_context, hubmap_sennet_context + required: false + description: A UBKG context to which to limit the response. Possible values are base_context, data_distillery_context, hubmap_sennet_context. The sources from base_context are included with any other context. schema: type: string - example: base_context + enum: + - base_context + - hubmap_sennet_context + - data_distillery_context responses: '200': description: An array of Concepts with preferred terms that exactly match the specified string @@ -1534,9 +1537,11 @@ components: type: string example: base_context description: + type: string description: longform description of the source example: "An ontology for describing the classification of human diseases organized by etiology." download_date: + type: string description: Date when the source was obtained, in format YYYY_MM_DD example: "2024_02_24" home_urls: @@ -1559,20 +1564,25 @@ components: description: the subtype of license example: CCO version: - description: the versoin of the license + description: the version of the license example: version 4 name: + type: string description: name of the source example: Human Disease Ontology sab: + type: string description: acronym for Source ABbreviation example: DOID source_etl: + type: string description: the parameter provided to the UBKG generation framework ETL script. For sources that are from OWL files, source_etl is the URL to the OWL; for other sources, source_etl is a command for one of the python scripts that the generation framework uses to import the source. example: "http://purl.obolibrary.org/obo/doid.owl" source_type: + type: string description: The type of source file. Possible values are owl, api, ftp, ubkg_edge_node, umls, and simpleknowledge. example: owl source_version: + type: string description: A reference to the version of the source. If the source is an OWL file, the usual version is the date extracted from the VersionIRI of the file; if from a website, the file date. Dates are in format YYYY_MM_DD. example: "2024_04_22"