Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Nunjucks templating engine for API call construction #30

Merged
merged 9 commits into from
Sep 3, 2021

Conversation

tokebe
Copy link
Member

@tokebe tokebe commented Aug 25, 2021

(addresses #26)

This PR allows bteEdges to supply their input property as an object and specify params and body properties as Nunjucks templates, allowing for multiple inputs and more flexible parameter/etc. creation.

x-BTE

Example for non-TRAPI queries:

We want each item in someDataField, but we want to remove the prefixes, and concatenate them with a delimiter into a single string.

{
  input: {
    someDataField: ["PREFIX:id0", "PREFIX:id1", "PREFIX:id0"],
  },
  parameters: {
    someParameter: "{{ someDataField | rmPrefix | join(',') }}",
  },
}

This will result in someParameter being "id0,id1,id2". URLs may make use of this via path_param. Unlike in #28, input is simplified to remove nested per-param namespaces, and html is not automatically escaped.

TRAPI

TRAPI queries may take multiple inputs (and use templating) to ids usinginput.ids, and may use templating/multiple inputs in n0 and n1 categories as well as e01 predicates.

Filter Functions

Finally, nunjucks supports filter functions. It comes with a number of builtins, while this PR supplies the following, which may be applied individually or on an array of strings:

  • substr(begin, end): slice a string
  • addPrefix(prefix, delim): add a prefix, with delimiter between prefix and string defaulting to :
  • rmPrefix(delim): remove a prefix by splitting by delimiter and removing first string, with delimiter defaulting to :
  • replPrefix(prefix, delim) replace a prefix by using rmPrefix and addPrefix in order, using same delimiter.

For each of the above, delim is an optional argument, and substr has the same options and behavior as String.prototype.slice().

@coveralls
Copy link

Pull Request Test Coverage Report for Build 1168136603

  • 73 of 77 (94.81%) changed or added relevant lines in 3 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.3%) to 92.781%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/builder/nunjucks_config.js 25 26 96.15%
src/builder/trapi_query_builder.js 13 16 81.25%
Totals Coverage Status
Change from base Build 1152072917: -0.3%
Covered Lines: 237
Relevant Lines: 251

💛 - Coveralls

@newgene newgene merged commit 20aebf2 into main Sep 3, 2021
@newgene newgene deleted the support_templating branch September 3, 2021 21:02
@tokebe tokebe mentioned this pull request Sep 15, 2021
colleenXu added a commit to NCATS-Tangerine/translator-api-registry that referenced this pull request Mar 18, 2023
reference: biothings/call-apis.js#30
due to code on some instances keeping the ID prefix from the TRAPI query
colleenXu added a commit to NCATS-Tangerine/translator-api-registry that referenced this pull request Mar 18, 2023
reference: biothings/call-apis.js#30
due to code on some instances keeping the ID prefix from the TRAPI query
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants