openapi-merge-cli
Advanced tools
Comparing version 1.1.18 to 1.1.20
@@ -25,2 +25,3 @@ "use strict"; | ||
const isomorphic_fetch_1 = __importDefault(require("isomorphic-fetch")); | ||
const js_yaml_1 = __importDefault(require("js-yaml")); | ||
const ERROR_LOADING_CONFIG = 1; | ||
@@ -46,2 +47,39 @@ 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); | ||
} | ||
}); | ||
}); | ||
} | ||
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(filePath) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const fileContents = (yield readFilePromise(filePath)).toString('utf-8'); | ||
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) { | ||
@@ -52,3 +90,3 @@ return __awaiter(this, void 0, void 0, function* () { | ||
logger.log(`## Loading input ${inputIndex}: ${fullPath}`); | ||
return JSON.parse(fs_1.default.readFileSync(fullPath).toString('utf-8')); | ||
return (yield readYamlOrJSON(fullPath)); | ||
} | ||
@@ -55,0 +93,0 @@ else { |
{ | ||
"name": "openapi-merge-cli", | ||
"version": "1.1.18", | ||
"version": "1.1.20", | ||
"description": "A cli tool for the openapi-merge library.", | ||
@@ -32,2 +32,3 @@ "keywords": [ | ||
"@types/isomorphic-fetch": "^0.0.35", | ||
"@types/js-yaml": "^3.12.5", | ||
"@types/node": "^13.13.5", | ||
@@ -47,2 +48,3 @@ "@typescript-eslint/eslint-plugin": "2.31.0", | ||
"isomorphic-fetch": "^2.2.1", | ||
"js-yaml": "^3.14.0", | ||
"openapi-merge": "^1.0.22" | ||
@@ -49,0 +51,0 @@ }, |
@@ -32,3 +32,3 @@ # openapi-merge-cli | ||
{ | ||
"inputFile": "./confluence.swagger.json", | ||
"inputFile": "./confluence.swagger.yaml", | ||
"disputePrefix": "Confluence", | ||
@@ -49,3 +49,3 @@ "pathModification": { | ||
* `inputFile` or `inputURL`: the relative path (or URL), from the `openapi-merge.json`, to the OpenAPI schema file for that input. | ||
* `inputFile` or `inputURL`: the relative path (or URL), from the `openapi-merge.json`, to the OpenAPI schema file for that input (in JSON or Yaml format). | ||
* `disputePrefix`: if two inputs both define a component with the same name then, in order to prevent incorrect overlaps, we will attempt to use the dispute prefix to come up with a unique name for that component. | ||
@@ -52,0 +52,0 @@ * `pathModification.stripStart`: When copying over the `paths` from your OpenAPI specification for this input, it will strip this string from the start of the path if it is found. |
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
27068
486
6
11
+ Addedjs-yaml@^3.14.0
+ Addedargparse@1.0.10(transitive)
+ Addedesprima@4.0.1(transitive)
+ Addedjs-yaml@3.14.1(transitive)
+ Addedsprintf-js@1.0.3(transitive)