Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AB-290]-Extracting-type-information from OAS #834

Merged
merged 19 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from 10 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
5 changes: 3 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,8 @@ class SchemaPack {
actualStack: 0,
numberOfRequests: 0
};

this.enableTypeFetching = enableTypeFetching;
this.resolvedSchemaTypes = [];
barshan23 marked this conversation as resolved.
Show resolved Hide resolved
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 = {},
finalExtractedTypesObject = {};
barshan23 marked this conversation as resolved.
Show resolved Hide resolved

/**
* 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 = {},
extractedTypesObject = {};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Can we name the variable typesObject instead of extracted types object ?


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

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

}
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: finalExtractedTypesObject || []
});
}
return cb(null, {
result: true,
output: [{
Expand Down
Loading
Loading