Skip to content

Commit

Permalink
Merge 9ffdc14 into 78c4320
Browse files Browse the repository at this point in the history
  • Loading branch information
newgene committed Jun 16, 2021
2 parents 78c4320 + 9ffdc14 commit 5fbc8dc
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 19 deletions.
2 changes: 1 addition & 1 deletion __test__/integration/TRAPIv1.1.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ describe("Testing v1.1 endpoints", () => {
expect(response.body.message.knowledge_graph).toHaveProperty("edges");
expect(response.body.message.knowledge_graph.nodes).toHaveProperty("MONDO:0016575");
expect(response.body.message.knowledge_graph.nodes).toHaveProperty("UMLS:C0008780");
expect(response.body.message.knowledge_graph.nodes["UMLS:C0008780"]).toHaveProperty("category", "biolink:PhenotypicFeature");
expect(response.body.message.knowledge_graph.nodes["UMLS:C0008780"]).toHaveProperty("categories", ["biolink:PhenotypicFeature"]);
})
})

Expand Down
2 changes: 1 addition & 1 deletion data/predicates.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion data/smartapi_specs.json

Large diffs are not rendered by default.

25 changes: 12 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"supertest": "^6.1.3"
},
"dependencies": {
"@biothings-explorer/query_graph_handler": "^1.17.1",
"@biothings-explorer/query_graph_handler": "^1.17.3",
"@biothings-explorer/smartapi-kg": "^3.8.1",
"axios": "^0.21.1",
"body-parser": "^1.19.0",
Expand Down
28 changes: 26 additions & 2 deletions src/controllers/cron/update_local_smartapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const cron = require('node-cron');

const getTRAPIWithPredicatesEndpoint = (specs) => {
const trapi = [];
let special_cases = []
specs.map((spec) => {
try {
if (
Expand All @@ -16,7 +17,9 @@ const getTRAPIWithPredicatesEndpoint = (specs) => {
"/query" in spec.paths &&
"x-trapi" in spec.info &&
spec.servers.length &&
"/predicates" in spec.paths || "/meta_knowledge_graph" in spec.paths
"/predicates" in spec.paths ||
"/meta_knowledge_graph" in spec.paths ||
"/1.1/meta_knowledge_graph" in spec.paths
) {
let api = {
association: {
Expand Down Expand Up @@ -46,10 +49,25 @@ const getTRAPIWithPredicatesEndpoint = (specs) => {
//1.1
api['predicates_path'] = "/meta_knowledge_graph";
trapi.push(api);
}
if (
"/1.1/meta_knowledge_graph" in spec.paths &&
Object.prototype.hasOwnProperty.call(spec.info["x-trapi"], "version") &&
spec.info["x-trapi"].version.includes("1.1")
) {
//1.1
api['predicates_path'] = "/1.1/meta_knowledge_graph";
trapi.push(api);
special_cases.push({name: spec.info['title'], id: spec['_id']})
}else if("/predicates" in spec.paths ){
//1.0
api['predicates_path'] = "/predicates";
trapi.push(api);
}else{
debug(
`[error]: Unable to parse spec, ${spec ? spec.info.title : spec
}. Endpoint required not found.`
);
}
}
} catch (err) {
Expand All @@ -59,6 +77,12 @@ const getTRAPIWithPredicatesEndpoint = (specs) => {
);
}
});
if (special_cases.length) {
debug(
`Found some APIs with unexpected endpoint "/1.1/meta_knowledge_graph":`
);
debug(`${JSON.stringify(special_cases)}`);
}
return trapi;
}

Expand All @@ -71,7 +95,7 @@ const constructQueryUrl = (serverUrl, path) => {

const getPredicatesFromGraphData = (predicate_endpoint, data) => {
//if /predicates just return normal response
if (predicate_endpoint !== '/meta_knowledge_graph') {
if (!['/meta_knowledge_graph', '/1.1/meta_knowledge_graph'].includes(predicate_endpoint)) {
return data
}
// transform graph data to legacy format > object.subject : predicates
Expand Down

0 comments on commit 5fbc8dc

Please sign in to comment.