@microsoft/m365-spec-parser 0.2.5-alpha.66ee22767.0 → 0.2.5-alpha.9303bbfbd.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.node.cjs.js
CHANGED
|
@@ -9,7 +9,6 @@ var fs = require('fs-extra');
|
|
|
9
9
|
var path = require('path');
|
|
10
10
|
var teamsManifest = require('@microsoft/teams-manifest');
|
|
11
11
|
var crypto = require('crypto');
|
|
12
|
-
var jsonSchemaRefParser = require('@apidevtools/json-schema-ref-parser');
|
|
13
12
|
|
|
14
13
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
15
14
|
|
|
@@ -2153,7 +2152,6 @@ class SpecParser {
|
|
|
2153
2152
|
};
|
|
2154
2153
|
this.pathOrSpec = pathOrDoc;
|
|
2155
2154
|
this.parser = new SwaggerParser__default['default']();
|
|
2156
|
-
this.refParser = new jsonSchemaRefParser.$RefParser();
|
|
2157
2155
|
this.options = Object.assign(Object.assign({}, this.defaultOptions), (options !== null && options !== void 0 ? options : {}));
|
|
2158
2156
|
}
|
|
2159
2157
|
/**
|
|
@@ -2167,11 +2165,11 @@ class SpecParser {
|
|
|
2167
2165
|
let hash = "";
|
|
2168
2166
|
try {
|
|
2169
2167
|
yield this.loadSpec();
|
|
2170
|
-
if (!this.
|
|
2168
|
+
if (!this.parser.$refs.circular) {
|
|
2171
2169
|
yield this.parser.validate(this.spec);
|
|
2172
2170
|
}
|
|
2173
2171
|
else {
|
|
2174
|
-
// The following code hangs for Graph API, support will be added when SwaggerParser is updated.
|
|
2172
|
+
// The following code still hangs for Graph API, support will be added when SwaggerParser is updated.
|
|
2175
2173
|
/*
|
|
2176
2174
|
const clonedUnResolveSpec = JSON.parse(JSON.stringify(this.unResolveSpec));
|
|
2177
2175
|
await this.parser.validate(clonedUnResolveSpec);
|
|
@@ -2203,7 +2201,7 @@ class SpecParser {
|
|
|
2203
2201
|
};
|
|
2204
2202
|
}
|
|
2205
2203
|
// Remote reference not supported
|
|
2206
|
-
const refPaths = this.
|
|
2204
|
+
const refPaths = this.parser.$refs.paths();
|
|
2207
2205
|
// refPaths [0] is the current spec file path
|
|
2208
2206
|
if (refPaths.length > 1) {
|
|
2209
2207
|
errors.push({
|
|
@@ -2351,7 +2349,7 @@ class SpecParser {
|
|
|
2351
2349
|
}
|
|
2352
2350
|
deReferenceSpec(spec) {
|
|
2353
2351
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2354
|
-
const result = yield this.
|
|
2352
|
+
const result = yield this.parser.dereference(spec);
|
|
2355
2353
|
return result;
|
|
2356
2354
|
});
|
|
2357
2355
|
}
|
|
@@ -2488,6 +2486,54 @@ class SpecParser {
|
|
|
2488
2486
|
return result;
|
|
2489
2487
|
});
|
|
2490
2488
|
}
|
|
2489
|
+
/**
|
|
2490
|
+
* Generates and update artifacts from the OpenAPI specification file. Generate Adaptive Cards, update Teams app manifest, and generate a new OpenAPI specification file.
|
|
2491
|
+
* @param pluginFilePath A file path of the plugin manifest file to update.
|
|
2492
|
+
* @param filter An array of strings that represent the filters to apply when generating the artifacts. If filter is empty, it would process nothing.
|
|
2493
|
+
*/
|
|
2494
|
+
generateAdaptiveCardInPlugin(pluginFilePath, filter, signal) {
|
|
2495
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2496
|
+
if (!this.options.allowResponseSemantics) {
|
|
2497
|
+
return;
|
|
2498
|
+
}
|
|
2499
|
+
const newSpecs = yield this.getFilteredSpecs(filter, signal);
|
|
2500
|
+
const newSpec = newSpecs[1];
|
|
2501
|
+
const apiPlugin = (yield fs__default['default'].readJSON(pluginFilePath));
|
|
2502
|
+
const paths = newSpec.paths;
|
|
2503
|
+
for (const pathUrl in paths) {
|
|
2504
|
+
const pathItem = paths[pathUrl];
|
|
2505
|
+
if (pathItem) {
|
|
2506
|
+
const operations = pathItem;
|
|
2507
|
+
for (const method in operations) {
|
|
2508
|
+
if (this.options.allowMethods.includes(method)) {
|
|
2509
|
+
const operationItem = operations[method];
|
|
2510
|
+
if (operationItem) {
|
|
2511
|
+
try {
|
|
2512
|
+
const operationId = operationItem.operationId;
|
|
2513
|
+
const safeFunctionName = operationId.replace(/[^a-zA-Z0-9]/g, "_");
|
|
2514
|
+
if (apiPlugin.functions.findIndex((func) => func.name === safeFunctionName) === -1) {
|
|
2515
|
+
continue;
|
|
2516
|
+
}
|
|
2517
|
+
const { json } = Utils.getResponseJson(operationItem);
|
|
2518
|
+
if (json.schema) {
|
|
2519
|
+
const [card, jsonPath] = AdaptiveCardGenerator.generateAdaptiveCard(operationItem, false, 5);
|
|
2520
|
+
const responseSemantic = wrapResponseSemantics(card, jsonPath);
|
|
2521
|
+
apiPlugin.functions.find((func) => func.name === safeFunctionName).capabilities = {
|
|
2522
|
+
response_semantics: responseSemantic,
|
|
2523
|
+
};
|
|
2524
|
+
}
|
|
2525
|
+
}
|
|
2526
|
+
catch (err) {
|
|
2527
|
+
throw new SpecParserError(err.toString(), exports.ErrorType.GenerateAdaptiveCardFailed);
|
|
2528
|
+
}
|
|
2529
|
+
}
|
|
2530
|
+
}
|
|
2531
|
+
}
|
|
2532
|
+
}
|
|
2533
|
+
}
|
|
2534
|
+
yield fs__default['default'].outputJSON(pluginFilePath, apiPlugin, { spaces: 4 });
|
|
2535
|
+
});
|
|
2536
|
+
}
|
|
2491
2537
|
loadSpec() {
|
|
2492
2538
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2493
2539
|
if (!this.spec) {
|