Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Validate yaml#28

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
ShMcK merged 9 commits intomasterfromvalidate-yaml
Jun 7, 2020
Merged
Show file tree
Hide file tree
Changes from1 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
PrevPrevious commit
NextNext commit
refactor schema validation
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
  • Loading branch information
@ShMcK
ShMcK committedJun 7, 2020
commit8cd8a8818ab0df4e2d938b13f76186be730180f1
3 changes: 2 additions & 1 deletionsrc/build.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,7 @@ import * as util from "util";
import { parse } from "./utils/parse";
import { getArg } from "./utils/args";
import { getCommits, CommitLogObject } from "./utils/commits";
import tutorialSchema from "./schema/tutorial";
import { validateSchema } from "./utils/validateSchema";
import * as T from "../typings/tutorial";

Expand DownExpand Up@@ -112,7 +113,7 @@ async function build(args: string[]) {

// validate tutorial based on json schema
try {
const valid = validateSchema(tutorial);
const valid = validateSchema(tutorialSchema,tutorial);
if (!valid) {
console.error("Tutorial validation failed. See above to see what to fix");
return;
Expand Down
7 changes: 4 additions & 3 deletionssrc/utils/validateSchema.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
import schema from "../schema/tutorial";

// https://www.npmjs.com/package/ajv
// @ts-ignore ajv typings not working
import JsonSchema from "ajv";

export function validateSchema(json: any): boolean | PromiseLike<boolean> {
export function validateSchema(
schema: any,
json: any
): boolean | PromiseLike<boolean> {
// validate using https://json-schema.org/
const jsonSchema = new JsonSchema({
allErrors: true,
Expand Down
29 changes: 0 additions & 29 deletionssrc/utils/validateSkeleton.ts
View file
Open in desktop

This file was deleted.

5 changes: 4 additions & 1 deletiontests/skeleton.test.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
import { validateSkeleton } from "../src/utils/validateSkeleton";
import { validateSchema } from "../src/utils/validateSchema";
import skeletonSchema from "../src/schema/skeleton";

const validateSkeleton = (json: any) => validateSchema(skeletonSchema, json);

const validJson = {
version: "0.1.0",
Expand Down
7 changes: 5 additions & 2 deletionstests/validate.test.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
import * as T from "../typings/tutorial";
import tutorialSchema from "../src/schema/tutorial";
import { validateSchema } from "../src/utils/validateSchema";

const validateTutorial = (json: any) => validateSchema(tutorialSchema, json);

describe("validate tutorial", () => {
it("should reject an empty tutorial", () => {
const json = { version: "here" };

const valid =validateSchema(json);
const valid =validateTutorial(json);
expect(valid).toBe(false);
});
it("should return true for a valid tutorial", () => {
Expand DownExpand Up@@ -45,7 +48,7 @@ describe("validate tutorial", () => {
],
};

const valid =validateSchema(json);
const valid =validateTutorial(json);
expect(valid).toBe(true);
});
});

[8]ページ先頭

©2009-2025 Movatter.jp