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

Add an even better validator #9

Open
wants to merge 67 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
546e917
Add codespell action
peternewman Sep 12, 2020
ecb58e5
Fix a typo
peternewman Sep 12, 2020
ad2dda0
Validate the schema itself
peternewman Sep 12, 2020
ee04d55
First go at validation
peternewman Sep 12, 2020
0938780
Remove awaits
peternewman Sep 12, 2020
d81e07b
Ensure we meta-validate
peternewman Sep 12, 2020
6b7e1a0
Switch to just our schema and validate a file
peternewman Sep 12, 2020
7b4e231
Try and deal with unhandled promises
peternewman Sep 12, 2020
04e917c
Try and exit when we get an error
peternewman Sep 12, 2020
d863a11
Validate two files
peternewman Sep 12, 2020
723cdd2
Try validating all files
peternewman Sep 12, 2020
4848bb3
Try and fix the async issue
peternewman Sep 12, 2020
223ef8d
Fix some variable names
peternewman Sep 12, 2020
b2a7f57
Hopefully fix the variable scope
peternewman Sep 12, 2020
000a77b
Try and fix the sync issues
peternewman Sep 12, 2020
63a1c9b
Try and make it all async
peternewman Sep 12, 2020
0d72dec
Try going sync again
peternewman Sep 12, 2020
638931a
Try a better file list function
peternewman Sep 12, 2020
b16b1b0
Try to fix the path
peternewman Sep 12, 2020
0ac9704
Fix the paths
peternewman Sep 12, 2020
4518ed1
Try asyncing again
peternewman Sep 12, 2020
4037cca
Try being a bit more async
peternewman Sep 12, 2020
56ec4db
Fix a variable
peternewman Sep 12, 2020
ee0ee48
Async walk too
peternewman Sep 12, 2020
f4a91ea
Fix the variable names
peternewman Sep 12, 2020
cce903c
Make sure we've fetched the base schema
peternewman Sep 12, 2020
ceb9fdb
Await the base schema
peternewman Sep 13, 2020
ad75135
Try loading two schemas
peternewman Sep 13, 2020
62ec77d
Try a different way to load two schemas
peternewman Sep 13, 2020
e520a0c
Skip the meta validation
peternewman Sep 13, 2020
808f398
Priorities?
peternewman Sep 13, 2020
48bcb8a
Test fix type validation
peternewman Sep 13, 2020
2b68255
Move to mjs. Use cfworker json-schema validator.
Bartel-C8 Jan 7, 2021
4df672b
Try validating more files
peternewman Jun 27, 2021
5f79fde
Run the new file
peternewman Jun 27, 2021
955c8ba
Install the correct module
peternewman Jun 27, 2021
42c8ba4
Try a new way to import the schema
peternewman Jun 27, 2021
3243e29
Third attempt at loading the JSON in
peternewman Jun 27, 2021
b832aca
Try and fix a syntax error
peternewman Jun 27, 2021
71d607d
Try another way to read the JSON
peternewman Jun 27, 2021
03d220c
Fix the variable name
peternewman Jun 27, 2021
a5e7812
Extract the data from the async function
peternewman Jun 27, 2021
3d3897c
Another way to try working around the errors
peternewman Jun 27, 2021
fa6383d
Refer to the path in the new way
peternewman Jun 27, 2021
29a6348
Try and just use the local path
peternewman Jun 27, 2021
49358a4
Drop an errant bracket
peternewman Jun 27, 2021
f317da1
Die when validation fails
peternewman Jun 27, 2021
8d4c2a0
Try and fix the warning
peternewman Jun 27, 2021
c8cb967
Change to local ref
peternewman Jun 27, 2021
27c059c
Resolve all paths
peternewman Jun 27, 2021
c1b42bf
Fix all paths
peternewman Jun 27, 2021
54a9446
Simplify tests
peternewman Jun 27, 2021
1b29a8c
Simplify code
peternewman Jun 27, 2021
aa322fd
Syntax!
peternewman Jun 27, 2021
4035e59
More debugging
peternewman Jun 27, 2021
d96ae81
Add the schema version
peternewman Jun 27, 2021
037c831
Don't validate for the minute
peternewman Jun 27, 2021
331433d
Format the path in a different way
peternewman Jun 27, 2021
0c0ecaf
Grab the raw schema first, then parse it
peternewman Jun 27, 2021
20afb8c
Convert the schema buffer to a string
peternewman Jun 27, 2021
7c985dc
Try removing the curly brackets
peternewman Jun 27, 2021
5cecb8d
Tweak some logging
peternewman Jun 27, 2021
e98ece9
Validate all the files
peternewman Jun 27, 2021
52f568b
Merge branch 'ssilverman:master' into patch-6
peternewman Jul 17, 2021
53196b4
Merge branch 'ssilverman:master' into patch-6
peternewman Sep 25, 2021
62b8dfb
Merge branch 'ssilverman:master' into patch-6
peternewman May 10, 2022
c073912
Standardise file and workflow names
peternewman May 10, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .github/workflows/validation-json-schema.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# GitHub Action to validate schema and example files
# https://github.com/codespell-project/actions-codespell
name: Validation - JSON-Schema
on: [push, pull_request]
jobs:
validate-schema:
name: Validate our Schema
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Node
uses: actions/setup-node@v1
with:
node-version: '12'
- name: Install dependencies
run: npm install @cfworker/json-schema
- run: node --unhandled-rejections=strict validate-schema.mjs
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.DS_Store
node_modules
1 change: 0 additions & 1 deletion rdm-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"$schema": "https://json-schema.org/draft/2019-09/schema",
"title": "Parameter Message",
"description": "The schema for the Parameter Metadata Language from Section 5 of E1.37-5. This schema is subject to change.",
"type": "object",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not 100% sure this needs to be removed, it needs double-checking.

