@microsoft/m365-spec-parser 0.1.1-alpha.f4dd51600.0 → 0.1.1-alpha.fbb412c19.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.js +47 -17
- package/dist/index.esm2017.js.map +1 -1
- package/dist/index.esm2017.mjs +144 -104
- package/dist/index.esm2017.mjs.map +1 -1
- package/dist/index.esm5.js +47 -17
- package/dist/index.esm5.js.map +1 -1
- package/dist/index.node.cjs.js +146 -104
- package/dist/index.node.cjs.js.map +1 -1
- package/dist/src/constants.d.ts +5 -3
- package/dist/src/interfaces.d.ts +8 -0
- package/dist/src/manifestUpdater.d.ts +6 -4
- package/dist/src/specParser.d.ts +1 -0
- package/dist/src/utils.d.ts +1 -0
- package/package.json +3 -4
package/dist/index.node.cjs.js
CHANGED
|
@@ -125,7 +125,7 @@ ConstantString.RemoteRefNotSupported = "Remote reference is not supported: %s.";
|
|
|
125
125
|
ConstantString.MissingOperationId = "Missing operationIds: %s.";
|
|
126
126
|
ConstantString.NoSupportedApi = "No supported API is found in the OpenAPI description document: only GET and POST methods are supported, additionally, there can be at most one required parameter, and no auth is allowed.";
|
|
127
127
|
ConstantString.AdditionalPropertiesNotSupported = "'additionalProperties' is not supported, and will be ignored.";
|
|
128
|
-
ConstantString.SchemaNotSupported = "'oneOf', 'anyOf', and 'not' schema are not supported: %s.";
|
|
128
|
+
ConstantString.SchemaNotSupported = "'oneOf', 'allOf', 'anyOf', and 'not' schema are not supported: %s.";
|
|
129
129
|
ConstantString.UnknownSchema = "Unknown schema: %s.";
|
|
130
130
|
ConstantString.UrlProtocolNotSupported = "Server url is not correct: protocol %s is not supported, you should use https protocol instead.";
|
|
131
131
|
ConstantString.RelativeServerUrlNotSupported = "Server url is not correct: relative server url is not supported.";
|
|
@@ -147,8 +147,12 @@ ConstantString.AdaptiveCardType = "AdaptiveCard";
|
|
|
147
147
|
ConstantString.TextBlockType = "TextBlock";
|
|
148
148
|
ConstantString.ImageType = "Image";
|
|
149
149
|
ConstantString.ContainerType = "Container";
|
|
150
|
-
ConstantString.RegistrationIdPostfix =
|
|
151
|
-
|
|
150
|
+
ConstantString.RegistrationIdPostfix = {
|
|
151
|
+
apiKey: "REGISTRATION_ID",
|
|
152
|
+
oauth2: "CONFIGURATION_ID",
|
|
153
|
+
http: "REGISTRATION_ID",
|
|
154
|
+
openIdConnect: "REGISTRATION_ID",
|
|
155
|
+
};
|
|
152
156
|
ConstantString.ResponseCodeFor20X = [
|
|
153
157
|
"200",
|
|
154
158
|
"201",
|
|
@@ -207,6 +211,7 @@ ConstantString.ShortDescriptionMaxLens = 80;
|
|
|
207
211
|
ConstantString.FullDescriptionMaxLens = 4000;
|
|
208
212
|
ConstantString.CommandDescriptionMaxLens = 128;
|
|
209
213
|
ConstantString.ParameterDescriptionMaxLens = 128;
|
|
214
|
+
ConstantString.ConversationStarterMaxLens = 50;
|
|
210
215
|
ConstantString.CommandTitleMaxLens = 32;
|
|
211
216
|
ConstantString.ParameterTitleMaxLens = 32;
|
|
212
217
|
ConstantString.SMERequiredParamsMaxNum = 5;
|
|
@@ -251,9 +256,10 @@ class Utils {
|
|
|
251
256
|
var _a;
|
|
252
257
|
const result = [];
|
|
253
258
|
const securitySchemas = (_a = spec.components) === null || _a === void 0 ? void 0 : _a.securitySchemes;
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
259
|
+
const securitiesArr = securities !== null && securities !== void 0 ? securities : spec.security;
|
|
260
|
+
if (securitiesArr && securitySchemas) {
|
|
261
|
+
for (let i = 0; i < securitiesArr.length; i++) {
|
|
262
|
+
const security = securitiesArr[i];
|
|
257
263
|
const authArray = [];
|
|
258
264
|
for (const name in security) {
|
|
259
265
|
const auth = securitySchemas[name];
|
|
@@ -270,6 +276,25 @@ class Utils {
|
|
|
270
276
|
result.sort((a, b) => a[0].name.localeCompare(b[0].name));
|
|
271
277
|
return result;
|
|
272
278
|
}
|
|
279
|
+
static getAuthInfo(spec) {
|
|
280
|
+
let authInfo = undefined;
|
|
281
|
+
for (const url in spec.paths) {
|
|
282
|
+
for (const method in spec.paths[url]) {
|
|
283
|
+
const operation = spec.paths[url][method];
|
|
284
|
+
const authArray = Utils.getAuthArray(operation.security, spec);
|
|
285
|
+
if (authArray && authArray.length > 0) {
|
|
286
|
+
const currentAuth = authArray[0][0];
|
|
287
|
+
if (!authInfo) {
|
|
288
|
+
authInfo = authArray[0][0];
|
|
289
|
+
}
|
|
290
|
+
else if (authInfo.name !== currentAuth.name) {
|
|
291
|
+
throw new SpecParserError(ConstantString.MultipleAuthNotSupported, exports.ErrorType.MultipleAuthNotSupported);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
return authInfo;
|
|
297
|
+
}
|
|
273
298
|
static updateFirstLetter(str) {
|
|
274
299
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
275
300
|
}
|
|
@@ -651,13 +676,15 @@ class Validator {
|
|
|
651
676
|
const result = { isValid: true, reason: [] };
|
|
652
677
|
const operationObject = this.spec.paths[path][method];
|
|
653
678
|
const { json, multipleMediaType } = Utils.getResponseJson(operationObject);
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
679
|
+
if (this.options.projectType === exports.ProjectType.SME) {
|
|
680
|
+
// only support response body only contains “application/json” content type
|
|
681
|
+
if (multipleMediaType) {
|
|
682
|
+
result.reason.push(exports.ErrorType.ResponseContainMultipleMediaTypes);
|
|
683
|
+
}
|
|
684
|
+
else if (Object.keys(json).length === 0) {
|
|
685
|
+
// response body should not be empty
|
|
686
|
+
result.reason.push(exports.ErrorType.ResponseJsonIsEmpty);
|
|
687
|
+
}
|
|
661
688
|
}
|
|
662
689
|
return result;
|
|
663
690
|
}
|
|
@@ -875,9 +902,6 @@ class CopilotValidator extends Validator {
|
|
|
875
902
|
// validate requestBody
|
|
876
903
|
const requestBody = operationObject.requestBody;
|
|
877
904
|
const requestJsonBody = requestBody === null || requestBody === void 0 ? void 0 : requestBody.content["application/json"];
|
|
878
|
-
if (Utils.containMultipleMediaTypes(requestBody)) {
|
|
879
|
-
result.reason.push(exports.ErrorType.PostBodyContainMultipleMediaTypes);
|
|
880
|
-
}
|
|
881
905
|
if (requestJsonBody) {
|
|
882
906
|
const requestBodySchema = requestJsonBody.schema;
|
|
883
907
|
if (requestBodySchema.type !== "object") {
|
|
@@ -1382,20 +1406,23 @@ function inferProperties(card) {
|
|
|
1382
1406
|
|
|
1383
1407
|
// Copyright (c) Microsoft Corporation.
|
|
1384
1408
|
class ManifestUpdater {
|
|
1385
|
-
static updateManifestWithAiPlugin(manifestPath, outputSpecPath, apiPluginFilePath, spec, options) {
|
|
1409
|
+
static updateManifestWithAiPlugin(manifestPath, outputSpecPath, apiPluginFilePath, spec, options, authInfo) {
|
|
1386
1410
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1387
1411
|
const manifest = yield fs__default['default'].readJSON(manifestPath);
|
|
1388
1412
|
const apiPluginRelativePath = ManifestUpdater.getRelativePath(manifestPath, apiPluginFilePath);
|
|
1389
|
-
manifest.
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1413
|
+
// Insert plugins in manifest.json if it is plugin for Copilot.
|
|
1414
|
+
if (!options.isGptPlugin) {
|
|
1415
|
+
manifest.plugins = [
|
|
1416
|
+
{
|
|
1417
|
+
file: apiPluginRelativePath,
|
|
1418
|
+
id: ConstantString.DefaultPluginId,
|
|
1419
|
+
},
|
|
1420
|
+
];
|
|
1421
|
+
ManifestUpdater.updateManifestDescription(manifest, spec);
|
|
1422
|
+
}
|
|
1395
1423
|
const appName = this.removeEnvs(manifest.name.short);
|
|
1396
|
-
ManifestUpdater.updateManifestDescription(manifest, spec);
|
|
1397
1424
|
const specRelativePath = ManifestUpdater.getRelativePath(manifestPath, outputSpecPath);
|
|
1398
|
-
const apiPlugin = yield ManifestUpdater.generatePluginManifestSchema(spec, specRelativePath, apiPluginFilePath, appName, options);
|
|
1425
|
+
const apiPlugin = yield ManifestUpdater.generatePluginManifestSchema(spec, specRelativePath, apiPluginFilePath, appName, authInfo, options);
|
|
1399
1426
|
return [manifest, apiPlugin];
|
|
1400
1427
|
});
|
|
1401
1428
|
}
|
|
@@ -1406,27 +1433,40 @@ class ManifestUpdater {
|
|
|
1406
1433
|
full: (_b = ((_a = spec.info.description) !== null && _a !== void 0 ? _a : manifest.description.full)) === null || _b === void 0 ? void 0 : _b.slice(0, ConstantString.FullDescriptionMaxLens),
|
|
1407
1434
|
};
|
|
1408
1435
|
}
|
|
1409
|
-
static
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
schema.type === "integer" ||
|
|
1414
|
-
schema.type === "number" ||
|
|
1415
|
-
schema.type === "array") {
|
|
1416
|
-
parameter = schema;
|
|
1436
|
+
static checkSchema(schema, method, pathUrl) {
|
|
1437
|
+
if (schema.type === "array") {
|
|
1438
|
+
const items = schema.items;
|
|
1439
|
+
ManifestUpdater.checkSchema(items, method, pathUrl);
|
|
1417
1440
|
}
|
|
1418
|
-
else
|
|
1441
|
+
else if (schema.type !== "string" &&
|
|
1442
|
+
schema.type !== "boolean" &&
|
|
1443
|
+
schema.type !== "integer" &&
|
|
1444
|
+
schema.type !== "number") {
|
|
1419
1445
|
throw new SpecParserError(Utils.format(ConstantString.UnsupportedSchema, method, pathUrl, JSON.stringify(schema)), exports.ErrorType.UpdateManifestFailed);
|
|
1420
1446
|
}
|
|
1421
|
-
return parameter;
|
|
1422
1447
|
}
|
|
1423
|
-
static generatePluginManifestSchema(spec, specRelativePath, apiPluginFilePath, appName, options) {
|
|
1448
|
+
static generatePluginManifestSchema(spec, specRelativePath, apiPluginFilePath, appName, authInfo, options) {
|
|
1424
1449
|
var _a, _b, _c, _d;
|
|
1425
1450
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1426
1451
|
const functions = [];
|
|
1427
1452
|
const functionNames = [];
|
|
1428
1453
|
const conversationStarters = [];
|
|
1429
1454
|
const paths = spec.paths;
|
|
1455
|
+
const pluginAuthObj = {
|
|
1456
|
+
type: "None",
|
|
1457
|
+
};
|
|
1458
|
+
if (authInfo) {
|
|
1459
|
+
if (Utils.isOAuthWithAuthCodeFlow(authInfo.authScheme)) {
|
|
1460
|
+
pluginAuthObj.type = "OAuthPluginVault";
|
|
1461
|
+
}
|
|
1462
|
+
else if (Utils.isBearerTokenAuth(authInfo.authScheme)) {
|
|
1463
|
+
pluginAuthObj.type = "ApiKeyPluginVault";
|
|
1464
|
+
}
|
|
1465
|
+
if (pluginAuthObj.type !== "None") {
|
|
1466
|
+
const safeRegistrationIdName = Utils.getSafeRegistrationIdEnvName(`${authInfo.name}_${ConstantString.RegistrationIdPostfix[authInfo.authScheme.type]}`);
|
|
1467
|
+
pluginAuthObj.reference_id = `\${{${safeRegistrationIdName}}}`;
|
|
1468
|
+
}
|
|
1469
|
+
}
|
|
1430
1470
|
for (const pathUrl in paths) {
|
|
1431
1471
|
const pathItem = paths[pathUrl];
|
|
1432
1472
|
if (pathItem) {
|
|
@@ -1434,39 +1474,29 @@ class ManifestUpdater {
|
|
|
1434
1474
|
for (const method in operations) {
|
|
1435
1475
|
if (options.allowMethods.includes(method)) {
|
|
1436
1476
|
const operationItem = operations[method];
|
|
1477
|
+
const confirmationBodies = [];
|
|
1437
1478
|
if (operationItem) {
|
|
1438
1479
|
const operationId = operationItem.operationId;
|
|
1439
1480
|
const description = (_a = operationItem.description) !== null && _a !== void 0 ? _a : "";
|
|
1481
|
+
const summary = operationItem.summary;
|
|
1440
1482
|
const paramObject = operationItem.parameters;
|
|
1441
1483
|
const requestBody = operationItem.requestBody;
|
|
1442
|
-
const parameters = {
|
|
1443
|
-
type: "object",
|
|
1444
|
-
properties: {},
|
|
1445
|
-
required: [],
|
|
1446
|
-
};
|
|
1447
1484
|
if (paramObject) {
|
|
1448
1485
|
for (let i = 0; i < paramObject.length; i++) {
|
|
1449
1486
|
const param = paramObject[i];
|
|
1450
1487
|
const schema = param.schema;
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
parameters.required.push(param.name);
|
|
1454
|
-
}
|
|
1455
|
-
if (!parameters.properties[param.name].description) {
|
|
1456
|
-
parameters.properties[param.name].description = (_b = param.description) !== null && _b !== void 0 ? _b : "";
|
|
1457
|
-
}
|
|
1488
|
+
ManifestUpdater.checkSchema(schema, method, pathUrl);
|
|
1489
|
+
confirmationBodies.push(ManifestUpdater.getConfirmationBodyItem(param.name));
|
|
1458
1490
|
}
|
|
1459
1491
|
}
|
|
1460
1492
|
if (requestBody) {
|
|
1461
1493
|
const requestJsonBody = requestBody.content["application/json"];
|
|
1462
1494
|
const requestBodySchema = requestJsonBody.schema;
|
|
1463
1495
|
if (requestBodySchema.type === "object") {
|
|
1464
|
-
if (requestBodySchema.required) {
|
|
1465
|
-
parameters.required.push(...requestBodySchema.required);
|
|
1466
|
-
}
|
|
1467
1496
|
for (const property in requestBodySchema.properties) {
|
|
1468
1497
|
const schema = requestBodySchema.properties[property];
|
|
1469
|
-
|
|
1498
|
+
ManifestUpdater.checkSchema(schema, method, pathUrl);
|
|
1499
|
+
confirmationBodies.push(ManifestUpdater.getConfirmationBodyItem(property));
|
|
1470
1500
|
}
|
|
1471
1501
|
}
|
|
1472
1502
|
else {
|
|
@@ -1476,19 +1506,34 @@ class ManifestUpdater {
|
|
|
1476
1506
|
const funcObj = {
|
|
1477
1507
|
name: operationId,
|
|
1478
1508
|
description: description,
|
|
1479
|
-
parameters: parameters,
|
|
1480
1509
|
};
|
|
1481
1510
|
if (options.allowResponseSemantics) {
|
|
1482
|
-
const
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1511
|
+
const { json } = Utils.getResponseJson(operationItem);
|
|
1512
|
+
if (json.schema) {
|
|
1513
|
+
const [card, jsonPath] = AdaptiveCardGenerator.generateAdaptiveCard(operationItem);
|
|
1514
|
+
const responseSemantic = wrapResponseSemantics(card, jsonPath);
|
|
1515
|
+
funcObj.capabilities = {
|
|
1516
|
+
response_semantics: responseSemantic,
|
|
1517
|
+
};
|
|
1518
|
+
}
|
|
1519
|
+
}
|
|
1520
|
+
if (options.allowConfirmation && method !== ConstantString.GetMethod) {
|
|
1521
|
+
if (!funcObj.capabilities) {
|
|
1522
|
+
funcObj.capabilities = {};
|
|
1523
|
+
}
|
|
1524
|
+
funcObj.capabilities.confirmation = {
|
|
1525
|
+
type: "AdaptiveCard",
|
|
1526
|
+
title: (_b = operationItem.summary) !== null && _b !== void 0 ? _b : description,
|
|
1486
1527
|
};
|
|
1528
|
+
if (confirmationBodies.length > 0) {
|
|
1529
|
+
funcObj.capabilities.confirmation.body = confirmationBodies.join("\n");
|
|
1530
|
+
}
|
|
1487
1531
|
}
|
|
1488
1532
|
functions.push(funcObj);
|
|
1489
1533
|
functionNames.push(operationId);
|
|
1490
|
-
|
|
1491
|
-
|
|
1534
|
+
const conversationStarterStr = (summary !== null && summary !== void 0 ? summary : description).slice(0, ConstantString.ConversationStarterMaxLens);
|
|
1535
|
+
if (conversationStarterStr) {
|
|
1536
|
+
conversationStarters.push(conversationStarterStr);
|
|
1492
1537
|
}
|
|
1493
1538
|
}
|
|
1494
1539
|
}
|
|
@@ -1501,9 +1546,10 @@ class ManifestUpdater {
|
|
|
1501
1546
|
}
|
|
1502
1547
|
else {
|
|
1503
1548
|
apiPlugin = {
|
|
1504
|
-
schema_version: "v2",
|
|
1549
|
+
schema_version: "v2.1",
|
|
1505
1550
|
name_for_human: "",
|
|
1506
1551
|
description_for_human: "",
|
|
1552
|
+
namespace: "",
|
|
1507
1553
|
functions: [],
|
|
1508
1554
|
runtimes: [],
|
|
1509
1555
|
};
|
|
@@ -1519,13 +1565,16 @@ class ManifestUpdater {
|
|
|
1519
1565
|
}
|
|
1520
1566
|
}
|
|
1521
1567
|
apiPlugin.runtimes = apiPlugin.runtimes || [];
|
|
1522
|
-
const index = apiPlugin.runtimes.findIndex((runtime) =>
|
|
1568
|
+
const index = apiPlugin.runtimes.findIndex((runtime) => {
|
|
1569
|
+
var _a, _b;
|
|
1570
|
+
return runtime.spec.url === specRelativePath &&
|
|
1571
|
+
runtime.type === "OpenApi" &&
|
|
1572
|
+
((_b = (_a = runtime.auth) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : "None") === pluginAuthObj.type;
|
|
1573
|
+
});
|
|
1523
1574
|
if (index === -1) {
|
|
1524
1575
|
apiPlugin.runtimes.push({
|
|
1525
1576
|
type: "OpenApi",
|
|
1526
|
-
auth:
|
|
1527
|
-
type: "none",
|
|
1528
|
-
},
|
|
1577
|
+
auth: pluginAuthObj,
|
|
1529
1578
|
spec: {
|
|
1530
1579
|
url: specRelativePath,
|
|
1531
1580
|
},
|
|
@@ -1538,6 +1587,9 @@ class ManifestUpdater {
|
|
|
1538
1587
|
if (!apiPlugin.name_for_human) {
|
|
1539
1588
|
apiPlugin.name_for_human = appName;
|
|
1540
1589
|
}
|
|
1590
|
+
if (!apiPlugin.namespace) {
|
|
1591
|
+
apiPlugin.namespace = ManifestUpdater.removeAllSpecialCharacters(appName);
|
|
1592
|
+
}
|
|
1541
1593
|
if (!apiPlugin.description_for_human) {
|
|
1542
1594
|
apiPlugin.description_for_human =
|
|
1543
1595
|
(_d = spec.info.description) !== null && _d !== void 0 ? _d : "<Please add description of the plugin>";
|
|
@@ -1575,21 +1627,21 @@ class ManifestUpdater {
|
|
|
1575
1627
|
};
|
|
1576
1628
|
if (authInfo) {
|
|
1577
1629
|
const auth = authInfo.authScheme;
|
|
1630
|
+
const safeRegistrationIdName = Utils.getSafeRegistrationIdEnvName(`${authInfo.name}_${ConstantString.RegistrationIdPostfix[authInfo.authScheme.type]}`);
|
|
1578
1631
|
if (Utils.isAPIKeyAuth(auth) || Utils.isBearerTokenAuth(auth)) {
|
|
1579
|
-
const safeApiSecretRegistrationId = Utils.getSafeRegistrationIdEnvName(`${authInfo.name}_${ConstantString.RegistrationIdPostfix}`);
|
|
1632
|
+
const safeApiSecretRegistrationId = Utils.getSafeRegistrationIdEnvName(`${authInfo.name}_${ConstantString.RegistrationIdPostfix[authInfo.authScheme.type]}`);
|
|
1580
1633
|
composeExtension.authorization = {
|
|
1581
1634
|
authType: "apiSecretServiceAuth",
|
|
1582
1635
|
apiSecretServiceAuthConfiguration: {
|
|
1583
|
-
apiSecretRegistrationId: `\${{${
|
|
1636
|
+
apiSecretRegistrationId: `\${{${safeRegistrationIdName}}}`,
|
|
1584
1637
|
},
|
|
1585
1638
|
};
|
|
1586
1639
|
}
|
|
1587
1640
|
else if (Utils.isOAuthWithAuthCodeFlow(auth)) {
|
|
1588
|
-
const safeOAuth2RegistrationId = Utils.getSafeRegistrationIdEnvName(`${authInfo.name}_${ConstantString.OAuthRegistrationIdPostFix}`);
|
|
1589
1641
|
composeExtension.authorization = {
|
|
1590
1642
|
authType: "oAuth2.0",
|
|
1591
1643
|
oAuthConfiguration: {
|
|
1592
|
-
oauthConfigurationId: `\${{${
|
|
1644
|
+
oauthConfigurationId: `\${{${safeRegistrationIdName}}}`,
|
|
1593
1645
|
},
|
|
1594
1646
|
};
|
|
1595
1647
|
updatedPart.webApplicationInfo = {
|
|
@@ -1669,6 +1721,12 @@ class ManifestUpdater {
|
|
|
1669
1721
|
}
|
|
1670
1722
|
return newStr;
|
|
1671
1723
|
}
|
|
1724
|
+
static removeAllSpecialCharacters(str) {
|
|
1725
|
+
return str.toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
1726
|
+
}
|
|
1727
|
+
static getConfirmationBodyItem(paramName) {
|
|
1728
|
+
return `* **${Utils.updateFirstLetter(paramName)}**: {{function.parameters.${paramName}}}`;
|
|
1729
|
+
}
|
|
1672
1730
|
}
|
|
1673
1731
|
|
|
1674
1732
|
// Copyright (c) Microsoft Corporation.
|
|
@@ -1692,7 +1750,9 @@ class SpecParser {
|
|
|
1692
1750
|
allowMethods: ["get", "post"],
|
|
1693
1751
|
allowConversationStarters: false,
|
|
1694
1752
|
allowResponseSemantics: false,
|
|
1753
|
+
allowConfirmation: false,
|
|
1695
1754
|
projectType: exports.ProjectType.SME,
|
|
1755
|
+
isGptPlugin: false,
|
|
1696
1756
|
};
|
|
1697
1757
|
this.pathOrSpec = pathOrDoc;
|
|
1698
1758
|
this.parser = new SwaggerParser__default['default']();
|
|
@@ -1873,18 +1933,12 @@ class SpecParser {
|
|
|
1873
1933
|
const newSpecs = yield this.getFilteredSpecs(filter, signal);
|
|
1874
1934
|
const newUnResolvedSpec = newSpecs[0];
|
|
1875
1935
|
const newSpec = newSpecs[1];
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
resultStr = jsyaml__default['default'].dump(newUnResolvedSpec);
|
|
1879
|
-
}
|
|
1880
|
-
else {
|
|
1881
|
-
resultStr = JSON.stringify(newUnResolvedSpec, null, 2);
|
|
1882
|
-
}
|
|
1883
|
-
yield fs__default['default'].outputFile(outputSpecPath, resultStr);
|
|
1936
|
+
const authInfo = Utils.getAuthInfo(newSpec);
|
|
1937
|
+
yield this.saveFilterSpec(outputSpecPath, newUnResolvedSpec);
|
|
1884
1938
|
if (signal === null || signal === void 0 ? void 0 : signal.aborted) {
|
|
1885
1939
|
throw new SpecParserError(ConstantString.CancelledMessage, exports.ErrorType.Cancelled);
|
|
1886
1940
|
}
|
|
1887
|
-
const [updatedManifest, apiPlugin] = yield ManifestUpdater.updateManifestWithAiPlugin(manifestPath, outputSpecPath, pluginFilePath, newSpec, this.options);
|
|
1941
|
+
const [updatedManifest, apiPlugin] = yield ManifestUpdater.updateManifestWithAiPlugin(manifestPath, outputSpecPath, pluginFilePath, newSpec, this.options, authInfo);
|
|
1888
1942
|
yield fs__default['default'].outputJSON(manifestPath, updatedManifest, { spaces: 2 });
|
|
1889
1943
|
yield fs__default['default'].outputJSON(pluginFilePath, apiPlugin, { spaces: 2 });
|
|
1890
1944
|
}
|
|
@@ -1914,35 +1968,11 @@ class SpecParser {
|
|
|
1914
1968
|
const newSpecs = yield this.getFilteredSpecs(filter, signal);
|
|
1915
1969
|
const newUnResolvedSpec = newSpecs[0];
|
|
1916
1970
|
const newSpec = newSpecs[1];
|
|
1917
|
-
let hasMultipleAuth = false;
|
|
1918
1971
|
let authInfo = undefined;
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
const operation = newSpec.paths[url][method];
|
|
1922
|
-
const authArray = Utils.getAuthArray(operation.security, newSpec);
|
|
1923
|
-
if (authArray && authArray.length > 0) {
|
|
1924
|
-
const currentAuth = authArray[0][0];
|
|
1925
|
-
if (!authInfo) {
|
|
1926
|
-
authInfo = authArray[0][0];
|
|
1927
|
-
}
|
|
1928
|
-
else if (authInfo.name !== currentAuth.name) {
|
|
1929
|
-
hasMultipleAuth = true;
|
|
1930
|
-
break;
|
|
1931
|
-
}
|
|
1932
|
-
}
|
|
1933
|
-
}
|
|
1934
|
-
}
|
|
1935
|
-
if (hasMultipleAuth && this.options.projectType !== exports.ProjectType.TeamsAi) {
|
|
1936
|
-
throw new SpecParserError(ConstantString.MultipleAuthNotSupported, exports.ErrorType.MultipleAuthNotSupported);
|
|
1937
|
-
}
|
|
1938
|
-
let resultStr;
|
|
1939
|
-
if (outputSpecPath.endsWith(".yaml") || outputSpecPath.endsWith(".yml")) {
|
|
1940
|
-
resultStr = jsyaml__default['default'].dump(newUnResolvedSpec);
|
|
1941
|
-
}
|
|
1942
|
-
else {
|
|
1943
|
-
resultStr = JSON.stringify(newUnResolvedSpec, null, 2);
|
|
1972
|
+
if (this.options.projectType === exports.ProjectType.SME) {
|
|
1973
|
+
authInfo = Utils.getAuthInfo(newSpec);
|
|
1944
1974
|
}
|
|
1945
|
-
yield
|
|
1975
|
+
yield this.saveFilterSpec(outputSpecPath, newUnResolvedSpec);
|
|
1946
1976
|
if (adaptiveCardFolder) {
|
|
1947
1977
|
for (const url in newSpec.paths) {
|
|
1948
1978
|
for (const method in newSpec.paths[url]) {
|
|
@@ -2013,6 +2043,18 @@ class SpecParser {
|
|
|
2013
2043
|
this.validator = validator;
|
|
2014
2044
|
return validator;
|
|
2015
2045
|
}
|
|
2046
|
+
saveFilterSpec(outputSpecPath, unResolvedSpec) {
|
|
2047
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2048
|
+
let resultStr;
|
|
2049
|
+
if (outputSpecPath.endsWith(".yaml") || outputSpecPath.endsWith(".yml")) {
|
|
2050
|
+
resultStr = jsyaml__default['default'].dump(unResolvedSpec);
|
|
2051
|
+
}
|
|
2052
|
+
else {
|
|
2053
|
+
resultStr = JSON.stringify(unResolvedSpec, null, 2);
|
|
2054
|
+
}
|
|
2055
|
+
yield fs__default['default'].outputFile(outputSpecPath, resultStr);
|
|
2056
|
+
});
|
|
2057
|
+
}
|
|
2016
2058
|
}
|
|
2017
2059
|
|
|
2018
2060
|
exports.AdaptiveCardGenerator = AdaptiveCardGenerator;
|