Unverified Commit 295a0a85 authored by Károly Erdős's avatar Károly Erdős Committed by GitHub
Browse files

Merge pull request #10 from elixir-europe/update_readme

Update README file
parents f5319dfd 40315c73
......@@ -2,11 +2,9 @@
[![Build Status](https://travis-ci.org/EMBL-EBI-SUBS/json-schema-validator.svg?branch=master)](https://travis-ci.org/EMBL-EBI-SUBS/json-schema-validator) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/7fbabc981e294249a9a0967965418058)](https://www.codacy.com/app/fpenim/json-schema-validator?utm_source=github.com&utm_medium=referral&utm_content=EMBL-EBI-SUBS/json-schema-validator&utm_campaign=Badge_Grade)
[![tested with jest](https://img.shields.io/badge/tested_with-jest-99424f.svg)](https://github.com/facebook/jest)
This repository contains a [JSON Schema](http://json-schema.org/) validator for the EMBL-EBI Submissions Project. This validator runs as a standalone node server that receives validation requests and gives back it's results.
This repository contains a deployable and/or executable [JSON Schema](http://json-schema.org/) validator service. This validator can runs as a standalone node server or just a command line application that receives validation requests and gives back it's results.
This service uses [Elixir's JSON schema validator library](https://github.com/elixir-europe/json-schema-validator).
The validation is done using the [AJV](https://github.com/epoberezkin/ajv) library version ^6.0.0 that fully supports the JSON Schema **draft-07**.
The validation is done using the [AJV](https://github.com/epoberezkin/ajv) library version ^7.0.0 that supports the JSON Schema draft-06/07/2019-09.
## Contents
- [Getting Started](README.md#getting-started)
......@@ -19,7 +17,7 @@ The validation is done using the [AJV](https://github.com/epoberezkin/ajv) libra
- [Executing](README.md#executing)
- [Executing with Docker](README.md#executing-with-docker)
- [Executing the validator by a command line](README.md#executing-with-the-provided-cli-script)
- [Development](README.md#development)
......@@ -59,8 +57,8 @@ npm -v
#### Project
Clone project and install dependencies:
```
git clone https://github.com/EMBL-EBI-SUBS/json-schema-validator.git
cd json-schema-validator
git clone https://github.com/elixir-europe/bio-validator.git
cd bio-validator
npm install
```
......@@ -93,15 +91,34 @@ node src/server --pidPath=/pid/file/path/server.pid
```
Note: This is the **file path** and not just the directory it will be written to.
### Executing with Docker
1. Build docker image:
```
docker build -t subs/json-schema-validator .
```
2. Run docker image:
```
docker run -p 3020:3020 -d subs/json-schema-validator
### Executing with the provided CLI script
There is a `validator-cli.js` script is provided in the repository's root folder for the user if they would like to execute the validation from the command line without setting up a running server.
Just simply type `node ./validator-cli.js --help` to get the usage of this script:
```js
node ./validator-cli.js --help
Bio-validator CLI (Command Line Interface)
usage: node ./validator-cli.js [--schema=path/to/schema] [--json=path/to/json]
Options:
--help Show help [boolean]
--version Show version number [boolean]
-s, --schema path to the schema file [required]
-j, --json path to the json file to validate [required]
Examples:
node ./validator-cli.js Validates 'valid.json' with
--json=valid.json 'test_schema.json'.
--schema=test_schema.json
```
### Development
For development purposes using [nodemon](https://nodemon.io/) is useful. It reloads the application everytime something has changed on save time.
```
......@@ -201,8 +218,159 @@ HTTP status code `400`
## Custom keywords
The AJV library supports the implementation of custom json schema keywords to address validation scenarios that go beyond what json schema can handle.
The list of implemented custom keywords could be found in the
[Elixir's JSON Schema Validator library's documentation](https://github.com/elixir-europe/json-schema-validator/blob/master/README.md#custom-keywords).
Currently, in this repository four custom keywords are implemented: `graph_restriction`, `isChildTermOf`, `isValidTerm` and `isValidTaxonomy`.
If the user would like to add a new custom keywords then they have to add it to the validator when it is being instantiated:
```js
// get all the custom extensions
const { newCustomKeyword, isChildTermOf, isValidTerm, isValidTaxonomy } = require("./keywords");
const validator = new BioValidator([
new CustomKeyword(param1, param2),
new isChildTermOf(null, "https://www.ebi.ac.uk/ols/api/search?q="),
new isValidTerm(null, "https://www.ebi.ac.uk/ols/api/search?q="),
new isValidTaxonomy(null)
]);
// only use the new custom keyword
let validator = new BioValidator([CustomKeyword])
```
### graph_restriction
This custom keyword *evaluates if an ontology term is child of another*. This keyword is applied to a string (CURIE) and **passes validation if the term is a child of the term defined in the schema**.
The keyword requires one or more **parent terms** *(classes)* and **ontology ids** *(ontologies)*, both of which should exist in [OLS - Ontology Lookup Service](https://www.ebi.ac.uk/ols).
This keyword works by doing an asynchronous call to the [OLS API](https://www.ebi.ac.uk/ols/api/) that will respond with the required information to know if a given term is child of another.
Being an async validation step, whenever used in a schema, the schema must have the flag: `"$async": true` in its object root.
#### Usage
Schema:
```js
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "http://schema.dev.data.humancellatlas.org/module/ontology/5.3.0/organ_ontology",
"$async": true,
"properties": {
"ontology": {
"description": "A term from the ontology [UBERON](https://www.ebi.ac.uk/ols/ontologies/uberon) for an organ or a cellular bodily fluid such as blood or lymph.",
"type": "string",
"graph_restriction": {
"ontologies" : ["obo:hcao", "obo:uberon"],
"classes": ["UBERON:0000062","UBERON:0000179"],
"relations": ["rdfs:subClassOf"],
"direct": false,
"include_self": false
}
}
}
}
```
JSON object:
```js
{
"ontology": "UBERON:0000955"
}
```
### isChildTermOf
This custom keyword also *evaluates if an ontology term is child of another* and is a simplified version of the graph_restriction keyword. This keyword is applied to a string (url) and **passes validation if the term is a child of the term defined in the schema**.
The keyword requires the **parent term** and the **ontology id**, both of which should exist in [OLS - Ontology Lookup Service](https://www.ebi.ac.uk/ols).
This keyword works by doing an asynchronous call to the [OLS API](https://www.ebi.ac.uk/ols/api/) that will respond with the required information to know if a given term is child of another.
Being an async validation step, whenever used in a schema, the schema must have the flag: `"$async": true` in its object root.
#### Usage
Schema:
```js
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$async": true,
"properties": {
"term": {
"type": "string",
"format": "uri",
"isChildTermOf": {
"parentTerm": "http://purl.obolibrary.org/obo/PATO_0000047",
"ontologyId": "pato"
}
}
}
}
```
JSON object:
```js
{
"term": "http://purl.obolibrary.org/obo/PATO_0000383"
}
```
### isValidTerm
This custom keyword *evaluates if a given ontology term url exists in OLS* ([Ontology Lookup Service](https://www.ebi.ac.uk/ols)). It is applied to a string (url) and **passes validation if the term exists in OLS**. It can be aplied to any string defined in the schema.
This keyword works by doing an asynchronous call to the [OLS API](https://www.ebi.ac.uk/ols/api/) that will respond with the required information to determine if the term exists in OLS or not.
Being an async validation step, whenever used in a schema, the schema must have the flag: `"$async": true` in its object root.
#### Usage
Schema:
```js
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$async": true,
"properties": {
"url": {
"type": "string",
"format": "uri",
"isValidTerm": true
}
}
}
```
JSON object:
```js
{
"url": "http://purl.obolibrary.org/obo/PATO_0000383"
}
```
### isValidTaxonomy
This custom keyword evaluates if a given *taxonomy* exists in ENA's Taxonomy Browser. It is applied to a string (url) and **passes validation if the taxonomy exists in ENA**. It can be aplied to any string defined in the schema.
This keyword works by doing an asynchronous call to the [ENA API](https://www.ebi.ac.uk/ena/taxonomy/rest/any-name/<REPLACE_ME_WITH_AXONOMY_TERM>) that will respond with the required information to determine if the term exists or not.
Being an async validation step, whenever used in a schema, the schema must have the flag: `"$async": true` in its object root.
#### Usage
Schema:
```js
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Is valid taxonomy expression.",
"$async": true,
"properties": {
"value": {
"type": "string",
"minLength": 1,
"isValidTaxonomy": true
}
}
}
```
JSON object:
```js
{
"metagenomic source" : [ {
"value" : "wastewater metagenome"
} ]
}
```
## License
For more details about licensing see the [LICENSE](LICENSE.md).
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment