require("ajv")
var Ajv = require('ajv');
const data = {
"@type": "n3c:Dataset",
"@context": {
"schema": "http://schema.org/",
"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
"rdfs": "http://www.w3.org/2000/01/rdf-schema#",
"bts": "http://schema.biothings.io/",
"xsd": "http://www.w3.org/2001/XMLSchema#",
"owl": "http://www.w3.org/2002/07/owl/",
"niaid": "https://discovery.biothings.io/view/niaid/",
"outbreak": "https://discovery.biothings.io/view/outbreak/",
"n3c": "http://discovery.biothings.io/"
},
"name": "name",
"description": "some description",
"author": {
"@type": "Person",
"name": "First Last",
"givenName": "First",
"familyName": "Last",
"orcid": "abc123",
"affiliation": {
"name": "company",
"alternateName": "otherName"
}
},
"license": "CC0",
"cost": "some text",
"url": "http://www.myurl.com",
"identifier": "fdsaffdsaf",
"contain_geo_codes": true,
"contain_phi": false,
"justification": "fdsafasdfasdk fhsl flk sdalkfjkl"
}
const schema ={
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"name": {
"description": "Descriptive name of the dataset",
"type": "string",
"categories": [
{
"category": "Dataset",
"subcategory": "Required"
}
],
"value": "nbg"
},
"description": {
"description": "Longer description of what is contained in the dataset",
"type": "string",
"categories": [
{
"category": "Dataset",
"subcategory": "Required"
}
],
"value": "gd"
},
"license": {
"description": "A license document that applies to this content, typically indicated by a URL.",
"type": "string",
"categories": [
{
"category": "Dataset",
"subcategory": "Required"
}
],
"value": "fd"
},
"cost": {
"description": "Specify the cost to obtain the dataset, \"Free\", \"Subscription\" or others",
"type": "string",
"categories": [
{
"category": "Dataset",
"subcategory": "Required"
}
]
},
"url": {
"description": "The main URL about the dataset",
"type": "string",
"format": "uri",
"categories": [
{
"category": "Dataset",
"subcategory": "Required"
}
]
},
"identifier": {
"description": "identifier for the dataset in a shared repository (GEO, Zenodo, figshare, etc)",
"type": "string",
"categories": [
{
"category": "Dataset",
"subcategory": "Required"
}
]
},
"contain_geo_codes": {
"description": "Does the dataset contains GEO codes (e.g. zip codes)?",
"type": "boolean",
"categories": [
{
"category": "Dataset",
"subcategory": "Required"
}
]
},
"contain_phi": {
"description": "Does the dataset contains Protected health information (PHI)?",
"type": "boolean",
"categories": [
{
"category": "Dataset",
"subcategory": "Required"
}
]
},
"justification": {
"description": "How is the dataset relevant to the N3C project, why does the community want and how can it be used?",
"type": "string",
"categories": [
{
"category": "Dataset",
"subcategory": "Required"
}
]
},
"doi": {
"description": "The DOI for the dataset if available",
"type": "string",
"categories": [
{
"category": "Dataset",
"subcategory": "Recommended"
}
]
},
"contact": {
"description": "Provide an email contact",
"type": "string",
"categories": [
{
"category": "Dataset",
"subcategory": "Recommended"
}
]
},
"documentation": {
"description": "Provide the URL to the detailed documentation about the dataset",
"type": "string",
"format": "uri",
"categories": [
{
"category": "Dataset",
"subcategory": "Recommended"
}
]
},
"funding": {
"description": "Funding that supports (sponsors) the collection of this dataset through some kind of financial contribution",
"oneOf": [
{
"type": "object",
"@type": "MonetaryGrant",
"description": "Information about funding support",
"properties": {
"name": {
"type": "string",
"description": "The name of the monetary grant that funded/funds the Dataset"
},
"identifier": {
"type": "string",
"description": "Unique identifier(s) for the grant(s) used to fund the Dataset"
},
"funder": {
"description": "name of the funding organization",
"oneOf": [
{
"description": "A barebones Organization object to work around recursion issues in DDE",
"@type": "Organization",
"type": "object",
"properties": {
"name": {
"description": "name of the organization",
"type": "string"
},
"alternateName": {
"description": "Alternate name or Acronym for the organization.",
"type": "string"
}
},
"required": [
"name"
]
},
{
"type": "array",
"items": {
"description": "A barebones Organization object to work around recursion issues in DDE",
"@type": "Organization",
"type": "object",
"properties": {
"name": {
"description": "name of the organization",
"type": "string"
},
"alternateName": {
"description": "Alternate name or Acronym for the organization.",
"type": "string"
}
},
"required": [
"name"
]
}
}
]
},
"url": {
"type": "string",
"format": "uri",
"description": "award URL"
}
},
"required": [
"funder"
]
},
{
"type": "array",
"items": {
"type": "object",
"@type": "MonetaryGrant",
"description": "Information about funding support",
"properties": {
"name": {
"type": "string",
"description": "The name of the monetary grant that funded/funds the Dataset"
},
"identifier": {
"type": "string",
"description": "Unique identifier(s) for the grant(s) used to fund the Dataset"
},
"funder": {
"description": "name of the funding organization",
"oneOf": [
{
"description": "A barebones Organization object to work around recursion issues in DDE",
"@type": "Organization",
"type": "object",
"properties": {
"name": {
"description": "name of the organization",
"type": "string"
},
"alternateName": {
"description": "Alternate name or Acronym for the organization.",
"type": "string"
}
},
"required": [
"name"
]
},
{
"type": "array",
"items": {
"description": "A barebones Organization object to work around recursion issues in DDE",
"@type": "Organization",
"type": "object",
"properties": {
"name": {
"description": "name of the organization",
"type": "string"
},
"alternateName": {
"description": "Alternate name or Acronym for the organization.",
"type": "string"
}
},
"required": [
"name"
]
}
}
]
},
"url": {
"type": "string",
"format": "uri",
"description": "award URL"
}
},
"required": [
"funder"
]
}
}
],
"categories": [
{
"category": "Dataset",
"subcategory": "Recommended"
}
]
},
"keywords": {
"description": "A list of keywords associated with this dataset",
"oneOf": [
{
"type": "string"
},
{
"type": "array",
"items": {
"type": "string"
}
}
],
"categories": [
{
"category": "Dataset",
"subcategory": "Recommended"
}
]
},
"measurementTechnique": {
"description": "A technique or technology used in a Dataset, corresponding to the method used for measuring the corresponding variable(s).",
"oneOf": [
{
"description": "collection of vocabulary terms defined in ontologies",
"@type": "CreativeWork",
"type": "string",
"vocabulary": {
"ontology": [
"efo",
"ncit",
"obi"
],
"children_of": [
"https://www.ebi.ac.uk/efo/EFO_0002694",
"http://purl.obolibrary.org/obo/NCIT_C20368",
"http://purl.obolibrary.org/obo/OBI_0000011"
]
},
"strict": false
},
{
"type": "array",
"items": {
"description": "collection of vocabulary terms defined in ontologies",
"@type": "CreativeWork",
"type": "string",
"vocabulary": {
"ontology": [
"efo",
"ncit",
"obi"
],
"children_of": [
"https://www.ebi.ac.uk/efo/EFO_0002694",
"http://purl.obolibrary.org/obo/NCIT_C20368",
"http://purl.obolibrary.org/obo/OBI_0000011"
]
},
"strict": false
}
}
],
"categories": [
{
"category": "Dataset",
"subcategory": "Recommended"
}
]
},
"standards_used": {
"description": "A list of standards used in the dataset, e.g. OMOP.",
"oneOf": [
{
"type": "string"
},
{
"type": "array",
"items": {
"type": "string"
}
}
],
"categories": [
{
"category": "Dataset",
"subcategory": "Recommended"
}
]
},
"citation": {
"description": "A citation to the dataset",
"oneOf": [
{
"description": "A citation object for a resource which is cited by the dataset (ie- is a derivative of the dataset) , related to the dataset, or from which the dataset was based on (ie- is derived from).",
"@type": "Thing",
"type": "object",
"properties": {
"name": {
"description": "Name of or title of the citation",
"type": "string"
},
"identifier": {
"description": "An identifier associated with the citation",
"type": "string"
},
"pmid": {
"description": "A pubmed identifier if available",
"type": "string"
},
"doi": {
"description": "A doi if available",
"type": "string"
},
"url": {
"description": "The url of the resource cited.",
"type": "string",
"format": "uri"
},
"citeText": {
"description": "The bibliographic citation for the referenced resource as is provided",
"type": "string"
}
},
"required": [
"name"
]
},
{
"type": "array",
"items": {
"description": "A citation object for a resource which is cited by the dataset (ie- is a derivative of the dataset) , related to the dataset, or from which the dataset was based on (ie- is derived from).",
"@type": "Thing",
"type": "object",
"properties": {
"name": {
"description": "Name of or title of the citation",
"type": "string"
},
"identifier": {
"description": "An identifier associated with the citation",
"type": "string"
},
"pmid": {
"description": "A pubmed identifier if available",
"type": "string"
},
"doi": {
"description": "A doi if available",
"type": "string"
},
"url": {
"description": "The url of the resource cited.",
"type": "string",
"format": "uri"
},
"citeText": {
"description": "The bibliographic citation for the referenced resource as is provided",
"type": "string"
}
},
"required": [
"name"
]
}
}
],
"categories": [
{
"category": "Dataset",
"subcategory": "Recommended"
}
]
},
"release_frequency": {
"description": "How frequent is the new version of the dataset released (monthly, quarterly, etc)",
"type": "string",
"categories": [
{
"category": "Dataset",
"subcategory": "Recommended"
}
]
},
"comment": {
"description": "Any other comments about this dataset?",
"type": "string",
"categories": [
{
"category": "Dataset",
"subcategory": "Recommended"
}
]
},
"includedInDataCatalog": {
"description": "Data catalog(s) which contain this dataset.",
"oneOf": [
{
"description": "A data catalog which contains this dataset.",
"type": "object",
"properties": {
"name": {
"const": "N3C Datasets"
},
"url": {
"const": "https://ncats.nih.gov/n3c/"
}
}
},
{
"type": "array",
"items": {
"description": "A data catalog which contains this dataset.",
"type": "object",
"properties": {
"name": {
"const": "N3C Datasets"
},
"url": {
"const": "https://ncats.nih.gov/n3c/"
}
}
}
}
],
"categories": [
{
"category": "Dataset",
"subcategory": "Recommended"
}
]
}
},
"required": [
"name",
"description",
"author",
"license",
"cost",
"url",
"identifier",
"contain_geo_codes",
"contain_phi",
"justification",
"identifier"
],
"definitions": {
"controlledVocabulary": {
"description": "collection of vocabulary terms defined in ontologies",
"@type": "CreativeWork",
"type": "string",
"vocabulary": {
"ontology": [
"efo",
"ncit",
"obi"
],
"children_of": [
"https://www.ebi.ac.uk/efo/EFO_0002694",
"http://purl.obolibrary.org/obo/NCIT_C20368",
"http://purl.obolibrary.org/obo/OBI_0000011"
]
},
"strict": false
},
"moreControlledVocabulary": {
"definition": "collection of vocabulary terms defined in ontologies",
"@type": "CreativeWork",
"type": "string",
"strict": false,
"vocabulary": {
"ontology": [
"efo",
"cido",
"epo",
"covid19"
],
"children_of": [
"https://www.ebi.ac.uk/efo/EFO_0001444",
"http://purl.obolibrary.org/obo/cido.owl",
"http://purl.obolibrary.org/obo/epo",
"https://bioportal.bioontology.org/ontologies/COVID19"
]
}
},
"baseOrgObject": {
"description": "A barebones Organization object to work around recursion issues in DDE",
"@type": "Organization",
"type": "object",
"properties": {
"name": {
"description": "name of the organization",
"type": "string"
},
"alternateName": {
"description": "Alternate name or Acronym for the organization.",
"type": "string"
}
},
"required": [
"name"
]
},
"person": {
"description": "Reusable person definition",
"@type": "Person",
"type": "object",
"properties": {
"name": {
"type": "string"
},
"givenName": {
"type": "string"
},
"familyName": {
"type": "string"
},
"orcid": {
"type": "string"
},
"affiliation": {
"oneOf": [
{
"description": "A barebones Organization object to work around recursion issues in DDE",
"@type": "Organization",
"type": "object",
"properties": {
"name": {
"description": "name of the organization",
"type": "string"
},
"alternateName": {
"description": "Alternate name or Acronym for the organization.",
"type": "string"
}
},
"required": [
"name"
]
},
{
"type": "array",
"items": {
"description": "A barebones Organization object to work around recursion issues in DDE",
"@type": "Organization",
"type": "object",
"properties": {
"name": {
"description": "name of the organization",
"type": "string"
},
"alternateName": {
"description": "Alternate name or Acronym for the organization.",
"type": "string"
}
},
"required": [
"name"
]
}
}
]
}
},
"required": [
"name"
]
},
"organization": {
"description": "Reusable organization definition",
"@type": "Organization",
"type": "object",
"properties": {
"name": {
"type": "string"
},
"alternateName": {
"type": "string"
},
"affiliation": {
"description": "A barebones Organization object to work around recursion issues in DDE",
"@type": "Organization",
"type": "object",
"properties": {
"name": {
"description": "name of the organization",
"type": "string"
},
"alternateName": {
"description": "Alternate name or Acronym for the organization.",
"type": "string"
}
},
"required": [
"name"
]
},
"members": {
"oneOf": [
{
"description": "Reusable person definition",
"@type": "Person",
"type": "object",
"properties": {
"name": {
"type": "string"
},
"givenName": {
"type": "string"
},
"familyName": {
"type": "string"
},
"orcid": {
"type": "string"
},
"affiliation": {
"oneOf": [
{
"description": "A barebones Organization object to work around recursion issues in DDE",
"@type": "Organization",
"type": "object",
"properties": {
"name": {
"description": "name of the organization",
"type": "string"
},
"alternateName": {
"description": "Alternate name or Acronym for the organization.",
"type": "string"
}
},
"required": [
"name"
]
},
{
"type": "array",
"items": {
"description": "A barebones Organization object to work around recursion issues in DDE",
"@type": "Organization",
"type": "object",
"properties": {
"name": {
"description": "name of the organization",
"type": "string"
},
"alternateName": {
"description": "Alternate name or Acronym for the organization.",
"type": "string"
}
},
"required": [
"name"
]
}
}
]
}
},
"required": [
"name"
]
},
{
"type": "array",
"items": {
"description": "Reusable person definition",
"@type": "Person",
"type": "object",
"properties": {
"name": {
"type": "string"
},
"givenName": {
"type": "string"
},
"familyName": {
"type": "string"
},
"orcid": {
"type": "string"
},
"affiliation": {
"oneOf": [
{
"description": "A barebones Organization object to work around recursion issues in DDE",
"@type": "Organization",
"type": "object",
"properties": {
"name": {
"description": "name of the organization",
"type": "string"
},
"alternateName": {
"description": "Alternate name or Acronym for the organization.",
"type": "string"
}
},
"required": [
"name"
]
},
{
"type": "array",
"items": {
"description": "A barebones Organization object to work around recursion issues in DDE",
"@type": "Organization",
"type": "object",
"properties": {
"name": {
"description": "name of the organization",
"type": "string"
},
"alternateName": {
"description": "Alternate name or Acronym for the organization.",
"type": "string"
}
},
"required": [
"name"
]
}
}
]
}
},
"required": [
"name"
]
}
}
]
}
},
"required": [
"name"
]
},
"funding": {
"type": "object",
"@type": "MonetaryGrant",
"description": "Information about funding support",
"properties": {
"name": {
"type": "string",
"description": "The name of the monetary grant that funded/funds the Dataset"
},
"identifier": {
"type": "string",
"description": "Unique identifier(s) for the grant(s) used to fund the Dataset"
},
"funder": {
"description": "name of the funding organization",
"oneOf": [
{
"description": "A barebones Organization object to work around recursion issues in DDE",
"@type": "Organization",
"type": "object",
"properties": {
"name": {
"description": "name of the organization",
"type": "string"
},
"alternateName": {
"description": "Alternate name or Acronym for the organization.",
"type": "string"
}
},
"required": [
"name"
]
},
{
"type": "array",
"items": {
"description": "A barebones Organization object to work around recursion issues in DDE",
"@type": "Organization",
"type": "object",
"properties": {
"name": {
"description": "name of the organization",
"type": "string"
},
"alternateName": {
"description": "Alternate name or Acronym for the organization.",
"type": "string"
}
},
"required": [
"name"
]
}
}
]
},
"url": {
"type": "string",
"format": "uri",
"description": "award URL"
}
},
"required": [
"funder"
]
},
"citation": {
"description": "A citation object for a resource which is cited by the dataset (ie- is a derivative of the dataset) , related to the dataset, or from which the dataset was based on (ie- is derived from).",
"@type": "Thing",
"type": "object",
"properties": {
"name": {
"description": "Name of or title of the citation",
"type": "string"
},
"identifier": {
"description": "An identifier associated with the citation",
"type": "string"
},
"pmid": {
"description": "A pubmed identifier if available",
"type": "string"
},
"doi": {
"description": "A doi if available",
"type": "string"
},
"url": {
"description": "The url of the resource cited.",
"type": "string",
"format": "uri"
},
"citeText": {
"description": "The bibliographic citation for the referenced resource as is provided",
"type": "string"
}
},
"required": [
"name"
]
},
"inclusionObject": {
"description": "A data catalog which contains this dataset.",
"type": "object",
"properties": {
"name": {
"const": "N3C Datasets"
},
"url": {
"const": "https://ncats.nih.gov/n3c/"
}
}
}
}
}
var ajv = new Ajv({allErrors: true, jsonPointers: true});
const isValid = ajv.validate(schema, data); //schema, data
if(! isValid){
console.log('%c ***** VALIDATION DETAILS *****','color:pink')
console.log("NOT VALID ",ajv.errors);
}else {
console.log('%c ***** VALIDATION RESULT *****','color:limegreen')
console.log(isValid)
}