Skip to content

Validate/schema #9

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

Merged
merged 3 commits into from
May 31, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Prev Previous commit
cleanup merge conflicts
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
  • Loading branch information
ShMcK committed May 31, 2020
commit b2af5f966fd13ff8f5831e9f92e7a3780115ad0f
1 change: 1 addition & 0 deletions src/build.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as yamlParser from "js-yaml";
import * as path from "path";
import * as _ from "lodash";
import * as fs from "fs";
Expand Down
2 changes: 1 addition & 1 deletion src/create.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as ncp from "ncp";
import ncp from "ncp";
import * as path from "path";
import { promisify } from "util";

Expand Down
5 changes: 3 additions & 2 deletions src/utils/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import schema from "./schema";
// @ts-ignore ajv typings not working
import JsonSchema from "ajv";

export function validateSchema(json: T.Tutorial) {
export function validateSchema(json: any) {
// validate using https://json-schema.org/
const jsonSchema = new JsonSchema({ allErrors: true, verbose: true });
// support draft-07 of json schema
jsonSchema.addMetaSchema(require("ajv/lib/refs/json-schema-draft-07.json"));

const valid = jsonSchema.compile(schema, json);
const validator = jsonSchema.compile(schema);
const valid = validator(json);

if (!valid) {
// log errors
Expand Down