Skip to content

Commit e85b374

Browse files
committed
undo validation
undo validation
1 parent c7feb13 commit e85b374

File tree

4 files changed

+29
-55
lines changed

4 files changed

+29
-55
lines changed

lib/ajValidation/ajvValidation.js

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,6 @@ function getDraftToUse(localDraft, jsonSchemaDialect) {
5050
return localDraft ? localDraft : jsonSchemaDialect;
5151
}
5252

53-
/**
54-
* Checks if the schema object property is deprecated
55-
*
56-
* @param {*} schema - Schema object used in validation
57-
* @returns {Boolean} postman variable or not
58-
*/
59-
function isDeprecated (schema) {
60-
return schema ? schema.deprecated ? schema.deprecated : false : false;
61-
}
62-
6353
/**
6454
* Used to validate schema against a value.
6555
* NOTE: Used in assets/json-schema-faker.js to validate schema example
@@ -117,18 +107,6 @@ function validateSchema (schema, valueToUse, options = {}, jsonSchemaDialect) {
117107
return !isTypeValue(valueToValidate, schemaToUse);
118108
}
119109

120-
if (validationError.keyword === 'required') {
121-
let schemaDataPath = formatDataPath(formatSchemaPathFromAJVErrorToConvertToDataPath(validationError.schemaPath)),
122-
propertyError = _.get(validationError, 'params.missingProperty') || '',
123-
schemaPropertyPath = schemaDataPath.replace('.required', '.properties.') + propertyError;
124-
125-
if (options.includeDeprecated === false &&
126-
isDeprecated(_.get(schema, schemaPropertyPath))) {
127-
return false;
128-
}
129-
return true;
130-
}
131-
132110
return true;
133111
});
134112

lib/schemaUtils.js

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3910,35 +3910,31 @@ module.exports = {
39103910
return param.key === qp.name;
39113911
})) {
39123912

3913-
if (shouldAddDeprecatedOperation(qp, options)) {
3914-
3915-
// assign parameter example(s) as schema examples;
3916-
this.assignParameterExamples(qp);
3913+
// assign parameter example(s) as schema examples;
3914+
this.assignParameterExamples(qp);
39173915

3918-
mismatchObj = {
3919-
property: mismatchProperty,
3920-
transactionJsonPath: transactionPathPrefix,
3921-
schemaJsonPath: qp.pathPrefix + '[?(@.name==\'' + qp.name + '\')]',
3922-
reasonCode: 'MISSING_IN_REQUEST',
3923-
reason: `The required query parameter "${qp.name}" was not found in the transaction`
3924-
};
3916+
mismatchObj = {
3917+
property: mismatchProperty,
3918+
transactionJsonPath: transactionPathPrefix,
3919+
schemaJsonPath: qp.pathPrefix + '[?(@.name==\'' + qp.name + '\')]',
3920+
reasonCode: 'MISSING_IN_REQUEST',
3921+
reason: `The required query parameter "${qp.name}" was not found in the transaction`
3922+
};
39253923

3926-
if (options.suggestAvailableFixes) {
3927-
mismatchObj.suggestedFix = {
3924+
if (options.suggestAvailableFixes) {
3925+
mismatchObj.suggestedFix = {
3926+
key: qp.name,
3927+
actualValue: null,
3928+
suggestedValue: {
39283929
key: qp.name,
3929-
actualValue: null,
3930-
suggestedValue: {
3931-
key: qp.name,
3932-
value: safeSchemaFaker(qp.schema || {}, 'example', PROCESSING_TYPE.VALIDATION,
3933-
PARAMETER_SOURCE.REQUEST, components, SCHEMA_FORMATS.DEFAULT, options.indentCharacter, schemaCache,
3934-
options.stackLimit, options.includeDeprecated),
3935-
description: this.getParameterDescription(qp)
3936-
}
3937-
};
3938-
}
3939-
mismatches.push(mismatchObj);
3930+
value: safeSchemaFaker(qp.schema || {}, 'example', PROCESSING_TYPE.VALIDATION,
3931+
PARAMETER_SOURCE.REQUEST, components, SCHEMA_FORMATS.DEFAULT, options.indentCharacter, schemaCache,
3932+
options.stackLimit, options.includeDeprecated),
3933+
description: this.getParameterDescription(qp)
3934+
}
3935+
};
39403936
}
3941-
3937+
mismatches.push(mismatchObj);
39423938
}
39433939
});
39443940
return callback(null, _.concat(_.flatten(res), mismatches));

test/unit/validator.test.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1894,7 +1894,7 @@ describe('validateTransaction convert and validate schemas with deprecated eleme
18941894
});
18951895
});
18961896

1897-
it('Should convert and validate without error excluding deprecated query param when ' +
1897+
it('Should convert and validate required parameter even if it is deprecated' +
18981898
'includeDeprecated is false', function() {
18991899
const openAPI = path.join(__dirname, VALID_OPENAPI_FOLDER_PATH + '/petstore_deprecated_param.json'),
19001900
openAPIData = fs.readFileSync(openAPI, 'utf8'),
@@ -1921,16 +1921,14 @@ describe('validateTransaction convert and validate schemas with deprecated eleme
19211921
expect(err).to.be.null;
19221922
expect(result.missingEndpoints.length).to.eq(0);
19231923
let requestIds = Object.keys(result.requests);
1924-
requestIds.forEach((requestId) => {
1925-
expect(result.requests[requestId].endpoints[0]).to.not.be.undefined;
1926-
expect(result.requests[requestId].endpoints[0].matched).to.be.true;
1927-
});
1924+
expect(result.requests[requestIds[0]].endpoints[0].matched).to.be.false;
1925+
expect(result.requests[requestIds[0]].endpoints[0].mismatches[0].reason.includes('variable2')).to.be.true;
19281926
});
19291927
});
19301928

19311929
});
19321930

1933-
it('Should convert and validate without error excluding deprecated query param when ' +
1931+
it('Should convert and validate required parameter even if it is deprecated' +
19341932
'includeDeprecated is true', function() {
19351933
const openAPI = path.join(__dirname, VALID_OPENAPI_FOLDER_PATH + '/petstore_deprecated_param.json'),
19361934
openAPIData = fs.readFileSync(openAPI, 'utf8'),

test/unit/xajvValidation.test.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ describe('validateSchema', function () {
580580
expect(result[0].keyword).to.equal('type');
581581
});
582582

583-
it('Should not report error with deprecated property when is not present and' +
583+
it('Should report error with deprecated property when is not present and it is required' +
584584
' includeDeprecated is false', function () {
585585
const schema = {
586586
type: 'object',
@@ -616,7 +616,8 @@ describe('validateSchema', function () {
616616
}
617617
},
618618
result = validateSchema(schema, valueToUse, { includeDeprecated: false });
619-
expect(result).to.be.empty;
619+
expect(result).to.not.be.empty;
620+
expect(result[0].params.missingProperty).to.equal('id');
620621
});
621622

622623
it('Should report error with deprecated property when is not present and' +
@@ -656,6 +657,7 @@ describe('validateSchema', function () {
656657
},
657658
result = validateSchema(schema, valueToUse, { includeDeprecated: true });
658659
expect(result).to.not.be.empty;
660+
expect(result[0].params.missingProperty).to.equal('id');
659661
});
660662
});
661663

0 commit comments

Comments
 (0)