"$ref": "#/$defs/commonPropertiesForNamed",
"properties": {
"manufacturer_id": {
Expand Down
64 changes: 64 additions & 0 deletions validate-schema.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { promises as fs } from 'fs';
import { Validator } from '@cfworker/json-schema';
import * as path from "path"
// const path = require("path");
// const JsonSchema = require("@cfworker/json-schema");
//import RdmSchema from "./rdm-schema.json"
//const { RdmSchema } = JSON.parse(fs.readFile('./rdm-schema.json'));

async function validate(validator, filename) {
// JsonSchema.setShouldMetaValidate(true);
// JsonSchema.setMetaOutputFormat(JsonSchema.VERBOSE);

// Fetch from file
const fileContent = await fs.readFile(path.resolve() + filename)
console.log("Checking file " + path.resolve() + filename);
// console.log("Contents:");
// console.log(JSON.parse(fileContent.toString()));
const output = validator.validate(JSON.parse(fileContent.toString()))
// const output = await JsonSchema.validate(schema, "file://" + filename, JsonSchema.VERBOSE);
// console.log(output);
if (output.valid) {
console.log("File " + filename + " is valid :-)");
} else {
console.log("File " + filename + " is invalid :-(", output.errors); process.exitCode = 1
}
}

//From https://gist.github.com/lovasoa/8691344#file-node-walk-es6
async function* walk(dir) {
for await (const d of await fs.opendir(path.resolve() + dir)) {
const entry = path.join(dir, d.name);
if (d.isDirectory()) yield* walk(entry);
else if (d.isFile()) yield entry;
}
}

async function validateAllFiles(validator, exampleDir) {
for await (const file of walk(exampleDir)) {
if (/\.json$/.test(file)) {
await validate(validator, file);
}
}
}

(async function() {
console.log("Loading schema");
const rawSchema = await fs.readFile(path.resolve() + "/rdm-schema.json");
//console.log("Got raw schema:");
//console.log(rawSchema.toString());
//console.log("Got parsed JSON:");
//console.log(JSON.parse(rawSchema.toString()))
const RdmSchema = JSON.parse(rawSchema.toString());
console.log("Got schema:");
console.log(RdmSchema);

console.log("Prepping validator");
const validator = new Validator(RdmSchema, '2019-09');
validator.addSchema("https://json-schema.org/draft/2019-09/schema")

console.log("Validating single file");
validate(validator, "/examples/e1.20/BOOT_SOFTWARE_VERSION_ID.json");
console.log("Validating all examples");
validateAllFiles(validator, "/examples/");
})();