Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/schemaUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions test/unit/util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
Expand Down