mirror of
https://github.com/postmanlabs/openapi-to-postman.git
synced 2022-11-29 22:05:00 +03:00
Comments
This commit is contained in:
@@ -88,7 +88,6 @@ var sdk = require('postman-collection'),
|
||||
// saving in util for global access
|
||||
util.components = openapi.components;
|
||||
|
||||
|
||||
// ---- Collection Variables ----
|
||||
// adding the collection variables for all the necessary root level variables
|
||||
// and adding them to the collection variables
|
||||
|
||||
29
lib/util.js
29
lib/util.js
@@ -173,12 +173,12 @@ module.exports = {
|
||||
openApiObj = parse.asYaml(openApiSpec);
|
||||
}
|
||||
catch (yamlException) {
|
||||
// Could be a JSON as well
|
||||
// Not valid YAML, could be a JSON as well
|
||||
try {
|
||||
openApiObj = parse.asJson(openApiSpec);
|
||||
}
|
||||
catch (jsonException) {
|
||||
// Its neither JSON nor YAML
|
||||
// It's neither JSON nor YAML
|
||||
return {
|
||||
result: false,
|
||||
reason: 'Invalid format. Input must be in YAML or JSON format'
|
||||
@@ -282,6 +282,7 @@ module.exports = {
|
||||
trie = new Trie(new Node({
|
||||
name: '/'
|
||||
})),
|
||||
// returns a list of methods supported at each path
|
||||
getPathMethods = function(pathKeys) {
|
||||
var methods = [];
|
||||
pathKeys.forEach(function(element) {
|
||||
@@ -305,7 +306,7 @@ module.exports = {
|
||||
currentPath = path.split('/');
|
||||
pathLength = currentPath.length;
|
||||
|
||||
// stores names of methods in path to pathMethods, if they present in METHODS.
|
||||
// stores names of methods in path to pathMethods, if they're present in METHODS.
|
||||
pathMethods = getPathMethods(Object.keys(currentPathObject));
|
||||
// the number of requests under this node
|
||||
currentPathRequestCount = pathMethods.length;
|
||||
@@ -330,13 +331,13 @@ module.exports = {
|
||||
currentNode = currentNode.children[currentPath[i]];
|
||||
}
|
||||
|
||||
// handling common parameters for all the methods in the current path item
|
||||
// extracting common parameters for all the methods in the current path item
|
||||
if (currentPathObject.hasOwnProperty('parameters')) {
|
||||
commonParams = currentPathObject.parameters;
|
||||
delete currentPathObject.parameters;
|
||||
}
|
||||
|
||||
// handling the server object at the path item level
|
||||
// storing common path/collection vars from the server object at the path item level
|
||||
if (currentPathObject.hasOwnProperty('servers')) {
|
||||
pathLevelServers = currentPathObject.servers;
|
||||
collectionVariables[path + 'Url'] = pathLevelServers[0];
|
||||
@@ -372,7 +373,7 @@ module.exports = {
|
||||
|
||||
return {
|
||||
tree: trie,
|
||||
variables: collectionVariables // server variables, that are to be converted into collection variables.
|
||||
variables: collectionVariables // server variables that are to be converted into collection variables.
|
||||
};
|
||||
},
|
||||
|
||||
@@ -382,11 +383,11 @@ module.exports = {
|
||||
* method: request(operation)-level, root: spec-level, param: url-level
|
||||
* @param {Array<object>} providedPathVars - Array of path variables
|
||||
* @param {object} commonPathVariables - Object of path variables taken from the specification
|
||||
* @returns {Array<object>} returns array of variables
|
||||
* @returns {Array<object>} returns array of sdk.Variable
|
||||
*/
|
||||
convertPathVariables: function(type, providedPathVars, commonPathVariables) {
|
||||
var variables = providedPathVars;
|
||||
// converting the base uri path variables if any
|
||||
// converting the base uri path variables, if any
|
||||
if (type === 'root' || type === 'method') {
|
||||
_.forOwn(commonPathVariables, (value, key) => {
|
||||
variables.push({
|
||||
@@ -464,7 +465,7 @@ module.exports = {
|
||||
if (resource.type === 'item-group') {
|
||||
// 3 options:
|
||||
|
||||
// folder with more than one request in its subtree
|
||||
// 1. folder with more than one request in its subtree
|
||||
if (resource.requestCount > 1) {
|
||||
// only return a Postman folder if this folder has>1 requests in its subtree
|
||||
// otherwise we can end up with 10 levels of folders
|
||||
@@ -493,13 +494,13 @@ module.exports = {
|
||||
return itemGroup;
|
||||
}
|
||||
|
||||
// it's a folder with just one request in its subtree
|
||||
// 2. it's a folder with just one request in its subtree
|
||||
// recurse DFS-ly to find that one request
|
||||
if (resource.requests.length === 1) {
|
||||
return this.convertChildToItemGroup(openapi, resource.requests[0]);
|
||||
}
|
||||
|
||||
// it has only request
|
||||
// 3. it has only request
|
||||
for (subChild in resource.children) {
|
||||
if (resource.children.hasOwnProperty(subChild) && resource.children[subChild].requestCount === 1) {
|
||||
return this.convertChildToItemGroup(openapi, resource.children[subChild]);
|
||||
@@ -511,6 +512,12 @@ module.exports = {
|
||||
return item;
|
||||
},
|
||||
|
||||
/**
|
||||
* Gets helper object based on the root spec and the operation.security object
|
||||
* @param {*} openapi
|
||||
* @param {Array<object>} securitySet
|
||||
* @returns {object} The authHelper to use while constructing the Postman Request
|
||||
*/
|
||||
getAuthHelper: function(openapi, securitySet) {
|
||||
var securityDef,
|
||||
helper;
|
||||
|
||||
Reference in New Issue
Block a user