Skip to content

Commit

Permalink
Added 'path' reference context.
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeLenny committed Apr 3, 2017
1 parent 0bb25c0 commit e708f55
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
11 changes: 11 additions & 0 deletions app/lib/reference-contexts.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,19 @@ function definition(ref) {
return responseSchemaDefinition(ref) || propertyArrayDefinition(ref);
}

/**
* Recognize URL paths.
* @param {String} ref the JSON reference.
* @return {Boolean} `true` if the current path is an OpenAPI `path`.
*/
function path(ref) {
var parts = ref.split("/");
return parts.length === 2 && parts.lastIndexOf("paths") === parts.length - 2 && parts[1].length > 0;
}

module.exports = {
responseSchemaDefinition: responseSchemaDefinition,
propertyArrayDefinition: propertyArrayDefinition,
definition: definition,
path: path,
};
16 changes: 16 additions & 0 deletions test/test-reference-contexts.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,20 @@ describe("reference-contexts.js", function() {

});

describe("path()", function() {

success("path", [
"paths/index.html",
"paths/{part}",
"paths/{a}-{b}-{c}",
]);

failure("path", [
"paths/",
"paths",
"paths/index.html/responses/",
]);

});

});

0 comments on commit e708f55

Please sign in to comment.