Skip to content

Commit dd03a65

Browse files
authored
Merge pull request #228 from postmanlabs/feature/missing-endpoints
Added support for missing endpoints in collection.
2 parents e1d7fef + 1cdf63a commit dd03a65

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

lib/schemaUtils.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2980,5 +2980,35 @@ module.exports = {
29802980
score: null,
29812981
pathVars: []
29822982
};
2983+
},
2984+
2985+
/**
2986+
* @param {Object} schemaPaths - OpenAPI Paths object
2987+
* @param {Array} matchedEndpoints - All matched endpoints
2988+
* @returns {Array} - Array of all MISSING_ENDPOINT objects
2989+
*/
2990+
getMissingSchemaEndpoints: function (schemaPaths, matchedEndpoints) {
2991+
let endpoints = [],
2992+
schemaJsonPath;
2993+
2994+
_.forEach(schemaPaths, (schemaPathObj, schemaPath) => {
2995+
_.forEach(_.keys(schemaPathObj), (pathKey) => {
2996+
schemaJsonPath = `$.paths[${schemaPath}].${_.toLower(pathKey)}`;
2997+
if (METHODS.includes(pathKey) && !matchedEndpoints.includes(schemaJsonPath)) {
2998+
endpoints.push({
2999+
property: 'ENDPOINT',
3000+
transactionJsonPath: null,
3001+
schemaJsonPath,
3002+
reasonCode: 'MISSING_ENDPOINT',
3003+
reason: `The endpoint "${_.toUpper(pathKey)} ${schemaPath}" is missing in collection`,
3004+
endpoint: {
3005+
method: _.toUpper(pathKey),
3006+
path: schemaPath
3007+
}
3008+
});
3009+
}
3010+
});
3011+
});
3012+
return endpoints;
29833013
}
29843014
};

lib/schemapack.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,8 @@ class SchemaPack {
309309
let schema = this.openapi,
310310
componentsAndPaths,
311311
options = this.computedOptions,
312-
schemaResolutionCache = this.schemaResolutionCache;
312+
schemaResolutionCache = this.schemaResolutionCache,
313+
matchedEndpoints = [];
313314

314315

315316
if (!this.validated) {
@@ -377,6 +378,7 @@ class SchemaPack {
377378
return setTimeout(() => {
378379
// 2. perform validation for each identified matchedPath (schema endpoint)
379380
return async.map(matchedPaths, (matchedPath, pathsCallback) => {
381+
matchedEndpoints.push(matchedPath.jsonPath);
380382
// 3. validation involves checking these individual properties
381383
async.parallel({
382384
path: function(cb) {
@@ -462,7 +464,8 @@ class SchemaPack {
462464
});
463465

464466
retVal = {
465-
requests: _.keyBy(result, 'requestId')
467+
requests: _.keyBy(result, 'requestId'),
468+
missingEndpoints: schemaUtils.getMissingSchemaEndpoints(schema.paths, matchedEndpoints)
466469
};
467470

468471
callback(null, retVal);

0 commit comments

Comments
 (0)