mirror of
https://github.com/postmanlabs/openapi-to-postman.git
synced 2022-11-29 22:05:00 +03:00
Fix conversion process for openapi 3.1, adding schemaUtils31X and schemaUtils30X, adding unit tests
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
// This is the default collection name if one can't be inferred from the OpenAPI spec
|
||||
const COLLECTION_NAME = 'Imported from OpenAPI 3.0',
|
||||
{ getConcreteSchemaUtils } = require('./common/versionUtils.js'),
|
||||
BROWSER = 'browser',
|
||||
Ajv = require('ajv'),
|
||||
async = require('async'),
|
||||
@@ -22,30 +23,27 @@ const COLLECTION_NAME = 'Imported from OpenAPI 3.0',
|
||||
// This provides the base class for
|
||||
// errors with the input OpenAPI spec
|
||||
OpenApiErr = require('./error.js'),
|
||||
DEFAULT_SPEC_VERSION = '3.0',
|
||||
{
|
||||
getSpecVersion
|
||||
} = require('./common/versionUtils.js');
|
||||
schemaUtils = require('./schemaUtils');
|
||||
|
||||
let path = require('path'),
|
||||
schemaUtils,
|
||||
concreteUtils,
|
||||
pathBrowserify = require('path-browserify');
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {string} specVersion - the OAS specification version
|
||||
* @returns {NodeRequire} the schema utils according to version
|
||||
*/
|
||||
function getConcreteSchemaUtils(specVersion) {
|
||||
let schemaUtils = {};
|
||||
if (specVersion === DEFAULT_SPEC_VERSION) {
|
||||
schemaUtils = require('./schemaUtils');
|
||||
}
|
||||
else {
|
||||
schemaUtils = require('./schemaUtils31X');
|
||||
}
|
||||
return schemaUtils;
|
||||
}
|
||||
// /**
|
||||
// *
|
||||
// * @param {string} specVersion - the OAS specification version
|
||||
// * @returns {NodeRequire} the schema utils according to version
|
||||
// */
|
||||
// function getConcreteSchemaUtils(specVersion) {
|
||||
// let concreteUtils = {};
|
||||
// if (specVersion === DEFAULT_SPEC_VERSION) {
|
||||
// concreteUtils = require('./30XUtils/schemaUtils30X');
|
||||
// }
|
||||
// else {
|
||||
// concreteUtils = require('./31XUtils/schemaUtils31X');
|
||||
// }
|
||||
// return concreteUtils;
|
||||
// }
|
||||
|
||||
class SchemaPack {
|
||||
constructor (input, options = {}) {
|
||||
@@ -66,10 +64,9 @@ class SchemaPack {
|
||||
);
|
||||
// hardcoding this option - not exposed to users yet
|
||||
this.computedOptions.schemaFaker = true;
|
||||
let indentCharacter = this.computedOptions.indentCharacter,
|
||||
specVersion = getSpecVersion(input);
|
||||
let indentCharacter = this.computedOptions.indentCharacter;
|
||||
this.computedOptions.indentCharacter = indentCharacter === 'tab' ? '\t' : ' ';
|
||||
schemaUtils = getConcreteSchemaUtils(specVersion);
|
||||
concreteUtils = getConcreteSchemaUtils(input);
|
||||
this.validate();
|
||||
}
|
||||
|
||||
@@ -125,7 +122,7 @@ class SchemaPack {
|
||||
return this.validationResult;
|
||||
}
|
||||
|
||||
specParseResult = schemaUtils.parseSpec(json);
|
||||
specParseResult = concreteUtils.parseSpec(json);
|
||||
|
||||
if (!specParseResult.result) {
|
||||
// validation failed
|
||||
@@ -258,7 +255,7 @@ class SchemaPack {
|
||||
analysis,
|
||||
generatedStore = {},
|
||||
collectionJSON,
|
||||
componentsAndPaths,
|
||||
specComponentsAndUtils,
|
||||
authHelper,
|
||||
schemaCache = {
|
||||
schemaResolutionCache: this.schemaResolutionCache,
|
||||
@@ -270,10 +267,12 @@ class SchemaPack {
|
||||
}
|
||||
|
||||
// this cannot be attempted before validation
|
||||
componentsAndPaths = {
|
||||
components: this.openapi.components,
|
||||
paths: this.openapi.paths
|
||||
};
|
||||
specComponentsAndUtils = { concreteUtils };
|
||||
Object.assign(specComponentsAndUtils, concreteUtils.getRequiredData(this.openapi));
|
||||
// {
|
||||
// components: this.openapi.components,
|
||||
// paths: this.openapi.paths
|
||||
// };
|
||||
|
||||
// create and sanitize basic spec
|
||||
openapi = this.openapi;
|
||||
@@ -330,10 +329,24 @@ class SchemaPack {
|
||||
// For paths, All operations are grouped based on corresponding paths
|
||||
try {
|
||||
if (options.folderStrategy === 'tags') {
|
||||
schemaUtils.addCollectionItemsUsingTags(openapi, generatedStore, componentsAndPaths, options, schemaCache);
|
||||
schemaUtils.addCollectionItemsUsingTags(
|
||||
openapi,
|
||||
generatedStore,
|
||||
specComponentsAndUtils,
|
||||
options,
|
||||
schemaCache,
|
||||
concreteUtils
|
||||
);
|
||||
}
|
||||
else {
|
||||
schemaUtils.addCollectionItemsUsingPaths(openapi, generatedStore, componentsAndPaths, options, schemaCache);
|
||||
schemaUtils.addCollectionItemsUsingPaths(
|
||||
openapi,
|
||||
generatedStore,
|
||||
specComponentsAndUtils,
|
||||
options,
|
||||
schemaCache,
|
||||
concreteUtils
|
||||
);
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
|
||||
Reference in New Issue
Block a user