Commit 17d6646f authored by bedroesb's avatar bedroesb
Browse files

Readme improvements

parent 6ed04886
......@@ -7,29 +7,29 @@ This repository contains a deployable and/or executable [JSON Schema](http://jso
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)
- [Prerequisites](README.md#prerequisites)
- [Installing](README.md#installing)
- [Running the Tests](README.md#running-the-tests)
- [Executing](README.md#executing)
- [Executing the validator by a command line](README.md#executing-with-the-provided-cli-script)
- [Development](README.md#development)
- [Validation API](README.md#validation-api)
- [Usage](README.md#usage)
- [API Errors](README.md#api-errors)
- [Custom keywords](README.md#custom-keywords)
- [License](README.md#license)
- [JSON Schema Validator service](#json-schema-validator-service)
- [Contents](#contents)
- [Getting Started](#getting-started)
- [Prerequisites](#prerequisites)
- [Installing](#installing)
- [Node.js / npm](#nodejs--npm)
- [Project](#project)
- [Running the Tests](#running-the-tests)
- [Usage](#usage)
- [1. The web interface (Simple)](#1-the-web-interface-simple)
- [2. Executing with the provided CLI script](#2-executing-with-the-provided-cli-script)
- [3. The validation API (Advanced)](#3-the-validation-api-advanced)
- [Usage](#usage-1)
- [API Errors](#api-errors)
- [Advanced settings](#advanced-settings)
- [Startup arguments](#startup-arguments)
- [Custom keywords](#custom-keywords)
- [graph_restriction](#graph_restriction)
- [isChildTermOf](#ischildtermof)
- [isValidTerm](#isvalidterm)
- [isValidTaxonomy](#isvalidtaxonomy)
- [Running in Docker](#running-in-docker)
- [License](#license)
## Getting Started
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
......@@ -67,33 +67,26 @@ npm install
npm test
```
### Executing
```
node src/server
```
The node server will run on port **3020** and will expose one endpoint: **/validate**.
## Usage
#### Startup arguments
The biovalidator, when deployed, can be used in three ways: using the web interface, the command line interface (CLI) or using the API.
- logPath
### 1. The web interface (Simple)
Start the server by executing following command:
If provided with a log path argument, the application will write the logs to a file on the specified directory with a 24h rotation. To provide the log path add a `logPath` property after the startup statement:
```
node src/server --logPath=/log/directory/path
node src/server
```
- pidPath
The web interface will available at [http://localhost:3020/](http://localhost:3020/)
If provided with a pid file path argument, the application will write the pid into the specified file. If no pid file argument is provided, the application will still create a pid file on the default path: `./server.pid`.
To provide the pid file path add a `pidPath` property after the startup statement:
```
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.
Read more about our additional settings in the [Advanced settings](#advanced-settings) section.
### 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.
### 2. Executing with the provided CLI script
There is a `validator-cli.js` script 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:
......@@ -114,18 +107,16 @@ Examples:
--json=valid.json 'test_schema.json'.
--schema=test_schema.json
```
> Development tip
> For development purposes using [nodemon](https://nodemon.io/) is useful. It reloads the application everytime something has changed on save time.
> ```
> nodemon src/server
> ```
### Development
For development purposes using [nodemon](https://nodemon.io/) is useful. It reloads the application everytime something has changed on save time.
```
nodemon src/server
```
## Validation API
## 3. The validation API (Advanced)
This validator exposes one single endpoint that will accept POST requests. When running on you local machine it will look like: **http://localhost:3020/validate**.
### Usage
......@@ -215,7 +206,30 @@ HTTP status code `400`
"error": "Malformed JSON please check your request body."
}
```
## Custom keywords
Read more about our additional settings in the [Advanced settings](#advanced-settings) section.
## Advanced settings
### Startup arguments
- logPath
If provided with a log path argument, the application will write the logs to a file on the specified directory with a 24h rotation. To provide the log path add a `logPath` property after the startup statement:
```
node src/server --logPath=/log/directory/path
```
- pidPath
If provided with a pid file path argument, the application will write the pid into the specified file. If no pid file argument is provided, the application will still create a pid file on the default path: `./server.pid`.
To provide the pid file path add a `pidPath` property after the startup statement:
```
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.
### 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.
Currently, in this repository four custom keywords are implemented: `graph_restriction`, `isChildTermOf`, `isValidTerm` and `isValidTaxonomy`.
......@@ -237,8 +251,7 @@ const validator = new BioValidator([
let validator = new BioValidator([CustomKeyword])
```
### graph_restriction
#### 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).
......@@ -247,7 +260,6 @@ This keyword works by doing an asynchronous call to the [OLS API](https://www.eb
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
{
......@@ -277,14 +289,13 @@ JSON object:
```
### isChildTermOf
#### 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
{
......@@ -309,13 +320,12 @@ JSON object:
}
```
### isValidTerm
#### 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
{
......@@ -338,14 +348,13 @@ JSON object:
}
```
### isValidTaxonomy
#### 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
{
......
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