mirror of
https://github.com/postmanlabs/openapi-to-postman.git
synced 2022-11-29 22:05:00 +03:00
Merge branch 'removeAjv4UseAjv6' into feature/sync-develop-and-split-develop
This commit is contained in:
3
.github/workflows/integration.yml
vendored
3
.github/workflows/integration.yml
vendored
@@ -12,6 +12,7 @@ jobs:
|
||||
with:
|
||||
node-version: '14.x'
|
||||
- run: npm install
|
||||
- run: npm run test-lint
|
||||
- run: npm run test-unit
|
||||
|
||||
Regression:
|
||||
@@ -23,4 +24,4 @@ jobs:
|
||||
with:
|
||||
node-version: '14.x'
|
||||
- run: npm install
|
||||
- run: npm run test-regression
|
||||
- run: npm run test-regression
|
||||
|
||||
7191
assets/ajv6faker.js
Normal file
7191
assets/ajv6faker.js
Normal file
File diff suppressed because it is too large
Load Diff
149
assets/json-schema-draft-04.json
Normal file
149
assets/json-schema-draft-04.json
Normal file
@@ -0,0 +1,149 @@
|
||||
{
|
||||
"id": "http://json-schema.org/draft-04/schema#",
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"description": "Core schema meta-schema",
|
||||
"definitions": {
|
||||
"schemaArray": {
|
||||
"type": "array",
|
||||
"minItems": 1,
|
||||
"items": { "$ref": "#" }
|
||||
},
|
||||
"positiveInteger": {
|
||||
"type": "integer",
|
||||
"minimum": 0
|
||||
},
|
||||
"positiveIntegerDefault0": {
|
||||
"allOf": [ { "$ref": "#/definitions/positiveInteger" }, { "default": 0 } ]
|
||||
},
|
||||
"simpleTypes": {
|
||||
"enum": [ "array", "boolean", "integer", "null", "number", "object", "string" ]
|
||||
},
|
||||
"stringArray": {
|
||||
"type": "array",
|
||||
"items": { "type": "string" },
|
||||
"minItems": 1,
|
||||
"uniqueItems": true
|
||||
}
|
||||
},
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
},
|
||||
"$schema": {
|
||||
"type": "string"
|
||||
},
|
||||
"title": {
|
||||
"type": "string"
|
||||
},
|
||||
"description": {
|
||||
"type": "string"
|
||||
},
|
||||
"default": {},
|
||||
"multipleOf": {
|
||||
"type": "number",
|
||||
"minimum": 0,
|
||||
"exclusiveMinimum": true
|
||||
},
|
||||
"maximum": {
|
||||
"type": "number"
|
||||
},
|
||||
"exclusiveMaximum": {
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"minimum": {
|
||||
"type": "number"
|
||||
},
|
||||
"exclusiveMinimum": {
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"maxLength": { "$ref": "#/definitions/positiveInteger" },
|
||||
"minLength": { "$ref": "#/definitions/positiveIntegerDefault0" },
|
||||
"pattern": {
|
||||
"type": "string",
|
||||
"format": "regex"
|
||||
},
|
||||
"additionalItems": {
|
||||
"anyOf": [
|
||||
{ "type": "boolean" },
|
||||
{ "$ref": "#" }
|
||||
],
|
||||
"default": {}
|
||||
},
|
||||
"items": {
|
||||
"anyOf": [
|
||||
{ "$ref": "#" },
|
||||
{ "$ref": "#/definitions/schemaArray" }
|
||||
],
|
||||
"default": {}
|
||||
},
|
||||
"maxItems": { "$ref": "#/definitions/positiveInteger" },
|
||||
"minItems": { "$ref": "#/definitions/positiveIntegerDefault0" },
|
||||
"uniqueItems": {
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"maxProperties": { "$ref": "#/definitions/positiveInteger" },
|
||||
"minProperties": { "$ref": "#/definitions/positiveIntegerDefault0" },
|
||||
"required": { "$ref": "#/definitions/stringArray" },
|
||||
"additionalProperties": {
|
||||
"anyOf": [
|
||||
{ "type": "boolean" },
|
||||
{ "$ref": "#" }
|
||||
],
|
||||
"default": {}
|
||||
},
|
||||
"definitions": {
|
||||
"type": "object",
|
||||
"additionalProperties": { "$ref": "#" },
|
||||
"default": {}
|
||||
},
|
||||
"properties": {
|
||||
"type": "object",
|
||||
"additionalProperties": { "$ref": "#" },
|
||||
"default": {}
|
||||
},
|
||||
"patternProperties": {
|
||||
"type": "object",
|
||||
"additionalProperties": { "$ref": "#" },
|
||||
"default": {}
|
||||
},
|
||||
"dependencies": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"anyOf": [
|
||||
{ "$ref": "#" },
|
||||
{ "$ref": "#/definitions/stringArray" }
|
||||
]
|
||||
}
|
||||
},
|
||||
"enum": {
|
||||
"type": "array",
|
||||
"minItems": 1,
|
||||
"uniqueItems": true
|
||||
},
|
||||
"type": {
|
||||
"anyOf": [
|
||||
{ "$ref": "#/definitions/simpleTypes" },
|
||||
{
|
||||
"type": "array",
|
||||
"items": { "$ref": "#/definitions/simpleTypes" },
|
||||
"minItems": 1,
|
||||
"uniqueItems": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"format": { "type": "string" },
|
||||
"allOf": { "$ref": "#/definitions/schemaArray" },
|
||||
"anyOf": { "$ref": "#/definitions/schemaArray" },
|
||||
"oneOf": { "$ref": "#/definitions/schemaArray" },
|
||||
"not": { "$ref": "#" }
|
||||
},
|
||||
"dependencies": {
|
||||
"exclusiveMaximum": [ "maximum" ],
|
||||
"exclusiveMinimum": [ "minimum" ]
|
||||
},
|
||||
"default": {}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
const Ajv = require('ajv-draft-04'),
|
||||
addFormats = require('ajv-formats');
|
||||
const Ajv = require('../../assets/ajv6faker'),
|
||||
draft4MetaSchema = require('../../assets/json-schema-draft-04.json');
|
||||
|
||||
/**
|
||||
* Used to validate schema against a value.
|
||||
@@ -20,9 +20,12 @@ function validateSchemaAJVDraft04 (schema, valueToUse) {
|
||||
ajv = new Ajv({
|
||||
// check all rules collecting all errors. instead returning after the first error.
|
||||
allErrors: true,
|
||||
strict: false
|
||||
strict: false,
|
||||
schemaId: 'id',
|
||||
unknownFormats: ['int32', 'int64'],
|
||||
nullable: true
|
||||
});
|
||||
addFormats(ajv);
|
||||
ajv.addMetaSchema(draft4MetaSchema);
|
||||
validate = ajv.compile(schema);
|
||||
validate(valueToUse);
|
||||
}
|
||||
@@ -31,6 +34,19 @@ function validateSchemaAJVDraft04 (schema, valueToUse) {
|
||||
// input was invalid. Don't throw mismatch
|
||||
return { filteredValidationError };
|
||||
}
|
||||
|
||||
if (validate.errors && validate.errors.length > 0) {
|
||||
let mapped = validate.errors.map(((error) => {
|
||||
return {
|
||||
instancePath: error.dataPath,
|
||||
keyword: error.keyword,
|
||||
message: error.message,
|
||||
params: error.params,
|
||||
schemaPath: error.schemaPath
|
||||
};
|
||||
}));
|
||||
validate.errors = mapped;
|
||||
}
|
||||
return { filteredValidationError, validate };
|
||||
}
|
||||
|
||||
|
||||
@@ -3212,7 +3212,7 @@ module.exports = {
|
||||
|
||||
mismatchObj = _.assign({
|
||||
property: property,
|
||||
transactionJsonPath: jsonPathPrefix + ajvError.instancePath,
|
||||
transactionJsonPath: jsonPathPrefix + formatDataPath(ajvError.instancePath),
|
||||
schemaJsonPath: schemaPathPrefix + '.' + localSchemaPath
|
||||
}, ajvValidationError(ajvError, { property, humanPropName }));
|
||||
|
||||
|
||||
4582
package-lock.json
generated
4582
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -117,7 +117,6 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"ajv": "8.1.0",
|
||||
"ajv-draft-04": "1.0.0",
|
||||
"ajv-formats": "2.1.1",
|
||||
"async": "3.2.1",
|
||||
"commander": "2.20.3",
|
||||
@@ -139,15 +138,15 @@
|
||||
"eslint-plugin-mocha": "5.3.0",
|
||||
"eslint-plugin-security": "1.4.0",
|
||||
"expect.js": "0.3.1",
|
||||
"nyc": "15.1.0",
|
||||
"mocha": "7.2.0",
|
||||
"nyc": "15.1.0",
|
||||
"parse-gitignore": "0.5.1"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "./scripts/test.sh",
|
||||
"test-unit": "nyc --reporter=text ./node_modules/mocha/bin/mocha \"test/unit/**/**.test.js\"",
|
||||
"test-unit": "nyc --reporter=text -x **/assets/** ./node_modules/mocha/bin/mocha \"test/unit/**/**.test.js\"",
|
||||
"test-lint": "./scripts/test-lint.sh",
|
||||
"test-system": "./node_modules/mocha/bin/mocha \"test/system/**.test.js\"",
|
||||
"test-system": "./node_modules/mocha/bin/mocha -x **/assets/** \"test/system/**.test.js\"",
|
||||
"test-regression": "./node_modules/mocha/bin/mocha test/integration/integration.test.js test/unit/sanity.test.js",
|
||||
"release": "./scripts/release.sh",
|
||||
"coverage": "nyc report --reporter=html --reporter=text mocha"
|
||||
|
||||
@@ -80,8 +80,9 @@ describe('project repository', function () {
|
||||
// Unskip before merging
|
||||
it('must point to a valid and precise (no * or ^) semver', function () {
|
||||
json.dependencies && Object.keys(json.dependencies).forEach(function (item) {
|
||||
expect(json.dependencies[item]).to.match(new RegExp('^((\\d+)\\.(\\d+)\\.(\\d+))(?:-' +
|
||||
'([\\dA-Za-z\\-]+(?:\\.[\\dA-Za-z\\-]+)*))?(?:\\+([\\dA-Za-z\\-]+(?:\\.[\\dA-Za-z\\-]+)*))?$'));
|
||||
expect(json.dependencies[item]).to.match(new RegExp('(^((\\d+)\\.(\\d+)\\.(\\d+)|' +
|
||||
'(^npm:[\\dA-Za-z\\-]+@(\\d+)\\.(\\d+)\\.(\\d+)))(?:-([\\dA-Za-z\\-]+(?:\\.[\\dA-Za-z\\-]+)*))?' +
|
||||
'(?:\\+([\\dA-Za-z\\-]+(?:\\.[\\dA-Za-z\\-]+)*))?)$'));
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -93,8 +94,9 @@ describe('project repository', function () {
|
||||
|
||||
it('must point to a valid and precise (no * or ^) semver', function () {
|
||||
json.devDependencies && Object.keys(json.devDependencies).forEach(function (item) {
|
||||
expect(json.devDependencies[item]).to.match(new RegExp('^((\\d+)\\.(\\d+)\\.(\\d+))(?:-' +
|
||||
'([\\dA-Za-z\\-]+(?:\\.[\\dA-Za-z\\-]+)*))?(?:\\+([\\dA-Za-z\\-]+(?:\\.[\\dA-Za-z\\-]+)*))?$'));
|
||||
expect(json.devDependencies[item]).to.match(new RegExp('(^((\\d+)\\.(\\d+)\\.(\\d+)|' +
|
||||
'(^npm:[\\dA-Za-z\\-]+@(\\d+)\\.(\\d+)\\.(\\d+)))(?:-([\\dA-Za-z\\-]+(?:\\.[\\dA-Za-z\\-]+)*))?' +
|
||||
'(?:\\+([\\dA-Za-z\\-]+(?:\\.[\\dA-Za-z\\-]+)*))?)$'));
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -16,6 +16,21 @@ describe('formatData method', function() {
|
||||
formattedDataPath = formatDataPath(instancePath);
|
||||
expect(formattedDataPath).to.be.equal(expectedDataPath);
|
||||
});
|
||||
|
||||
it('Should return the same string when input is a data path ".id" ', function() {
|
||||
const inputAlreadyDataPath = '.id',
|
||||
expectedDataPath = '.id',
|
||||
formattedDataPath = formatDataPath(inputAlreadyDataPath);
|
||||
expect(formattedDataPath).to.be.equal(expectedDataPath);
|
||||
});
|
||||
|
||||
it('Should return the same string when input is a data path ".test[3]" ', function() {
|
||||
const inputAlreadyDataPath = '.test[3]',
|
||||
expectedDataPath = '.test[3]',
|
||||
formattedDataPath = formatDataPath(inputAlreadyDataPath);
|
||||
expect(formattedDataPath).to.be.equal(expectedDataPath);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('handleExclusiveMaximum method', function() {
|
||||
|
||||
@@ -227,7 +227,7 @@ describe('validateSchema', function () {
|
||||
name: 'dolor consectetur Excepteur'
|
||||
},
|
||||
result = validateSchema(schema, valueToUse);
|
||||
expect(result[0].instancePath).equal('/id');
|
||||
expect(result[0].instancePath).equal('.id');
|
||||
});
|
||||
|
||||
it('should return no errors correct schema value $schema pointing to draft 06', function () {
|
||||
|
||||
Reference in New Issue
Block a user