@jc21/cypress-jsonschema-validation
Advanced tools
Comparing version 0.0.1 to 1.0.0
import * as Models from './models'; | ||
import { ErrorObject } from "ajv"; | ||
export declare function JsonSchemaValidation(): { | ||
@@ -11,3 +12,3 @@ /** | ||
*/ | ||
validateJsonSchema: (options: Models.IOptions) => Promise<Error | null>; | ||
validateJsonSchema: (options: Models.IOptions) => Promise<ErrorObject<string, Record<string, any>, unknown>[] | null | Error | undefined>; | ||
}; |
@@ -15,2 +15,3 @@ "use strict"; | ||
const logger_1 = require("./logger"); | ||
const ajv_1 = require("ajv"); | ||
const defaultLog = new logger_1.default('cypress-jsonschema-validation'); | ||
@@ -44,7 +45,6 @@ function JsonSchemaValidation() { | ||
// Now validate the endpoint schema against the response | ||
const Ajv = require('ajv')({ | ||
const ajv = new ajv_1.default({ | ||
allErrors: true, | ||
format: 'full', | ||
nullable: true, | ||
verbose: true, | ||
strictSchema: false, | ||
}); | ||
@@ -55,4 +55,4 @@ if (verbose) { | ||
} | ||
const valid = Ajv.validate(options.schema, options.data); | ||
if (valid && !Ajv.errors) { | ||
const validate = ajv.compile(options.schema); | ||
if (validate(options.data)) { | ||
if (verbose) { | ||
@@ -64,4 +64,4 @@ log.success('Validation Success'); | ||
else { | ||
log.error(Ajv.errorsText()); | ||
return Ajv.errorsText(); | ||
log.error(JSON.stringify(validate.errors, null, 2)); | ||
return validate.errors; | ||
} | ||
@@ -68,0 +68,0 @@ }) |
@@ -76,3 +76,3 @@ "use strict"; | ||
test('test schema file', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const sv = index_1.JsonSchemaValidation(); | ||
const sv = (0, index_1.JsonSchemaValidation)(); | ||
const result = yield sv.validateJsonSchema({ | ||
@@ -96,3 +96,3 @@ schemaFile: './testing/schema-1.json', | ||
test('test schema file Invalid', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const sv = index_1.JsonSchemaValidation(); | ||
const sv = (0, index_1.JsonSchemaValidation)(); | ||
const result = yield sv.validateJsonSchema({ | ||
@@ -112,7 +112,7 @@ schemaFile: './testing/schema-1.json', | ||
}); | ||
expect(typeof result).toBe('string'); | ||
expect(result).toBe('data.result should have required property \'commit\''); | ||
expect(typeof result).toBe('object'); | ||
expect(getValidationErrorStrings(result)).toBe('must have required property \'commit\''); | ||
})); | ||
test('test schema object', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const sv = index_1.JsonSchemaValidation(); | ||
const sv = (0, index_1.JsonSchemaValidation)(); | ||
const result = yield sv.validateJsonSchema({ | ||
@@ -136,3 +136,3 @@ schema: schemaObject, | ||
test('test schema object Invalid', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const sv = index_1.JsonSchemaValidation(); | ||
const sv = (0, index_1.JsonSchemaValidation)(); | ||
const result = yield sv.validateJsonSchema({ | ||
@@ -152,5 +152,12 @@ schema: schemaObject, | ||
}); | ||
expect(typeof result).toBe('string'); | ||
expect(result).toBe('data.result should have required property \'commit\''); | ||
expect(typeof result).toBe('object'); | ||
expect(getValidationErrorStrings(result)).toBe('must have required property \'commit\''); | ||
})); | ||
const getValidationErrorStrings = (errors) => { | ||
if (typeof errors === 'object' && errors !== null) { | ||
const s = errors.map((error) => error.message); | ||
return s.join(', '); | ||
} | ||
return JSON.stringify(errors); | ||
}; | ||
//# sourceMappingURL=index.test.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const chalk = require("chalk"); | ||
const pc = require("picocolors"); | ||
const _ = require("lodash"); | ||
@@ -11,3 +11,3 @@ class Logger { | ||
const arr = _.values(args); | ||
arr.unshift(this.getTitle(chalk.green.bold('SUCCESS'))); | ||
arr.unshift(this.getTitle('SUCCESS', pc.green)); | ||
// @ts-ignore | ||
@@ -18,3 +18,3 @@ console.log.apply(null, arr); | ||
const arr = _.values(args); | ||
arr.unshift(this.getTitle(chalk.red.bold('ERROR'))); | ||
arr.unshift(this.getTitle('ERROR', pc.red)); | ||
// @ts-ignore | ||
@@ -25,3 +25,3 @@ console.log.apply(null, arr); | ||
const arr = _.values(args); | ||
arr.unshift(this.getTitle(chalk.blue.bold('INFO'))); | ||
arr.unshift(this.getTitle('INFO', pc.blue)); | ||
// @ts-ignore | ||
@@ -32,8 +32,8 @@ console.log.apply(null, arr); | ||
const arr = _.values(args); | ||
arr.unshift(this.getTitle(chalk.magenta.bold('DEBUG'))); | ||
arr.unshift(this.getTitle('DEBUG', pc.magenta)); | ||
// @ts-ignore | ||
console.log.apply(null, arr); | ||
} | ||
getTitle(type) { | ||
return chalk.blue.bold('[') + chalk.cyan.bold(this.title) + ' ' + type + chalk.blue.bold(']'); | ||
getTitle(type, colorFn) { | ||
return pc.blue('[') + pc.cyan(this.title) + ' ' + colorFn(pc.bold(type)) + pc.blue(']'); | ||
} | ||
@@ -40,0 +40,0 @@ } |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -10,3 +14,3 @@ if (k2 === undefined) k2 = k; | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
@@ -13,0 +17,0 @@ Object.defineProperty(exports, "__esModule", { value: true }); |
{ | ||
"name": "@jc21/cypress-jsonschema-validation", | ||
"version": "0.0.1", | ||
"version": "1.0.0", | ||
"description": "Validate your data against JSON Schema", | ||
@@ -16,3 +16,3 @@ "main": "./lib/index.js", | ||
"build": "rm -rf lib && tsc --project tsconfig.build.json", | ||
"test": "jest" | ||
"test": "jest src" | ||
}, | ||
@@ -24,20 +24,19 @@ "repository": { | ||
"devDependencies": { | ||
"@types/chalk": "^2.2.0", | ||
"@types/jest": "^26.0.9", | ||
"@types/json-schema": "^7.0.5", | ||
"@types/lodash": "^4.14.159", | ||
"@types/node": "^14.0.27", | ||
"jest": "^26.3.0", | ||
"ts-jest": "^26.2.0", | ||
"ts-node": "^8.10.2", | ||
"@types/jest": "^29.5.5", | ||
"@types/json-schema": "^7.0.13", | ||
"@types/lodash": "^4.14.199", | ||
"@types/node": "^20.8.6", | ||
"jest": "^29.7.0", | ||
"ts-jest": "^29.1.1", | ||
"ts-node": "^10.9.1", | ||
"tslint": "^6.1.3", | ||
"typescript": "^3.9.7" | ||
"typescript": "^5.2.2" | ||
}, | ||
"dependencies": { | ||
"ajv": "^6.12.3", | ||
"chalk": "^4.1.0", | ||
"json-schema": "^0.2.5", | ||
"ajv": "^8.12.0", | ||
"json-schema": "^0.4.0", | ||
"json-schema-ref-parser": "^9.0.6", | ||
"lodash": "^4.17.19" | ||
"lodash": "^4.17.21", | ||
"picocolors": "^1.0.0" | ||
} | ||
} |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
9
310
0
17627
14
+ Addedpicocolors@^1.0.0
+ Addedajv@8.13.0(transitive)
+ Addedjson-schema@0.4.0(transitive)
+ Addedjson-schema-traverse@1.0.0(transitive)
+ Addedpicocolors@1.0.0(transitive)
+ Addedrequire-from-string@2.0.2(transitive)
- Removedchalk@^4.1.0
- Removedajv@6.12.6(transitive)
- Removedansi-styles@4.3.0(transitive)
- Removedchalk@4.1.2(transitive)
- Removedcolor-convert@2.0.1(transitive)
- Removedcolor-name@1.1.4(transitive)
- Removedfast-json-stable-stringify@2.1.0(transitive)
- Removedhas-flag@4.0.0(transitive)
- Removedjson-schema@0.2.5(transitive)
- Removedjson-schema-traverse@0.4.1(transitive)
- Removedsupports-color@7.2.0(transitive)
Updatedajv@^8.12.0
Updatedjson-schema@^0.4.0
Updatedlodash@^4.17.21