Skip to content

Commit

Permalink
[AB-290]-Extracting-type-information from OAS (#834)
Browse files Browse the repository at this point in the history
- AB-290-extracting-type-information
  • Loading branch information
AyushShri authored Jan 9, 2025
1 parent d092f0f commit 20aa037
Show file tree
Hide file tree
Showing 9 changed files with 619 additions and 51 deletions.
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 = {},
requestTypesObject = {};

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

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

}
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

0 comments on commit 20aa037

Please sign in to comment.