-
Notifications
You must be signed in to change notification settings - Fork 3
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
peternewman
wants to merge
67
commits into
ssilverman:master
Choose a base branch
from
peternewman:patch-6
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
67 commits
Select commit
Hold shift + click to select a range
546e917
Add codespell action
peternewman ecb58e5
Fix a typo
peternewman ad2dda0
Validate the schema itself
peternewman ee04d55
First go at validation
peternewman 0938780
Remove awaits
peternewman d81e07b
Ensure we meta-validate
peternewman 6b7e1a0
Switch to just our schema and validate a file
peternewman 7b4e231
Try and deal with unhandled promises
peternewman 04e917c
Try and exit when we get an error
peternewman d863a11
Validate two files
peternewman 723cdd2
Try validating all files
peternewman 4848bb3
Try and fix the async issue
peternewman 223ef8d
Fix some variable names
peternewman b2a7f57
Hopefully fix the variable scope
peternewman 000a77b
Try and fix the sync issues
peternewman 63a1c9b
Try and make it all async
peternewman 0d72dec
Try going sync again
peternewman 638931a
Try a better file list function
peternewman b16b1b0
Try to fix the path
peternewman 0ac9704
Fix the paths
peternewman 4518ed1
Try asyncing again
peternewman 4037cca
Try being a bit more async
peternewman 56ec4db
Fix a variable
peternewman ee0ee48
Async walk too
peternewman f4a91ea
Fix the variable names
peternewman cce903c
Make sure we've fetched the base schema
peternewman ceb9fdb
Await the base schema
peternewman ad75135
Try loading two schemas
peternewman 62ec77d
Try a different way to load two schemas
peternewman e520a0c
Skip the meta validation
peternewman 808f398
Priorities?
peternewman 48bcb8a
Test fix type validation
peternewman 2b68255
Move to mjs. Use cfworker json-schema validator.
Bartel-C8 4df672b
Try validating more files
peternewman 5f79fde
Run the new file
peternewman 955c8ba
Install the correct module
peternewman 42c8ba4
Try a new way to import the schema
peternewman 3243e29
Third attempt at loading the JSON in
peternewman b832aca
Try and fix a syntax error
peternewman 71d607d
Try another way to read the JSON
peternewman 03d220c
Fix the variable name
peternewman a5e7812
Extract the data from the async function
peternewman 3d3897c
Another way to try working around the errors
peternewman fa6383d
Refer to the path in the new way
peternewman 29a6348
Try and just use the local path
peternewman 49358a4
Drop an errant bracket
peternewman f317da1
Die when validation fails
peternewman 8d4c2a0
Try and fix the warning
peternewman c8cb967
Change to local ref
peternewman 27c059c
Resolve all paths
peternewman c1b42bf
Fix all paths
peternewman 54a9446
Simplify tests
peternewman 1b29a8c
Simplify code
peternewman aa322fd
Syntax!
peternewman 4035e59
More debugging
peternewman d96ae81
Add the schema version
peternewman 037c831
Don't validate for the minute
peternewman 331433d
Format the path in a different way
peternewman 0c0ecaf
Grab the raw schema first, then parse it
peternewman 20afb8c
Convert the schema buffer to a string
peternewman 7c985dc
Try removing the curly brackets
peternewman 5cecb8d
Tweak some logging
peternewman e98ece9
Validate all the files
peternewman 52f568b
Merge branch 'ssilverman:master' into patch-6
peternewman 53196b4
Merge branch 'ssilverman:master' into patch-6
peternewman 62b8dfb
Merge branch 'ssilverman:master' into patch-6
peternewman c073912
Standardise file and workflow names
peternewman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
.DS_Store | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/"); | ||
})(); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.