Skip to content

Commit

Permalink
Merge branch 'update/SOF-7299' of github.com:Exabyte-io/exabyte-mater…
Browse files Browse the repository at this point in the history
…ials-json into update/SOF-7299-1
  • Loading branch information
k0stik committed Mar 25, 2024
2 parents 2530230 + 9defda2 commit d455369
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 35 deletions.
8 changes: 8 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,11 @@
"@babel/register": "^7.16.0",
"@babel/runtime-corejs3": "7.16.8",
"@types/chai": "^4.3.11",
"@types/js-yaml": "^4.0.9",
"@types/json-schema-merge-allof": "^0.6.5",
"@types/mocha": "^10.0.6",
"@types/js-yaml": "^4.0.9",
"ajv": "^8.12.0",
"ajv-formats": "^2.1.1",
"js-yaml": "^4.1.0",
"json-schema": "^0.4.0",
"json-schema-deref-sync": "0.14.0",
Expand Down
5 changes: 5 additions & 0 deletions src/js/utils/ajv.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Ajv, { SchemaObject } from "ajv";
import { AnyValidateFunction } from "ajv/dist/core";
import addFormats from "ajv-formats";

import { mapObjectDeep } from "../esse/schemaUtils";
import { AnyObject } from "../esse/types";
Expand Down Expand Up @@ -42,6 +43,10 @@ const ajvValidatorAndCleanerWithCoercingTypes = new Ajv({
coerceTypes: true,
});

addFormats(ajvValidator);
addFormats(ajvValidatorAndCleaner);
addFormats(ajvValidatorAndCleanerWithCoercingTypes);

interface AjvInstanceOptions {
clean: boolean;
coerceTypes: boolean;
Expand Down
34 changes: 0 additions & 34 deletions tests/js/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import groupBy from "lodash/groupBy";
import * as path from "path";

import JSONSchemasInterface from "../../src/js/esse/JSONSchemasInterfaceServer";
import { AnyObject } from "../../src/js/esse/types";
import * as ajv from "../../src/js/utils/ajv";
import { walkDirSync } from "../../src/js/utils/filesystem";

Expand Down Expand Up @@ -36,39 +35,6 @@ describe("validate all examples", () => {
});
});

interface Example extends AnyObject {
property: string | Date;
}

describe("validate Date object", () => {
const schema = {
$id: "validate-date-object",
type: "object",
properties: {
property: {
type: "string",
format: "date-time",
},
},
};

const example1: Example = { property: new Date() };
const example2: Example = { property: "December 17, 1995 03:24:00" };
const example3: Example = { property: "Invalid Date" };

const result1 = ajv.validate(example1, schema);
const result2 = ajv.validate(example2, schema);
const result3 = ajv.validate(example3, schema);

expect(result1.isValid).to.be.equal(true);
expect(result2.isValid).to.be.equal(true);
expect(result3.isValid).to.be.equal(false);

expect(example1.property instanceof Date).to.be.equal(true);
expect(example2.property instanceof Date).to.be.equal(true);
expect(typeof example3.property === "string").to.be.equal(true);
});

describe("schema titles must be unique or empty", () => {
JSONSchemasInterface.setSchemaFolder(schemasPath);
const schemas = JSONSchemasInterface.schemasCache.values();
Expand Down

0 comments on commit d455369

Please sign in to comment.