diff --git a/lib/schemaUtils.js b/lib/schemaUtils.js index 3ad72128..2590c8cf 100644 --- a/lib/schemaUtils.js +++ b/lib/schemaUtils.js @@ -2392,8 +2392,11 @@ module.exports = { findPathVariablesFromPath: function (path) { // /{{path}}/{{file}}.{{format}}/{{hello}} return [ '{{path}}', '{{hello}}' ] + // /tasks/{{id}}:cancel returns [ '/{{id}}' ] — `:` is the boundary used by + // AIP-136 custom methods and is not expected inside a path-segment literal + // in OpenAPI path templates, so it's a safe lookahead. // https://regex101.com/r/XGL4Gh/1 - return path.match(/(\/\{\{[^\/\{\}]+\}\})(?=\/|$)/g); + return path.match(/(\/\{\{[^\/\{\}]+\}\})(?=\/|$|:)/g); }, /** Finds all the possible collection variables in a given path string diff --git a/test/unit/util.test.js b/test/unit/util.test.js index 388f10a5..4f05c745 100644 --- a/test/unit/util.test.js +++ b/test/unit/util.test.js @@ -2821,6 +2821,13 @@ describe('SCHEMA UTILITY FUNCTION TESTS ', function () { pathVars = SchemaUtils.findPathVariablesFromPath('/send-sms.{{format}}'); expect(pathVars).to.equal(null); + + pathVars = SchemaUtils.findPathVariablesFromPath('/tasks/{{id}}:cancel'); + expect(pathVars[0]).to.equal('/{{id}}'); + + pathVars = SchemaUtils.findPathVariablesFromPath('/users/{{userId}}:archive/items/{{itemId}}'); + expect(pathVars[0]).to.equal('/{{userId}}'); + expect(pathVars[1]).to.equal('/{{itemId}}'); done(); }); });