openapi-merge-cli
Advanced tools
Comparing version 1.1.11 to 1.1.16
@@ -5,2 +5,4 @@ #!/usr/bin/env node | ||
const _1 = require("."); | ||
_1.main(); | ||
_1.main().catch(e => { | ||
console.error('An uncaught exception was thrown', e); | ||
}); |
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"additionalProperties": false, | ||
"properties": { | ||
"inputs": { | ||
"description": "The input items for the merge algorithm. You must provide at least one.", | ||
"items": { | ||
"additionalProperties": false, | ||
"properties": { | ||
"disputePrefix": { | ||
"description": "The prefix that will be used in the event of a conflict of two definition names.", | ||
"minLength": 1, | ||
"title": "disputePrefix", | ||
"type": "string" | ||
"definitions": { | ||
"ConfigurationInputFromFile": { | ||
"additionalProperties": false, | ||
"description": "A single Configuration input from a File.", | ||
"properties": { | ||
"disputePrefix": { | ||
"description": "The prefix that will be used in the event of a conflict of two definition names.", | ||
"minLength": 1, | ||
"title": "disputePrefix", | ||
"type": "string" | ||
}, | ||
"inputFile": { | ||
"description": "The path to the input OpenAPI Schema that will be merged.", | ||
"minLength": 1, | ||
"title": "inputFile", | ||
"type": "string" | ||
}, | ||
"operationSelection": { | ||
"additionalProperties": false, | ||
"description": "Choose which OpenAPI Operations should be included from this input.", | ||
"properties": { | ||
"excludeTags": { | ||
"description": "Any Operation that has any one of these tags will be excluded from the final result. If a single Operation contains\nan includeTag and an excludeTag then it will be excluded; exclusion takes precedence.", | ||
"items": { | ||
"type": "string" | ||
}, | ||
"title": "excludeTags", | ||
"type": "array" | ||
}, | ||
"includeTags": { | ||
"description": "Only Operatinos that have these tags will be taken from this OpenAPI file. If a single Operation contains\nan includeTag and an excludeTag then it will be excluded; exclusion takes precedence.", | ||
"items": { | ||
"type": "string" | ||
}, | ||
"title": "includeTags", | ||
"type": "array" | ||
} | ||
}, | ||
"inputFile": { | ||
"description": "The path to the input OpenAPI Schema that will be merged.", | ||
"minLength": 1, | ||
"title": "inputFile", | ||
"type": "string" | ||
"title": "operationSelection", | ||
"type": "object" | ||
}, | ||
"pathModification": { | ||
"additionalProperties": false, | ||
"description": "For this input, you can perform these modifications to its paths elements.", | ||
"properties": { | ||
"prepend": { | ||
"description": "Append these characters to the start of the paths for this input. Will run after stripStart.", | ||
"minLength": 1, | ||
"title": "prepend", | ||
"type": "string" | ||
}, | ||
"stripStart": { | ||
"description": "If a path starts with these characters, then stip them from the beginning of the path. Will run before prepend.", | ||
"minLength": 1, | ||
"title": "stripStart", | ||
"type": "string" | ||
} | ||
}, | ||
"operationSelection": { | ||
"additionalProperties": false, | ||
"description": "Choose which OpenAPI Operations should be included from this input.", | ||
"properties": { | ||
"excludeTags": { | ||
"description": "Any Operation that has any one of these tags will be excluded from the final result. If a single Operation contains\nan includeTag and an excludeTag then it will be excluded; exclusion takes precedence.", | ||
"items": { | ||
"type": "string" | ||
}, | ||
"title": "excludeTags", | ||
"type": "array" | ||
"title": "pathModification", | ||
"type": "object" | ||
} | ||
}, | ||
"required": [ | ||
"inputFile" | ||
], | ||
"title": "ConfigurationInputFromFile", | ||
"type": "object" | ||
}, | ||
"ConfigurationInputFromUrl": { | ||
"additionalProperties": false, | ||
"description": "A single Configuration input from a URL", | ||
"properties": { | ||
"disputePrefix": { | ||
"description": "The prefix that will be used in the event of a conflict of two definition names.", | ||
"minLength": 1, | ||
"title": "disputePrefix", | ||
"type": "string" | ||
}, | ||
"inputURL": { | ||
"description": "The input url that we should load our configuration file from.", | ||
"format": "uri", | ||
"pattern": "^https?://", | ||
"title": "inputURL", | ||
"type": "string" | ||
}, | ||
"operationSelection": { | ||
"additionalProperties": false, | ||
"description": "Choose which OpenAPI Operations should be included from this input.", | ||
"properties": { | ||
"excludeTags": { | ||
"description": "Any Operation that has any one of these tags will be excluded from the final result. If a single Operation contains\nan includeTag and an excludeTag then it will be excluded; exclusion takes precedence.", | ||
"items": { | ||
"type": "string" | ||
}, | ||
"includeTags": { | ||
"description": "Only Operatinos that have these tags will be taken from this OpenAPI file. If a single Operation contains\nan includeTag and an excludeTag then it will be excluded; exclusion takes precedence.", | ||
"items": { | ||
"type": "string" | ||
}, | ||
"title": "includeTags", | ||
"type": "array" | ||
} | ||
"title": "excludeTags", | ||
"type": "array" | ||
}, | ||
"title": "operationSelection", | ||
"type": "object" | ||
}, | ||
"pathModification": { | ||
"additionalProperties": false, | ||
"description": "For this input, you can perform these modifications to its paths elements.", | ||
"properties": { | ||
"prepend": { | ||
"description": "Append these characters to the start of the paths for this input. Will run after stripStart.", | ||
"minLength": 1, | ||
"title": "prepend", | ||
"includeTags": { | ||
"description": "Only Operatinos that have these tags will be taken from this OpenAPI file. If a single Operation contains\nan includeTag and an excludeTag then it will be excluded; exclusion takes precedence.", | ||
"items": { | ||
"type": "string" | ||
}, | ||
"stripStart": { | ||
"description": "If a path starts with these characters, then stip them from the beginning of the path. Will run before prepend.", | ||
"minLength": 1, | ||
"title": "stripStart", | ||
"type": "string" | ||
} | ||
"title": "includeTags", | ||
"type": "array" | ||
} | ||
}, | ||
"title": "operationSelection", | ||
"type": "object" | ||
}, | ||
"pathModification": { | ||
"additionalProperties": false, | ||
"description": "For this input, you can perform these modifications to its paths elements.", | ||
"properties": { | ||
"prepend": { | ||
"description": "Append these characters to the start of the paths for this input. Will run after stripStart.", | ||
"minLength": 1, | ||
"title": "prepend", | ||
"type": "string" | ||
}, | ||
"title": "pathModification", | ||
"type": "object" | ||
"stripStart": { | ||
"description": "If a path starts with these characters, then stip them from the beginning of the path. Will run before prepend.", | ||
"minLength": 1, | ||
"title": "stripStart", | ||
"type": "string" | ||
} | ||
}, | ||
"title": "pathModification", | ||
"type": "object" | ||
} | ||
}, | ||
"required": [ | ||
"inputURL" | ||
], | ||
"title": "ConfigurationInputFromUrl", | ||
"type": "object" | ||
} | ||
}, | ||
"properties": { | ||
"inputs": { | ||
"description": "The input items for the merge algorithm. You must provide at least one.", | ||
"items": { | ||
"anyOf": [ | ||
{ | ||
"$ref": "#/definitions/ConfigurationInputFromFile" | ||
}, | ||
{ | ||
"$ref": "#/definitions/ConfigurationInputFromUrl" | ||
} | ||
}, | ||
"required": [ | ||
"inputFile" | ||
], | ||
"type": "object" | ||
] | ||
}, | ||
@@ -87,3 +169,5 @@ "minItems": 1, | ||
], | ||
"type": "object" | ||
"type": "object", | ||
"title": "Configuration", | ||
"description": "The Configuration file for the OpenAPI Merge CLI Tool." | ||
} |
@@ -14,12 +14,6 @@ export declare type OperationSelection = { | ||
/** | ||
* A single Configuration input | ||
* The common configuration properties of an Input. | ||
*/ | ||
export declare type ConfigurationInput = { | ||
export interface ConfigurationInputBase { | ||
/** | ||
* The path to the input OpenAPI Schema that will be merged. | ||
* | ||
* @minLength 1 | ||
*/ | ||
inputFile: string; | ||
/** | ||
* The prefix that will be used in the event of a conflict of two definition names. | ||
@@ -51,4 +45,32 @@ * | ||
operationSelection?: OperationSelection; | ||
}; | ||
} | ||
/** | ||
* A single Configuration input from a File. | ||
*/ | ||
export interface ConfigurationInputFromFile extends ConfigurationInputBase { | ||
/** | ||
* The path to the input OpenAPI Schema that will be merged. | ||
* | ||
* @minLength 1 | ||
*/ | ||
inputFile: string; | ||
} | ||
/** | ||
* A single Configuration input from a URL | ||
*/ | ||
export interface ConfigurationInputFromUrl extends ConfigurationInputBase { | ||
/** | ||
* The input url that we should load our configuration file from. | ||
* | ||
* @format uri | ||
* @pattern ^https?:// | ||
*/ | ||
inputURL: string; | ||
} | ||
/** | ||
* The multiple types of configuration inputs that are supported. | ||
*/ | ||
export declare type ConfigurationInput = ConfigurationInputFromFile | ConfigurationInputFromUrl; | ||
export declare function isConfigurationInputFromFile(input: ConfigurationInput): input is ConfigurationInputFromFile; | ||
/** | ||
* The Configuration file for the OpenAPI Merge CLI Tool. | ||
@@ -55,0 +77,0 @@ */ |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function isConfigurationInputFromFile(input) { | ||
return 'inputFile' in input; | ||
} | ||
exports.isConfigurationInputFromFile = isConfigurationInputFromFile; |
@@ -1,2 +0,2 @@ | ||
export declare function main(): void; | ||
export declare function main(): Promise<void>; | ||
//# sourceMappingURL=index.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) { | ||
@@ -6,2 +15,3 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const data_1 = require("./data"); | ||
const load_configuration_1 = require("./load-configuration"); | ||
@@ -14,3 +24,4 @@ const commander_1 = require("commander"); | ||
const path_1 = __importDefault(require("path")); | ||
const data_1 = require("openapi-merge/dist/data"); | ||
const data_2 = require("openapi-merge/dist/data"); | ||
const isomorphic_fetch_1 = __importDefault(require("isomorphic-fetch")); | ||
const ERROR_LOADING_CONFIG = 1; | ||
@@ -36,53 +47,76 @@ const ERROR_LOADING_INPUTS = 2; | ||
} | ||
function convertInputs(basePath, configInputs, logger) { | ||
const results = []; | ||
for (let inputIndex = 0; inputIndex < configInputs.length; inputIndex++) { | ||
const input = configInputs[inputIndex]; | ||
try { | ||
function loadOasForInput(basePath, input, inputIndex, logger) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (data_1.isConfigurationInputFromFile(input)) { | ||
const fullPath = path_1.default.join(basePath, input.inputFile); | ||
logger.log(`## Loading input ${inputIndex}: ${fullPath}`); | ||
const rawData = JSON.parse(fs_1.default.readFileSync(fullPath).toString('utf-8')); | ||
results.push({ | ||
oas: rawData, | ||
disputePrefix: input.disputePrefix, | ||
pathModification: input.pathModification, | ||
operationSelection: input.operationSelection | ||
}); | ||
return JSON.parse(fs_1.default.readFileSync(fullPath).toString('utf-8')); | ||
} | ||
catch (e) { | ||
return `Input ${inputIndex}: could not load configuration file. ${e}`; | ||
else { | ||
logger.log(`## Loading input ${inputIndex} from URL: ${input.inputURL}`); | ||
return yield isomorphic_fetch_1.default(input.inputURL).then(rsp => rsp.json()); | ||
} | ||
} | ||
return results; | ||
}); | ||
} | ||
function isString(s) { | ||
return typeof s === 'string'; | ||
} | ||
function isSingleMergeInput(i) { | ||
return typeof i !== 'string'; | ||
} | ||
function convertInputs(basePath, configInputs, logger) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const results = yield Promise.all(configInputs.map((input, inputIndex) => __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
const oas = yield loadOasForInput(basePath, input, inputIndex, logger); | ||
return { | ||
oas, | ||
disputePrefix: input.disputePrefix, | ||
pathModification: input.pathModification, | ||
operationSelection: input.operationSelection | ||
}; | ||
} | ||
catch (e) { | ||
return `Input ${inputIndex}: could not load configuration file. ${e}`; | ||
} | ||
}))); | ||
const errors = results.filter(isString); | ||
if (errors.length > 0) { | ||
return { errors }; | ||
} | ||
return results.filter(isSingleMergeInput); | ||
}); | ||
} | ||
function main() { | ||
const logger = new LogWithMillisDiff(); | ||
program.parse(process.argv); | ||
logger.log(`## ${process.argv[0]}: Running v${pjson.version}`); | ||
const config = load_configuration_1.loadConfiguration(program.config); | ||
if (typeof config === 'string') { | ||
console.error(config); | ||
process.exit(ERROR_LOADING_CONFIG); | ||
return; | ||
} | ||
logger.log(`## Loaded the configuration: ${config.inputs.length} inputs`); | ||
const basePath = path_1.default.dirname(program.config || './'); | ||
const inputs = convertInputs(basePath, config.inputs, logger); | ||
if (typeof inputs === 'string') { | ||
console.error(inputs); | ||
process.exit(ERROR_LOADING_INPUTS); | ||
return; | ||
} | ||
logger.log(`## Loaded the inputs into memory, merging the results.`); | ||
const mergeResult = openapi_merge_1.merge(inputs); | ||
if (data_1.isErrorResult(mergeResult)) { | ||
console.error(`Error merging files: ${mergeResult.message} (${mergeResult.type})`); | ||
process.exit(ERROR_MERGING); | ||
return; | ||
} | ||
const outputFullPath = path_1.default.join(basePath, config.output); | ||
logger.log(`## Inputs merged, writing the results out to '${outputFullPath}'`); | ||
fs_1.default.writeFileSync(outputFullPath, JSON.stringify(mergeResult.output, null, 2)); | ||
logger.log(`## Finished writing to '${outputFullPath}'`); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const logger = new LogWithMillisDiff(); | ||
program.parse(process.argv); | ||
logger.log(`## ${process.argv[0]}: Running v${pjson.version}`); | ||
const config = load_configuration_1.loadConfiguration(program.config); | ||
if (typeof config === 'string') { | ||
console.error(config); | ||
process.exit(ERROR_LOADING_CONFIG); | ||
return; | ||
} | ||
logger.log(`## Loaded the configuration: ${config.inputs.length} inputs`); | ||
const basePath = path_1.default.dirname(program.config || './'); | ||
const inputs = yield convertInputs(basePath, config.inputs, logger); | ||
if ('errors' in inputs) { | ||
console.error(inputs); | ||
process.exit(ERROR_LOADING_INPUTS); | ||
return; | ||
} | ||
logger.log(`## Loaded the inputs into memory, merging the results.`); | ||
const mergeResult = openapi_merge_1.merge(inputs); | ||
if (data_2.isErrorResult(mergeResult)) { | ||
console.error(`Error merging files: ${mergeResult.message} (${mergeResult.type})`); | ||
process.exit(ERROR_MERGING); | ||
return; | ||
} | ||
const outputFullPath = path_1.default.join(basePath, config.output); | ||
logger.log(`## Inputs merged, writing the results out to '${outputFullPath}'`); | ||
fs_1.default.writeFileSync(outputFullPath, JSON.stringify(mergeResult.output, null, 2)); | ||
logger.log(`## Finished writing to '${outputFullPath}'`); | ||
}); | ||
} | ||
exports.main = main; |
{ | ||
"name": "openapi-merge-cli", | ||
"version": "1.1.11", | ||
"version": "1.1.16", | ||
"description": "A cli tool for the openapi-merge library.", | ||
@@ -30,2 +30,4 @@ "keywords": [ | ||
"devDependencies": { | ||
"@adobe/jsonschema2md": "^4.1.3", | ||
"@types/isomorphic-fetch": "^0.0.35", | ||
"@types/node": "^13.13.5", | ||
@@ -43,2 +45,4 @@ "@typescript-eslint/eslint-plugin": "2.31.0", | ||
"commander": "^5.1.0", | ||
"es6-promise": "^4.2.8", | ||
"isomorphic-fetch": "^2.2.1", | ||
"openapi-merge": "^1.0.22" | ||
@@ -50,5 +54,6 @@ }, | ||
"prepublishOnly": "npm run gen-schema && tsc --project .", | ||
"gen-schema": "typescript-json-schema src/data.ts Configuration --titles --refs --noExtraProps --required --strictNullChecks -o src/configuration.schema.json", | ||
"gen-schema": "typescript-json-schema src/data.ts Configuration --titles --refs --noExtraProps --required --strictNullChecks -o src/configuration.schema.json && ts-node --project tsconfig.json ./src/fix-schema.ts", | ||
"start": "ts-node --project ./tsconfig.json ./src/cli.ts", | ||
"lint": "yarn eslint src --ext .js,.jsx,.ts,.tsx --fix --format=visualstudio" | ||
"lint": "yarn eslint src --ext .js,.jsx,.ts,.tsx --fix --format=visualstudio", | ||
"gen-docs": "jsonschema2md --input=src" | ||
}, | ||
@@ -55,0 +60,0 @@ "husky": { |
@@ -48,3 +48,3 @@ # openapi-merge-cli | ||
* `inputFile`: the relative path, 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. | ||
* `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. | ||
@@ -62,4 +62,6 @@ * `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. | ||
For more fine grained details on what `Configuration` options are available to you. [Please read the docs](https://bitbucket.org/echo_rm/openapi-merge-cli/wiki/README). | ||
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
25873
18
448
65
5
10
3
+ Addedes6-promise@^4.2.8
+ Addedisomorphic-fetch@^2.2.1
+ Addedencoding@0.1.13(transitive)
+ Addedes6-promise@4.2.8(transitive)
+ Addediconv-lite@0.6.3(transitive)
+ Addedis-stream@1.1.0(transitive)
+ Addedisomorphic-fetch@2.2.1(transitive)
+ Addednode-fetch@1.7.3(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedwhatwg-fetch@3.6.20(transitive)