@@ -2236,6 +2236,9 @@ module.exports = {
22362236 invalidJson = false ,
22372237 ajv , validate ,
22382238 valueToUse = value ,
2239+ isPmVariable = ( value ) => {
2240+ return _ . isString ( value ) && _ . startsWith ( value , '{{' ) && _ . endsWith ( value , '}}' ) ;
2241+ } ,
22392242
22402243 // This is dereferenced schema (converted to JSON schema for validation)
22412244 schema = deref . resolveRefs ( openApiSchemaObj , parameterSourceOption , components ,
@@ -2257,7 +2260,14 @@ module.exports = {
22572260 // When processing a reference, schema.type could also be undefined
22582261 if ( schema && schema . type ) {
22592262 if ( typeof schemaTypeToJsValidator [ schema . type ] === 'function' ) {
2260- if ( ! schemaTypeToJsValidator [ schema . type ] ( valueToUse ) ) {
2263+ let isCorrectType = schemaTypeToJsValidator [ schema . type ] ( valueToUse ) ;
2264+
2265+ // Treat unresolved postman collection/environment variable as correct type
2266+ if ( options . ignoreUnresolvedVariables && ! isCorrectType && isPmVariable ( valueToUse ) ) {
2267+ isCorrectType = ! isCorrectType ;
2268+ }
2269+
2270+ if ( ! isCorrectType ) {
22612271 // if type didn't match, no point checking for AJV
22622272 let reason = '' ,
22632273 mismatchObj ;
@@ -2337,16 +2347,26 @@ module.exports = {
23372347 // input was invalid. Don't throw mismatch
23382348 }
23392349
2340- // As OAS only supports some of Json Schema keywords, and Ajv is supporting all keywords from Draft 7
2341- // Remove keyword currently not supported in OAS to make both compatible with each other
2350+ // Filter validation errors for following cases
23422351 filteredValidationError = _ . filter ( validate . errors , ( validationError ) => {
23432352 // for invalid `propertyNames` two error are thrown by Ajv, which include error with `pattern` keyword
23442353 if ( validationError . keyword === 'pattern' ) {
23452354 return ! _ . has ( validationError , 'propertyName' ) ;
23462355 }
23472356
2348- // Following are non-supported keywords in OpenAPI spec but supported in Json schema (Ajv)
2349- return ! _ . includes ( [ 'propertyNames' , 'const' , 'additionalItems' , 'dependencies' ] , validationError . keyword ) ;
2357+ // As OAS only supports some of Json Schema keywords, and Ajv is supporting all keywords from Draft 7
2358+ // Remove keyword currently not supported in OAS to make both compatible with each other
2359+ else if ( _ . includes ( [ 'propertyNames' , 'const' , 'additionalItems' , 'dependencies' ] ,
2360+ validationError . keyword ) ) {
2361+ return false ;
2362+ }
2363+
2364+ // Ignore unresolved variables from mismatch if option is set
2365+ else if ( options . ignoreUnresolvedVariables &&
2366+ isPmVariable ( _ . get ( valueToUse , validationError . dataPath . slice ( 1 ) ) ) ) {
2367+ return false ;
2368+ }
2369+ return true ;
23502370 } ) ;
23512371
23522372 // sort errors based on dataPath, as this will ensure no overriding later
0 commit comments