Skip to content

Commit

Permalink
Updated the schema and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
caparker committed Mar 27, 2024
1 parent 168b88d commit 687b93d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
12 changes: 9 additions & 3 deletions schema/v1.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Source",
"description": "An OpenAQ source",
"type": "object",
"required": [
"schema",
"provider",
"frequency",
"meta"
"meta",
"active"
],
"additionalProperties": false,
"properties": {
Expand All @@ -25,6 +26,12 @@
"day"
]
},
"secretKey": {
"type": "string"
},
"active": {
"type": "boolean"
},
"provider": {
"type": "string"
},
Expand All @@ -33,4 +40,3 @@
}
}
}

8 changes: 2 additions & 6 deletions test/source.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,21 @@ const ajv = new Ajv({
schemaId: 'auto'
});

ajv.addMetaSchema(
require('ajv/lib/refs/json-schema-draft-07.json'),
'http://json-schema.org/draft-07/schema#'
);

const validate = ajv.compile(schema);

tape('validate', (t) => {
t.ok(validate, 'schema loaded');
t.end();
});


// find all the sources, has to be synchronous for tape
sources.forEach((source) => {
tape(`tests for ${source}`, (t) => {
try {
const valid = validate(source);

t.ok(valid, `${source}: ${JSON.stringify(validate.errors)}`);
t.ok(valid, `${source.provider}: ${JSON.stringify(validate.errors)}`);
} catch (err) {
t.fail(`could not parse ${source} as JSON: ${err}`);
}
Expand Down

0 comments on commit 687b93d

Please sign in to comment.