mirror of
https://github.com/postmanlabs/openapi-to-postman.git
synced 2022-11-29 22:05:00 +03:00
constants extraction
constants extraction
This commit is contained in:
committed by
Erik Mendoza
parent
1a208ab0ed
commit
789f2e3522
@@ -1,9 +1,12 @@
|
|||||||
const slashes = /\//g,
|
const slashes = /\//g,
|
||||||
tildes = /~/g,
|
tildes = /~/g,
|
||||||
escapedSlash = /~1/g,
|
escapedSlash = /~1/g,
|
||||||
|
escapedSlashString = '~1',
|
||||||
componentsKey = 'components',
|
componentsKey = 'components',
|
||||||
localPointer = '#',
|
localPointer = '#',
|
||||||
escapedTilde = /~0/g;
|
escapedTilde = /~0/g,
|
||||||
|
jsonPointerLevelSeparator = '/',
|
||||||
|
escapedTildeString = '~0';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encodes a filepath name so it can be a json pointer
|
* Encodes a filepath name so it can be a json pointer
|
||||||
@@ -12,7 +15,7 @@ const slashes = /\//g,
|
|||||||
* @returns {string} - the encoded filepath
|
* @returns {string} - the encoded filepath
|
||||||
*/
|
*/
|
||||||
function jsonPointerEncodeAndReplace(filePathName) {
|
function jsonPointerEncodeAndReplace(filePathName) {
|
||||||
return encodeURIComponent(filePathName.replace(tildes, '~0').replace(slashes, '~1'));
|
return encodeURIComponent(filePathName.replace(tildes, escapedTildeString).replace(slashes, escapedSlashString));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -22,7 +25,7 @@ function jsonPointerEncodeAndReplace(filePathName) {
|
|||||||
* @returns {string} - the encoded filepath
|
* @returns {string} - the encoded filepath
|
||||||
*/
|
*/
|
||||||
function jsonPointerDecodeAndReplace(filePathName) {
|
function jsonPointerDecodeAndReplace(filePathName) {
|
||||||
return decodeURIComponent(filePathName.replace(escapedSlash, '/').replace(escapedTilde, '~'));
|
return decodeURIComponent(filePathName.replace(escapedSlash, jsonPointerLevelSeparator).replace(escapedTilde, '~'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -39,10 +42,10 @@ function getKeyInComponents(componentName, filePathName, localPath) {
|
|||||||
res.push(componentName);
|
res.push(componentName);
|
||||||
res.push(jsonPointerDecodeAndReplace(filePathName));
|
res.push(jsonPointerDecodeAndReplace(filePathName));
|
||||||
if (localPath) {
|
if (localPath) {
|
||||||
if (localPath.startsWith('/')) {
|
if (localPath.startsWith(jsonPointerLevelSeparator)) {
|
||||||
localPathToCheck = localPath.substring(1);
|
localPathToCheck = localPath.substring(1);
|
||||||
}
|
}
|
||||||
pointer = localPathToCheck.split('/');
|
pointer = localPathToCheck.split(jsonPointerLevelSeparator);
|
||||||
for (let i = 0; i < pointer.length; i++) {
|
for (let i = 0; i < pointer.length; i++) {
|
||||||
pointer[i] = jsonPointerDecodeAndReplace(pointer[i]);
|
pointer[i] = jsonPointerDecodeAndReplace(pointer[i]);
|
||||||
}
|
}
|
||||||
@@ -75,11 +78,12 @@ function getLocalPath(jsonPointer) {
|
|||||||
function concatJsonPointer(encodeFunction, filePathName, componentName, localPath) {
|
function concatJsonPointer(encodeFunction, filePathName, componentName, localPath) {
|
||||||
let base = '',
|
let base = '',
|
||||||
local = '';
|
local = '';
|
||||||
base = '/' + encodeFunction(filePathName);
|
base = jsonPointerLevelSeparator + encodeFunction(filePathName);
|
||||||
if (localPath) {
|
if (localPath) {
|
||||||
local = localPath;
|
local = localPath;
|
||||||
}
|
}
|
||||||
return localPointer + '/' + componentsKey + '/' + componentName + base + local;
|
return localPointer + jsonPointerLevelSeparator + componentsKey +
|
||||||
|
jsonPointerLevelSeparator + componentName + base + local;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -176,7 +180,7 @@ function getEntityName(jsonPointer) {
|
|||||||
if (!jsonPointer) {
|
if (!jsonPointer) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
let segment = jsonPointer.substring(jsonPointer.lastIndexOf('/') + 1);
|
let segment = jsonPointer.substring(jsonPointer.lastIndexOf(jsonPointerLevelSeparator) + 1);
|
||||||
return segment;
|
return segment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,11 @@ function added(path, referencesInNode) {
|
|||||||
return referencesInNode.find((reference) => { return reference.path === path; }) !== undefined;
|
return referencesInNode.find((reference) => { return reference.path === path; }) !== undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the path from a referenced entity
|
||||||
|
* @param {object} property - current node in process
|
||||||
|
* @returns {string} - $ref value
|
||||||
|
*/
|
||||||
function pathSolver(property) {
|
function pathSolver(property) {
|
||||||
return property.$ref;
|
return property.$ref;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user