openapi-merge-cli
Advanced tools
Comparing version 1.1.25 to 1.1.28
@@ -26,2 +26,3 @@ "use strict"; | ||
const js_yaml_1 = __importDefault(require("js-yaml")); | ||
const file_loading_1 = require("./file-loading"); | ||
const ERROR_LOADING_CONFIG = 1; | ||
@@ -47,43 +48,2 @@ const ERROR_LOADING_INPUTS = 2; | ||
} | ||
function readFilePromise(filePath) { | ||
return new Promise((resolve, reject) => { | ||
fs_1.default.readFile(filePath, (err, result) => { | ||
if (err) { | ||
reject(err); | ||
} | ||
else { | ||
resolve(result); | ||
} | ||
}); | ||
}); | ||
} | ||
function readFileAsString(filePath) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return (yield readFilePromise(filePath)).toString('utf-8'); | ||
}); | ||
} | ||
class JsonOrYamlParseError extends Error { | ||
constructor(jsonError, yamlError) { | ||
super(`Failed to parse the input as either JSON or YAML.\n\nJSON Error: ${jsonError.message}\n\nYAML Error: ${yamlError.message}`); | ||
} | ||
} | ||
function readYamlOrJSON(fileContents) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let jsonError; | ||
try { | ||
return JSON.parse(fileContents); | ||
} | ||
catch (e) { | ||
jsonError = e; | ||
} | ||
let yamlError; | ||
try { | ||
return js_yaml_1.default.safeLoad(fileContents); | ||
} | ||
catch (e) { | ||
yamlError = e; | ||
} | ||
throw new JsonOrYamlParseError(jsonError, yamlError); | ||
}); | ||
} | ||
function loadOasForInput(basePath, input, inputIndex, logger) { | ||
@@ -94,3 +54,3 @@ return __awaiter(this, void 0, void 0, function* () { | ||
logger.log(`## Loading input ${inputIndex}: ${fullPath}`); | ||
return (yield readYamlOrJSON(yield readFileAsString(fullPath))); | ||
return (yield file_loading_1.readYamlOrJSON(yield file_loading_1.readFileAsString(fullPath))); | ||
} | ||
@@ -100,3 +60,3 @@ else { | ||
const inputContents = yield isomorphic_fetch_1.default(input.inputURL).then(rsp => rsp.text()); | ||
return (yield readYamlOrJSON(inputContents)); | ||
return (yield file_loading_1.readYamlOrJSON(inputContents)); | ||
} | ||
@@ -153,3 +113,3 @@ }); | ||
logger.log(`## ${process.argv[0]}: Running v${pjson.version}`); | ||
const config = load_configuration_1.loadConfiguration(program.config); | ||
const config = yield load_configuration_1.loadConfiguration(program.config); | ||
if (typeof config === 'string') { | ||
@@ -156,0 +116,0 @@ console.error(config); |
import { Configuration } from "./data"; | ||
export declare function loadConfiguration(configLocation?: string): Configuration | string; | ||
export declare function loadConfiguration(configLocation?: string): Promise<Configuration | string>; | ||
//# sourceMappingURL=load-configuration.d.ts.map |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -8,31 +17,34 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
const configuration_schema_json_1 = __importDefault(require("./configuration.schema.json")); | ||
const fs_1 = __importDefault(require("fs")); | ||
const file_loading_1 = require("./file-loading"); | ||
function validateConfiguration(rawData) { | ||
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */ | ||
let data; | ||
try { | ||
data = JSON.parse(rawData); | ||
} | ||
catch (e) { | ||
return `Could not parse configuration: ${e}`; | ||
} | ||
const ajv = new ajv_1.default(); | ||
const validate = ajv.compile(configuration_schema_json_1.default); | ||
const valid = validate(data); | ||
if (!valid) { | ||
return ajv.errorsText(validate.errors); | ||
} | ||
return data; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */ | ||
try { | ||
const data = yield file_loading_1.readYamlOrJSON(rawData); | ||
const ajv = new ajv_1.default(); | ||
const validate = ajv.compile(configuration_schema_json_1.default); | ||
const valid = validate(data); | ||
if (!valid) { | ||
return ajv.errorsText(validate.errors); | ||
} | ||
return data; | ||
} | ||
catch (e) { | ||
return `Could not parse configuration: ${e}`; | ||
} | ||
}); | ||
} | ||
const STANDARD_CONFIG_FILE = 'openapi-merge.json'; | ||
function loadConfiguration(configLocation) { | ||
const configFile = configLocation === undefined ? STANDARD_CONFIG_FILE : configLocation; | ||
try { | ||
const rawData = fs_1.default.readFileSync(configFile); | ||
return validateConfiguration(rawData.toString('utf8')); | ||
} | ||
catch (e) { | ||
return `Could not find or read '${configFile}' in the current directory.`; | ||
} | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const configFile = configLocation === undefined ? STANDARD_CONFIG_FILE : configLocation; | ||
try { | ||
const rawData = yield file_loading_1.readFileAsString(configFile); | ||
return yield validateConfiguration(rawData); | ||
} | ||
catch (e) { | ||
return `Could not find or read '${configFile}' in the current directory.`; | ||
} | ||
}); | ||
} | ||
exports.loadConfiguration = loadConfiguration; |
{ | ||
"name": "openapi-merge-cli", | ||
"version": "1.1.25", | ||
"version": "1.1.28", | ||
"description": "A cli tool for the openapi-merge library.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -63,4 +63,10 @@ # openapi-merge-cli | ||
If you wish, you may write your configuration file in YAML format and then run: | ||
``` shell | ||
npx openapi-merge-cli --config path/to/openapi-merge.yaml | ||
``` | ||
And the merge should be run and complete! Congratulations and enjoy! | ||
If you experience any issues then please raise them in the bug tracker. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
31154
21
543
71