Skip to content

Commit

Permalink
fix: include check to add apis with meta_knowledge_graph paths conati…
Browse files Browse the repository at this point in the history
…ning 1.1 prefix to the predicates local file
  • Loading branch information
marcodarko committed Jun 15, 2021
1 parent dc2b8fc commit 7e0fe1d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
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.

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 7e0fe1d

Please sign in to comment.