mirror of
https://github.com/postmanlabs/openapi-to-postman.git
synced 2022-11-29 22:05:00 +03:00
Fix PR request changes
Fix PR request changes
This commit is contained in:
@@ -2,7 +2,10 @@ const {
|
||||
isExtRef,
|
||||
getKeyInComponents,
|
||||
getJsonPointerRelationToRoot,
|
||||
jsonPointerEncodeAndReplace
|
||||
jsonPointerEncodeAndReplace,
|
||||
removeLocalReferenceFromPath,
|
||||
localPointer,
|
||||
jsonPointerLevelSeparator
|
||||
} = require('./jsonPointer'),
|
||||
traverseUtility = require('traverse'),
|
||||
parse = require('./parse.js');
|
||||
@@ -35,18 +38,6 @@ function comparePaths(path1, path2) {
|
||||
return path1 === path2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the local pointer inside a path
|
||||
* aab.yaml#component returns aab.yaml
|
||||
* @param {string} refValue - value of the $ref property
|
||||
* @returns {string} - the calculated path only
|
||||
*/
|
||||
function removeLocalReferenceFromPath(refValue) {
|
||||
if (refValue.$ref.includes('#')) {
|
||||
return refValue.$ref.split('#')[0];
|
||||
}
|
||||
return refValue.$ref;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the path relative to parent
|
||||
@@ -67,7 +58,7 @@ function calculatePath(parentFileName, referencePath) {
|
||||
* @returns {object} - Detect root files result object
|
||||
*/
|
||||
function findNodeFromPath(referencePath, allData) {
|
||||
const partialComponents = referencePath.split('#');
|
||||
const partialComponents = referencePath.split(localPointer);
|
||||
let isPartial = partialComponents.length > 1,
|
||||
node = allData.find((node) => {
|
||||
if (isPartial) {
|
||||
@@ -140,8 +131,8 @@ function getContentFromTrace(content, partial) {
|
||||
if (!partial) {
|
||||
return content;
|
||||
}
|
||||
partial = partial[0] === '/' ? partial.substring(1) : partial;
|
||||
const trace = partial.split('/');
|
||||
partial = partial[0] === jsonPointerLevelSeparator ? partial.substring(1) : partial;
|
||||
const trace = partial.split(jsonPointerLevelSeparator);
|
||||
let currentValue = content;
|
||||
for (let place of trace) {
|
||||
currentValue = currentValue[place];
|
||||
@@ -202,7 +193,7 @@ function getTraceFromParentKeyInComponents(nodeContext, property) {
|
||||
parentKeys :
|
||||
[key, ...parentKeys],
|
||||
nodeTrace = getRootFileTrace(nodeParentsKey),
|
||||
[file, local] = property.split('#'),
|
||||
[file, local] = property.split(localPointer),
|
||||
[keyTraceInComponents, inComponents] = getKeyInComponents(nodeTrace, file, local);
|
||||
return [keyTraceInComponents, inComponents];
|
||||
}
|
||||
@@ -237,7 +228,7 @@ function getReferences (currentNode, refTypeResolver, pathSolver, parentFilename
|
||||
nodeTrace
|
||||
);
|
||||
let newValue,
|
||||
[file, local] = tempRef.split('#'),
|
||||
[file, local] = tempRef.split(localPointer),
|
||||
nodeData = findNodeFromPath(file, allData).content,
|
||||
nodeContent = nodeData ?
|
||||
parse.getOasObject(nodeData).oasObject :
|
||||
@@ -325,9 +316,7 @@ function getAdjacentAndMissingToBundle (currentNode, allData, specRoot, globalCo
|
||||
}
|
||||
}
|
||||
});
|
||||
if (missingNodes.length > 0) {
|
||||
throw new Error('Some files are missing, run detectRelatedFiles to get more detail');
|
||||
}
|
||||
|
||||
return { graphAdj, missingNodes, bundleDataInAdjacent, currentNode };
|
||||
}
|
||||
|
||||
@@ -352,7 +341,7 @@ function generateComponentsObject (documentContext, rootContent, refTypeResolver
|
||||
);
|
||||
if (hasReferenceTypeKey) {
|
||||
let tempRef = property.$ref,
|
||||
[, local] = tempRef.split('#'),
|
||||
[, local] = tempRef.split(localPointer),
|
||||
refData = documentContext[tempRef];
|
||||
if (local) {
|
||||
let related = refData.related,
|
||||
@@ -380,7 +369,9 @@ function generateComponentsObject (documentContext, rootContent, refTypeResolver
|
||||
|
||||
module.exports = {
|
||||
/**
|
||||
* Maps the output from get root files to detect root files
|
||||
* Takes in an spec root file and an array of data files
|
||||
* Bundles the content of the files into one single file according to the
|
||||
* json pointers ($ref)
|
||||
* @param {object} specRoot - root file information
|
||||
* @param {Array} allData - array of { path, content} objects
|
||||
* @param {Array} origin - process origin (BROWSER or node)
|
||||
|
||||
@@ -229,9 +229,6 @@ module.exports = {
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
if (options && options.partial) {
|
||||
return obj;
|
||||
}
|
||||
|
||||
// spec is a valid JSON object at this point
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ function jsonPointerDecodeAndReplace(filePathName) {
|
||||
* @returns {Array} - the calculated keys in an array representing each nesting property name
|
||||
*/
|
||||
function getKeyInComponents(traceFromParent, filePathName, localPath) {
|
||||
const localPart = localPath ? `#${localPath}` : '';
|
||||
const localPart = localPath ? `${localPointer}${localPath}` : '';
|
||||
let res = traceFromParent,
|
||||
trace = [],
|
||||
traceToKey = [],
|
||||
@@ -235,5 +235,7 @@ module.exports = {
|
||||
removeLocalReferenceFromPath,
|
||||
isLocalRef,
|
||||
getEntityName,
|
||||
isRemoteRef
|
||||
isRemoteRef,
|
||||
localPointer,
|
||||
jsonPointerLevelSeparator
|
||||
};
|
||||
|
||||
@@ -4836,6 +4836,9 @@ module.exports = {
|
||||
if (format === parse.YAML_FORMAT) {
|
||||
bundledFile = parse.toYAML(bundledFile);
|
||||
}
|
||||
else if (format === parse.JSON_FORMAT) {
|
||||
bundledFile = parse.toJSON(bundledFile, 2);
|
||||
}
|
||||
return { rootFile: { path: parsedRootFiles[0].fileName }, bundledContent: bundledFile };
|
||||
},
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
// const { traverseToBundle } = require('./bundle.js');
|
||||
|
||||
// This is the default collection name if one can't be inferred from the OpenAPI spec
|
||||
const COLLECTION_NAME = 'Imported from OpenAPI 3.0',
|
||||
|
||||
@@ -39,12 +39,7 @@ describe('bundle files method - 3.0', function () {
|
||||
const res = await Converter.bundle(input);
|
||||
expect(res).to.not.be.empty;
|
||||
expect(res.result).to.be.true;
|
||||
expect(res.output.data.bundledContent.paths['/users/{userId}'].get.responses['200']
|
||||
.content['application/json'].schema.$ref)
|
||||
.to.be.equal('#/components/schemas/~1schemas~1user.yaml');
|
||||
expect(Object.keys(res.output.data.bundledContent.components.schemas['/schemas/user.yaml']))
|
||||
.to.have.members(['type', 'properties']);
|
||||
expect(JSON.stringify(res.output.data.bundledContent, null, 2)).to.be.equal(expected);
|
||||
expect(res.output.data.bundledContent).to.be.equal(expected);
|
||||
});
|
||||
|
||||
it('Should return bundled file in yaml format providing bundleFormat - schema_from_response', async function () {
|
||||
@@ -153,7 +148,7 @@ describe('bundle files method - 3.0', function () {
|
||||
const res = await Converter.bundle(input);
|
||||
expect(res).to.not.be.empty;
|
||||
expect(res.result).to.be.true;
|
||||
expect(JSON.stringify(res.output.data.bundledContent, null, 2)).to.be.equal(expected);
|
||||
expect(res.output.data.bundledContent).to.be.equal(expected);
|
||||
});
|
||||
|
||||
it('Should return bundled file - local_references', async function () {
|
||||
@@ -196,7 +191,7 @@ describe('bundle files method - 3.0', function () {
|
||||
const res = await Converter.bundle(input);
|
||||
expect(res).to.not.be.empty;
|
||||
expect(res.result).to.be.true;
|
||||
expect(JSON.stringify(res.output.data.bundledContent, null, 2)).to.be.equal(expected);
|
||||
expect(res.output.data.bundledContent).to.be.equal(expected);
|
||||
});
|
||||
|
||||
it('Should return bundled file - petstore separated yaml', async function () {
|
||||
@@ -332,12 +327,7 @@ describe('bundle files method - 3.0', function () {
|
||||
const res = await Converter.bundle(input);
|
||||
expect(res).to.not.be.empty;
|
||||
expect(res.result).to.be.true;
|
||||
expect(res.output.data.bundledContent.paths['/users/{userId}'].get.responses['200']
|
||||
.content['application/json'].schema.$ref)
|
||||
.to.be.equal('#/components/schemas/~1schemas~1user.yaml');
|
||||
expect(Object.keys(res.output.data.bundledContent.components.schemas['/schemas/user.yaml']))
|
||||
.to.have.members(['type', 'properties']);
|
||||
expect(JSON.stringify(res.output.data.bundledContent, null, 2)).to.be.equal(expected);
|
||||
expect(res.output.data.bundledContent).to.be.equal(expected);
|
||||
});
|
||||
|
||||
it('Should return bundled file - with_ref_in_items', async function () {
|
||||
@@ -370,7 +360,7 @@ describe('bundle files method - 3.0', function () {
|
||||
const res = await Converter.bundle(input);
|
||||
expect(res).to.not.be.empty;
|
||||
expect(res.result).to.be.true;
|
||||
expect(JSON.stringify(res.output.data.bundledContent, null, 2))
|
||||
expect(res.output.data.bundledContent)
|
||||
.to.be.equal(expected);
|
||||
});
|
||||
|
||||
@@ -419,7 +409,7 @@ describe('bundle files method - 3.0', function () {
|
||||
const res = await Converter.bundle(input);
|
||||
expect(res).to.not.be.empty;
|
||||
expect(res.result).to.be.true;
|
||||
expect(JSON.stringify(res.output.data.bundledContent, null, 2)).to.be.equal(expected);
|
||||
expect(res.output.data.bundledContent).to.be.equal(expected);
|
||||
});
|
||||
|
||||
it('Should return bundled file - multiple_references_from_root_components', async function () {
|
||||
@@ -487,6 +477,6 @@ describe('bundle files method - 3.0', function () {
|
||||
const res = await Converter.bundle(input);
|
||||
expect(res).to.not.be.empty;
|
||||
expect(res.result).to.be.true;
|
||||
expect(JSON.stringify(res.output.data.bundledContent, null, 2)).to.be.equal(expected);
|
||||
expect(res.output.data.bundledContent).to.be.equal(expected);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user