mirror of
https://github.com/postmanlabs/openapi-to-postman.git
synced 2022-11-29 22:05:00 +03:00
Adding components generation
This commit is contained in:
@@ -89,7 +89,8 @@ const { formatDataPath, checkIsCorrectType, isKnownType } = require('./common/sc
|
||||
DEFAULT_SCHEMA_UTILS = require('./30XUtils/schemaUtils30X'),
|
||||
{ getRelatedFiles } = require('./relatedFiles'),
|
||||
{ compareVersion } = require('./common/versionUtils.js'),
|
||||
parse = require('./parse');
|
||||
parse = require('./parse'),
|
||||
{ getRelatedFilesAndBundleData } = require('./bundle.js');
|
||||
/* eslint-enable */
|
||||
|
||||
// See https://github.com/json-schema-faker/json-schema-faker/tree/master/docs#available-options
|
||||
@@ -4812,6 +4813,28 @@ module.exports = {
|
||||
};
|
||||
},
|
||||
|
||||
getRelatedFilesData(parsedRootFiles, inputData, origin) {
|
||||
const data = parsedRootFiles.map((root) => {
|
||||
let relatedData = getRelatedFiles(root, inputData, origin),
|
||||
result = {
|
||||
rootFile: { path: root.fileName },
|
||||
relatedFiles: relatedData.relatedFiles,
|
||||
missingRelatedFiles: relatedData.missingRelatedFiles
|
||||
};
|
||||
return result;
|
||||
});
|
||||
return data;
|
||||
},
|
||||
|
||||
getComponentsObject(parsedRootFiles, inputData, origin, version) {
|
||||
const data = parsedRootFiles.map((root) => {
|
||||
let calledAs = [],
|
||||
componentsData = getRelatedFilesAndBundleData(root, inputData, origin, version, calledAs);
|
||||
return componentsData;
|
||||
});
|
||||
return data;
|
||||
},
|
||||
|
||||
/**
|
||||
*
|
||||
* @description Takes in root files, input data and origin process every root
|
||||
@@ -4820,24 +4843,20 @@ module.exports = {
|
||||
* @param {array} inputData - [{path:string}]}
|
||||
* @param {string} origin - process origin
|
||||
* @param {string} version - process specification version
|
||||
* @param {boolean} toBundle - if it will be used in bundle
|
||||
*
|
||||
* @returns {object} root files information and data input
|
||||
*/
|
||||
mapProcessRelatedFiles(rootFiles, inputData, origin, version) {
|
||||
mapProcessRelatedFiles(rootFiles, inputData, origin, version, toBundle = false) {
|
||||
let parsedRootFiles = rootFiles.map((rootFile) => {
|
||||
let parsedContent = parse.getOasObject(rootFile.content);
|
||||
return { fileName: rootFile.fileName, content: rootFile.content, parsed: parsedContent };
|
||||
}).filter((rootWithParsedContent) => {
|
||||
return compareVersion(version, rootWithParsedContent.parsed.oasObject.openapi);
|
||||
}),
|
||||
data = parsedRootFiles.map((root) => {
|
||||
let { relatedFiles, missingRelatedFiles } = getRelatedFiles(root, inputData, origin);
|
||||
return {
|
||||
rootFile: { path: root.fileName },
|
||||
relatedFiles,
|
||||
missingRelatedFiles
|
||||
};
|
||||
});
|
||||
data = toBundle ?
|
||||
this.getComponentsObject(parsedRootFiles, inputData, origin, version) :
|
||||
this.getRelatedFilesData(parsedRootFiles, inputData, origin);
|
||||
return data;
|
||||
},
|
||||
|
||||
@@ -4846,15 +4865,16 @@ module.exports = {
|
||||
* @description Takes in a folder and identifies the related files from the
|
||||
* root file perspective (using $ref property)
|
||||
* @param {string} inputRelatedFiles - {rootFile:{path:string}, data: [{path:string}]}
|
||||
* @param {boolean} toBundle - if true it will return the bundle data
|
||||
*
|
||||
* @returns {object} root files information and data input
|
||||
*/
|
||||
processRelatedFiles(inputRelatedFiles) {
|
||||
processRelatedFiles(inputRelatedFiles, toBundle = false) {
|
||||
let version = inputRelatedFiles.specificationVersion ? inputRelatedFiles.specificationVersion : '3.0.0',
|
||||
res = {
|
||||
result: true,
|
||||
output: {
|
||||
type: 'relatedFiles',
|
||||
type: toBundle ? 'bundle' : 'relatedFiles',
|
||||
specification: {
|
||||
type: 'OpenAPI',
|
||||
version: version
|
||||
@@ -4865,9 +4885,12 @@ module.exports = {
|
||||
};
|
||||
if (inputRelatedFiles.rootFiles && inputRelatedFiles.rootFiles.length > 0) {
|
||||
res.output.data = this.mapProcessRelatedFiles(inputRelatedFiles.rootFiles, inputRelatedFiles.data,
|
||||
inputRelatedFiles.origin, version);
|
||||
inputRelatedFiles.origin, version, toBundle);
|
||||
return res;
|
||||
}
|
||||
else {
|
||||
return res;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user