@microsoft/m365-spec-parser 0.1.1-alpha.2c983f96a.0 → 0.1.1-alpha.3bb446445.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.
@@ -147,7 +147,12 @@ ConstantString.AdaptiveCardType = "AdaptiveCard";
147
147
  ConstantString.TextBlockType = "TextBlock";
148
148
  ConstantString.ImageType = "Image";
149
149
  ConstantString.ContainerType = "Container";
150
- ConstantString.RegistrationIdPostfix = "REGISTRATION_ID";
150
+ ConstantString.RegistrationIdPostfix = {
151
+ apiKey: "REGISTRATION_ID",
152
+ oauth2: "CONFIGURATION_ID",
153
+ http: "REGISTRATION_ID",
154
+ openIdConnect: "REGISTRATION_ID",
155
+ };
151
156
  ConstantString.ResponseCodeFor20X = [
152
157
  "200",
153
158
  "201",
@@ -206,6 +211,7 @@ ConstantString.ShortDescriptionMaxLens = 80;
206
211
  ConstantString.FullDescriptionMaxLens = 4000;
207
212
  ConstantString.CommandDescriptionMaxLens = 128;
208
213
  ConstantString.ParameterDescriptionMaxLens = 128;
214
+ ConstantString.ConversationStarterMaxLens = 50;
209
215
  ConstantString.CommandTitleMaxLens = 32;
210
216
  ConstantString.ParameterTitleMaxLens = 32;
211
217
  ConstantString.SMERequiredParamsMaxNum = 5;
@@ -1404,14 +1410,17 @@ class ManifestUpdater {
1404
1410
  return __awaiter(this, void 0, void 0, function* () {
1405
1411
  const manifest = yield fs__default['default'].readJSON(manifestPath);
1406
1412
  const apiPluginRelativePath = ManifestUpdater.getRelativePath(manifestPath, apiPluginFilePath);
1407
- manifest.plugins = [
1408
- {
1409
- file: apiPluginRelativePath,
1410
- id: ConstantString.DefaultPluginId,
1411
- },
1412
- ];
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
+ }
1413
1423
  const appName = this.removeEnvs(manifest.name.short);
1414
- ManifestUpdater.updateManifestDescription(manifest, spec);
1415
1424
  const specRelativePath = ManifestUpdater.getRelativePath(manifestPath, outputSpecPath);
1416
1425
  const apiPlugin = yield ManifestUpdater.generatePluginManifestSchema(spec, specRelativePath, apiPluginFilePath, appName, authInfo, options);
1417
1426
  return [manifest, apiPlugin];
@@ -1424,39 +1433,20 @@ class ManifestUpdater {
1424
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),
1425
1434
  };
1426
1435
  }
1427
- static mapOpenAPISchemaToFuncParam(schema, method, pathUrl) {
1428
- let parameter;
1436
+ static checkSchema(schema, method, pathUrl) {
1429
1437
  if (schema.type === "array") {
1430
1438
  const items = schema.items;
1431
- parameter = {
1432
- type: "array",
1433
- items: ManifestUpdater.mapOpenAPISchemaToFuncParam(items, method, pathUrl),
1434
- };
1435
- }
1436
- else if (schema.type === "string" ||
1437
- schema.type === "boolean" ||
1438
- schema.type === "integer" ||
1439
- schema.type === "number") {
1440
- parameter = {
1441
- type: schema.type,
1442
- };
1439
+ ManifestUpdater.checkSchema(items, method, pathUrl);
1443
1440
  }
1444
- else {
1441
+ else if (schema.type !== "string" &&
1442
+ schema.type !== "boolean" &&
1443
+ schema.type !== "integer" &&
1444
+ schema.type !== "number") {
1445
1445
  throw new SpecParserError(Utils.format(ConstantString.UnsupportedSchema, method, pathUrl, JSON.stringify(schema)), exports.ErrorType.UpdateManifestFailed);
1446
1446
  }
1447
- if (schema.enum) {
1448
- parameter.enum = schema.enum;
1449
- }
1450
- if (schema.description) {
1451
- parameter.description = schema.description;
1452
- }
1453
- if (schema.default) {
1454
- parameter.default = schema.default;
1455
- }
1456
- return parameter;
1457
1447
  }
1458
1448
  static generatePluginManifestSchema(spec, specRelativePath, apiPluginFilePath, appName, authInfo, options) {
1459
- var _a, _b, _c, _d, _e;
1449
+ var _a, _b, _c, _d;
1460
1450
  return __awaiter(this, void 0, void 0, function* () {
1461
1451
  const functions = [];
1462
1452
  const functionNames = [];
@@ -1473,7 +1463,7 @@ class ManifestUpdater {
1473
1463
  pluginAuthObj.type = "ApiKeyPluginVault";
1474
1464
  }
1475
1465
  if (pluginAuthObj.type !== "None") {
1476
- const safeRegistrationIdName = Utils.getSafeRegistrationIdEnvName(`${authInfo.name}_${ConstantString.RegistrationIdPostfix}`);
1466
+ const safeRegistrationIdName = Utils.getSafeRegistrationIdEnvName(`${authInfo.name}_${ConstantString.RegistrationIdPostfix[authInfo.authScheme.type]}`);
1477
1467
  pluginAuthObj.reference_id = `\${{${safeRegistrationIdName}}}`;
1478
1468
  }
1479
1469
  }
@@ -1488,37 +1478,24 @@ class ManifestUpdater {
1488
1478
  if (operationItem) {
1489
1479
  const operationId = operationItem.operationId;
1490
1480
  const description = (_a = operationItem.description) !== null && _a !== void 0 ? _a : "";
1481
+ const summary = operationItem.summary;
1491
1482
  const paramObject = operationItem.parameters;
1492
1483
  const requestBody = operationItem.requestBody;
1493
- const parameters = {
1494
- type: "object",
1495
- properties: {},
1496
- required: [],
1497
- };
1498
1484
  if (paramObject) {
1499
1485
  for (let i = 0; i < paramObject.length; i++) {
1500
1486
  const param = paramObject[i];
1501
1487
  const schema = param.schema;
1502
- parameters.properties[param.name] = ManifestUpdater.mapOpenAPISchemaToFuncParam(schema, method, pathUrl);
1488
+ ManifestUpdater.checkSchema(schema, method, pathUrl);
1503
1489
  confirmationBodies.push(ManifestUpdater.getConfirmationBodyItem(param.name));
1504
- if (param.required) {
1505
- parameters.required.push(param.name);
1506
- }
1507
- if (!parameters.properties[param.name].description) {
1508
- parameters.properties[param.name].description = (_b = param.description) !== null && _b !== void 0 ? _b : "";
1509
- }
1510
1490
  }
1511
1491
  }
1512
1492
  if (requestBody) {
1513
1493
  const requestJsonBody = requestBody.content["application/json"];
1514
1494
  const requestBodySchema = requestJsonBody.schema;
1515
1495
  if (requestBodySchema.type === "object") {
1516
- if (requestBodySchema.required) {
1517
- parameters.required.push(...requestBodySchema.required);
1518
- }
1519
1496
  for (const property in requestBodySchema.properties) {
1520
1497
  const schema = requestBodySchema.properties[property];
1521
- parameters.properties[property] = ManifestUpdater.mapOpenAPISchemaToFuncParam(schema, method, pathUrl);
1498
+ ManifestUpdater.checkSchema(schema, method, pathUrl);
1522
1499
  confirmationBodies.push(ManifestUpdater.getConfirmationBodyItem(property));
1523
1500
  }
1524
1501
  }
@@ -1530,15 +1507,15 @@ class ManifestUpdater {
1530
1507
  name: operationId,
1531
1508
  description: description,
1532
1509
  };
1533
- if (paramObject || requestBody) {
1534
- funcObj.parameters = parameters;
1535
- }
1536
1510
  if (options.allowResponseSemantics) {
1537
- const [card, jsonPath] = AdaptiveCardGenerator.generateAdaptiveCard(operationItem);
1538
- const responseSemantic = wrapResponseSemantics(card, jsonPath);
1539
- funcObj.capabilities = {
1540
- response_semantics: responseSemantic,
1541
- };
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
+ }
1542
1519
  }
1543
1520
  if (options.allowConfirmation && method !== ConstantString.GetMethod) {
1544
1521
  if (!funcObj.capabilities) {
@@ -1546,7 +1523,7 @@ class ManifestUpdater {
1546
1523
  }
1547
1524
  funcObj.capabilities.confirmation = {
1548
1525
  type: "AdaptiveCard",
1549
- title: (_c = operationItem.summary) !== null && _c !== void 0 ? _c : description,
1526
+ title: (_b = operationItem.summary) !== null && _b !== void 0 ? _b : description,
1550
1527
  };
1551
1528
  if (confirmationBodies.length > 0) {
1552
1529
  funcObj.capabilities.confirmation.body = confirmationBodies.join("\n");
@@ -1554,8 +1531,9 @@ class ManifestUpdater {
1554
1531
  }
1555
1532
  functions.push(funcObj);
1556
1533
  functionNames.push(operationId);
1557
- if (description) {
1558
- conversationStarters.push(description);
1534
+ const conversationStarterStr = (summary !== null && summary !== void 0 ? summary : description).slice(0, ConstantString.ConversationStarterMaxLens);
1535
+ if (conversationStarterStr) {
1536
+ conversationStarters.push(conversationStarterStr);
1559
1537
  }
1560
1538
  }
1561
1539
  }
@@ -1578,7 +1556,7 @@ class ManifestUpdater {
1578
1556
  }
1579
1557
  apiPlugin.functions = apiPlugin.functions || [];
1580
1558
  for (const func of functions) {
1581
- const index = (_d = apiPlugin.functions) === null || _d === void 0 ? void 0 : _d.findIndex((f) => f.name === func.name);
1559
+ const index = (_c = apiPlugin.functions) === null || _c === void 0 ? void 0 : _c.findIndex((f) => f.name === func.name);
1582
1560
  if (index === -1) {
1583
1561
  apiPlugin.functions.push(func);
1584
1562
  }
@@ -1614,7 +1592,7 @@ class ManifestUpdater {
1614
1592
  }
1615
1593
  if (!apiPlugin.description_for_human) {
1616
1594
  apiPlugin.description_for_human =
1617
- (_e = spec.info.description) !== null && _e !== void 0 ? _e : "<Please add description of the plugin>";
1595
+ (_d = spec.info.description) !== null && _d !== void 0 ? _d : "<Please add description of the plugin>";
1618
1596
  }
1619
1597
  if (options.allowConversationStarters && conversationStarters.length > 0) {
1620
1598
  if (!apiPlugin.capabilities) {
@@ -1649,9 +1627,9 @@ class ManifestUpdater {
1649
1627
  };
1650
1628
  if (authInfo) {
1651
1629
  const auth = authInfo.authScheme;
1652
- const safeRegistrationIdName = Utils.getSafeRegistrationIdEnvName(`${authInfo.name}_${ConstantString.RegistrationIdPostfix}`);
1630
+ const safeRegistrationIdName = Utils.getSafeRegistrationIdEnvName(`${authInfo.name}_${ConstantString.RegistrationIdPostfix[authInfo.authScheme.type]}`);
1653
1631
  if (Utils.isAPIKeyAuth(auth) || Utils.isBearerTokenAuth(auth)) {
1654
- const safeApiSecretRegistrationId = Utils.getSafeRegistrationIdEnvName(`${authInfo.name}_${ConstantString.RegistrationIdPostfix}`);
1632
+ const safeApiSecretRegistrationId = Utils.getSafeRegistrationIdEnvName(`${authInfo.name}_${ConstantString.RegistrationIdPostfix[authInfo.authScheme.type]}`);
1655
1633
  composeExtension.authorization = {
1656
1634
  authType: "apiSecretServiceAuth",
1657
1635
  apiSecretServiceAuthConfiguration: {
@@ -1774,6 +1752,7 @@ class SpecParser {
1774
1752
  allowResponseSemantics: false,
1775
1753
  allowConfirmation: false,
1776
1754
  projectType: exports.ProjectType.SME,
1755
+ isGptPlugin: false,
1777
1756
  };
1778
1757
  this.pathOrSpec = pathOrDoc;
1779
1758
  this.parser = new SwaggerParser__default['default']();