@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.esm2017.mjs
CHANGED
|
@@ -5,7 +5,6 @@ import fs from 'fs-extra';
|
|
|
5
5
|
import path from 'path';
|
|
6
6
|
import { ManifestUtil } from '@microsoft/teams-manifest';
|
|
7
7
|
import { createHash } from 'crypto';
|
|
8
|
-
import { $RefParser } from '@apidevtools/json-schema-ref-parser';
|
|
9
8
|
|
|
10
9
|
// Copyright (c) Microsoft Corporation.
|
|
11
10
|
/**
|
|
@@ -2103,7 +2102,6 @@ class SpecParser {
|
|
|
2103
2102
|
};
|
|
2104
2103
|
this.pathOrSpec = pathOrDoc;
|
|
2105
2104
|
this.parser = new SwaggerParser();
|
|
2106
|
-
this.refParser = new $RefParser();
|
|
2107
2105
|
this.options = Object.assign(Object.assign({}, this.defaultOptions), (options !== null && options !== void 0 ? options : {}));
|
|
2108
2106
|
}
|
|
2109
2107
|
/**
|
|
@@ -2116,11 +2114,11 @@ class SpecParser {
|
|
|
2116
2114
|
let hash = "";
|
|
2117
2115
|
try {
|
|
2118
2116
|
await this.loadSpec();
|
|
2119
|
-
if (!this.
|
|
2117
|
+
if (!this.parser.$refs.circular) {
|
|
2120
2118
|
await this.parser.validate(this.spec);
|
|
2121
2119
|
}
|
|
2122
2120
|
else {
|
|
2123
|
-
// The following code hangs for Graph API, support will be added when SwaggerParser is updated.
|
|
2121
|
+
// The following code still hangs for Graph API, support will be added when SwaggerParser is updated.
|
|
2124
2122
|
/*
|
|
2125
2123
|
const clonedUnResolveSpec = JSON.parse(JSON.stringify(this.unResolveSpec));
|
|
2126
2124
|
await this.parser.validate(clonedUnResolveSpec);
|
|
@@ -2152,7 +2150,7 @@ class SpecParser {
|
|
|
2152
2150
|
};
|
|
2153
2151
|
}
|
|
2154
2152
|
// Remote reference not supported
|
|
2155
|
-
const refPaths = this.
|
|
2153
|
+
const refPaths = this.parser.$refs.paths();
|
|
2156
2154
|
// refPaths [0] is the current spec file path
|
|
2157
2155
|
if (refPaths.length > 1) {
|
|
2158
2156
|
errors.push({
|
|
@@ -2292,7 +2290,7 @@ class SpecParser {
|
|
|
2292
2290
|
}
|
|
2293
2291
|
}
|
|
2294
2292
|
async deReferenceSpec(spec) {
|
|
2295
|
-
const result = await this.
|
|
2293
|
+
const result = await this.parser.dereference(spec);
|
|
2296
2294
|
return result;
|
|
2297
2295
|
}
|
|
2298
2296
|
/**
|
|
@@ -2424,6 +2422,52 @@ class SpecParser {
|
|
|
2424
2422
|
}
|
|
2425
2423
|
return result;
|
|
2426
2424
|
}
|
|
2425
|
+
/**
|
|
2426
|
+
* Generates and update artifacts from the OpenAPI specification file. Generate Adaptive Cards, update Teams app manifest, and generate a new OpenAPI specification file.
|
|
2427
|
+
* @param pluginFilePath A file path of the plugin manifest file to update.
|
|
2428
|
+
* @param filter An array of strings that represent the filters to apply when generating the artifacts. If filter is empty, it would process nothing.
|
|
2429
|
+
*/
|
|
2430
|
+
async generateAdaptiveCardInPlugin(pluginFilePath, filter, signal) {
|
|
2431
|
+
if (!this.options.allowResponseSemantics) {
|
|
2432
|
+
return;
|
|
2433
|
+
}
|
|
2434
|
+
const newSpecs = await this.getFilteredSpecs(filter, signal);
|
|
2435
|
+
const newSpec = newSpecs[1];
|
|
2436
|
+
const apiPlugin = (await fs.readJSON(pluginFilePath));
|
|
2437
|
+
const paths = newSpec.paths;
|
|
2438
|
+
for (const pathUrl in paths) {
|
|
2439
|
+
const pathItem = paths[pathUrl];
|
|
2440
|
+
if (pathItem) {
|
|
2441
|
+
const operations = pathItem;
|
|
2442
|
+
for (const method in operations) {
|
|
2443
|
+
if (this.options.allowMethods.includes(method)) {
|
|
2444
|
+
const operationItem = operations[method];
|
|
2445
|
+
if (operationItem) {
|
|
2446
|
+
try {
|
|
2447
|
+
const operationId = operationItem.operationId;
|
|
2448
|
+
const safeFunctionName = operationId.replace(/[^a-zA-Z0-9]/g, "_");
|
|
2449
|
+
if (apiPlugin.functions.findIndex((func) => func.name === safeFunctionName) === -1) {
|
|
2450
|
+
continue;
|
|
2451
|
+
}
|
|
2452
|
+
const { json } = Utils.getResponseJson(operationItem);
|
|
2453
|
+
if (json.schema) {
|
|
2454
|
+
const [card, jsonPath] = AdaptiveCardGenerator.generateAdaptiveCard(operationItem, false, 5);
|
|
2455
|
+
const responseSemantic = wrapResponseSemantics(card, jsonPath);
|
|
2456
|
+
apiPlugin.functions.find((func) => func.name === safeFunctionName).capabilities = {
|
|
2457
|
+
response_semantics: responseSemantic,
|
|
2458
|
+
};
|
|
2459
|
+
}
|
|
2460
|
+
}
|
|
2461
|
+
catch (err) {
|
|
2462
|
+
throw new SpecParserError(err.toString(), ErrorType.GenerateAdaptiveCardFailed);
|
|
2463
|
+
}
|
|
2464
|
+
}
|
|
2465
|
+
}
|
|
2466
|
+
}
|
|
2467
|
+
}
|
|
2468
|
+
}
|
|
2469
|
+
await fs.outputJSON(pluginFilePath, apiPlugin, { spaces: 4 });
|
|
2470
|
+
}
|
|
2427
2471
|
async loadSpec() {
|
|
2428
2472
|
if (!this.spec) {
|
|
2429
2473
|
const spec = (await this.parser.parse(this.pathOrSpec));
|