Skip to content
Merged
Show file tree
Hide file tree
Changes from 15 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
11 changes: 11 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ module.exports = {
return cb(new UserError(_.get(schema, 'validationResult.reason', DEFAULT_INVALID_ERROR)));
},

convertV2WithTypes: function(input, options, cb) {
const enableTypeFetching = true;
var schema = new SchemaPack(input, options, MODULE_VERSION.V2, enableTypeFetching);

if (schema.validated) {
return schema.convertV2(cb);
}

return cb(new UserError(_.get(schema, 'validationResult.reason', DEFAULT_INVALID_ERROR)));
},

validate: function (input) {
var schema = new SchemaPack(input);
return schema.validationResult;
Expand Down
4 changes: 2 additions & 2 deletions lib/schemapack.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ let path = require('path'),
pathBrowserify = require('path-browserify');

class SchemaPack {
constructor (input, options = {}, moduleVersion = MODULE_VERSION.V1) {
constructor (input, options = {}, moduleVersion = MODULE_VERSION.V1, enableTypeFetching = false) {
if (input.type === schemaUtils.MULTI_FILE_API_TYPE_ALLOWED_VALUE &&
input.data && input.data[0] && input.data[0].path) {
input = schemaUtils.mapDetectRootFilesInputToFolderInput(input);
Expand All @@ -57,7 +57,7 @@ class SchemaPack {
actualStack: 0,
numberOfRequests: 0
};

this.enableTypeFetching = enableTypeFetching;
this.computedOptions = utils.mergeOptions(
// predefined options
_.keyBy(this.definedOptions, 'id'),
Expand Down
22 changes: 18 additions & 4 deletions libV2/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ module.exports = {

let preOrderTraversal = GraphLib.alg.preorder(collectionTree, 'root:collection');

let collection = {};
let collection = {},
extractedTypesObject = {};

/**
* individually start generating the folder, request, collection
Expand Down Expand Up @@ -91,16 +92,19 @@ module.exports = {
// generate the request form the node
let request = {},
collectionVariables = [],
requestObject = {};
requestObject = {},
typesObject = {};

try {
({ request, collectionVariables } = resolvePostmanRequest(context,
({ request, collectionVariables, typesObject } = resolvePostmanRequest(context,
context.openapi.paths[node.meta.path],
node.meta.path,
node.meta.method
));

requestObject = generateRequestItemObject(request);
extractedTypesObject = Object.assign({}, extractedTypesObject, typesObject);

}
catch (error) {
console.error(error);
Expand Down Expand Up @@ -217,7 +221,17 @@ module.exports = {
if (!_.isEmpty(collection.variable)) {
collection.variable = _.uniqBy(collection.variable, 'key');
}

if (context.enableTypeFetching) {
return cb(null, {
result: true,
output: [{
type: 'collection',
data: collection
}],
analytics: this.analytics || {},
extractedTypes: extractedTypesObject || {}
});
}
return cb(null, {
result: true,
output: [{
Expand Down
Loading
Loading