@microsoft/m365-spec-parser 0.1.1-alpha.ded43fb2d.0 → 0.1.1-alpha.e1b11d5b2.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.
@@ -83,7 +83,7 @@ ConstantString.RemoteRefNotSupported = "Remote reference is not supported: %s.";
83
83
  ConstantString.MissingOperationId = "Missing operationIds: %s.";
84
84
  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.";
85
85
  ConstantString.AdditionalPropertiesNotSupported = "'additionalProperties' is not supported, and will be ignored.";
86
- ConstantString.SchemaNotSupported = "'oneOf', 'anyOf', and 'not' schema are not supported: %s.";
86
+ ConstantString.SchemaNotSupported = "'oneOf', 'allOf', 'anyOf', and 'not' schema are not supported: %s.";
87
87
  ConstantString.UnknownSchema = "Unknown schema: %s.";
88
88
  ConstantString.UrlProtocolNotSupported = "Server url is not correct: protocol %s is not supported, you should use https protocol instead.";
89
89
  ConstantString.RelativeServerUrlNotSupported = "Server url is not correct: relative server url is not supported.";
@@ -105,8 +105,12 @@ ConstantString.AdaptiveCardType = "AdaptiveCard";
105
105
  ConstantString.TextBlockType = "TextBlock";
106
106
  ConstantString.ImageType = "Image";
107
107
  ConstantString.ContainerType = "Container";
108
- ConstantString.RegistrationIdPostfix = "REGISTRATION_ID";
109
- ConstantString.OAuthRegistrationIdPostFix = "OAUTH_REGISTRATION_ID";
108
+ ConstantString.RegistrationIdPostfix = {
109
+ apiKey: "REGISTRATION_ID",
110
+ oauth2: "CONFIGURATION_ID",
111
+ http: "REGISTRATION_ID",
112
+ openIdConnect: "REGISTRATION_ID",
113
+ };
110
114
  ConstantString.ResponseCodeFor20X = [
111
115
  "200",
112
116
  "201",
@@ -165,6 +169,7 @@ ConstantString.ShortDescriptionMaxLens = 80;
165
169
  ConstantString.FullDescriptionMaxLens = 4000;
166
170
  ConstantString.CommandDescriptionMaxLens = 128;
167
171
  ConstantString.ParameterDescriptionMaxLens = 128;
172
+ ConstantString.ConversationStarterMaxLens = 50;
168
173
  ConstantString.CommandTitleMaxLens = 32;
169
174
  ConstantString.ParameterTitleMaxLens = 32;
170
175
  ConstantString.SMERequiredParamsMaxNum = 5;
@@ -209,9 +214,10 @@ class Utils {
209
214
  var _a;
210
215
  const result = [];
211
216
  const securitySchemas = (_a = spec.components) === null || _a === void 0 ? void 0 : _a.securitySchemes;
212
- if (securities && securitySchemas) {
213
- for (let i = 0; i < securities.length; i++) {
214
- const security = securities[i];
217
+ const securitiesArr = securities !== null && securities !== void 0 ? securities : spec.security;
218
+ if (securitiesArr && securitySchemas) {
219
+ for (let i = 0; i < securitiesArr.length; i++) {
220
+ const security = securitiesArr[i];
215
221
  const authArray = [];
216
222
  for (const name in security) {
217
223
  const auth = securitySchemas[name];
@@ -1361,14 +1367,17 @@ class ManifestUpdater {
1361
1367
  static async updateManifestWithAiPlugin(manifestPath, outputSpecPath, apiPluginFilePath, spec, options, authInfo) {
1362
1368
  const manifest = await fs.readJSON(manifestPath);
1363
1369
  const apiPluginRelativePath = ManifestUpdater.getRelativePath(manifestPath, apiPluginFilePath);
1364
- manifest.plugins = [
1365
- {
1366
- file: apiPluginRelativePath,
1367
- id: ConstantString.DefaultPluginId,
1368
- },
1369
- ];
1370
+ // Insert plugins in manifest.json if it is plugin for Copilot.
1371
+ if (!options.isGptPlugin) {
1372
+ manifest.plugins = [
1373
+ {
1374
+ file: apiPluginRelativePath,
1375
+ id: ConstantString.DefaultPluginId,
1376
+ },
1377
+ ];
1378
+ ManifestUpdater.updateManifestDescription(manifest, spec);
1379
+ }
1370
1380
  const appName = this.removeEnvs(manifest.name.short);
1371
- ManifestUpdater.updateManifestDescription(manifest, spec);
1372
1381
  const specRelativePath = ManifestUpdater.getRelativePath(manifestPath, outputSpecPath);
1373
1382
  const apiPlugin = await ManifestUpdater.generatePluginManifestSchema(spec, specRelativePath, apiPluginFilePath, appName, authInfo, options);
1374
1383
  return [manifest, apiPlugin];
@@ -1380,39 +1389,20 @@ class ManifestUpdater {
1380
1389
  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),
1381
1390
  };
1382
1391
  }
1383
- static mapOpenAPISchemaToFuncParam(schema, method, pathUrl) {
1384
- let parameter;
1392
+ static checkSchema(schema, method, pathUrl) {
1385
1393
  if (schema.type === "array") {
1386
1394
  const items = schema.items;
1387
- parameter = {
1388
- type: "array",
1389
- items: ManifestUpdater.mapOpenAPISchemaToFuncParam(items, method, pathUrl),
1390
- };
1395
+ ManifestUpdater.checkSchema(items, method, pathUrl);
1391
1396
  }
1392
- else if (schema.type === "string" ||
1393
- schema.type === "boolean" ||
1394
- schema.type === "integer" ||
1395
- schema.type === "number") {
1396
- parameter = {
1397
- type: schema.type,
1398
- };
1399
- }
1400
- else {
1397
+ else if (schema.type !== "string" &&
1398
+ schema.type !== "boolean" &&
1399
+ schema.type !== "integer" &&
1400
+ schema.type !== "number") {
1401
1401
  throw new SpecParserError(Utils.format(ConstantString.UnsupportedSchema, method, pathUrl, JSON.stringify(schema)), ErrorType.UpdateManifestFailed);
1402
1402
  }
1403
- if (schema.enum) {
1404
- parameter.enum = schema.enum;
1405
- }
1406
- if (schema.description) {
1407
- parameter.description = schema.description;
1408
- }
1409
- if (schema.default) {
1410
- parameter.default = schema.default;
1411
- }
1412
- return parameter;
1413
1403
  }
1414
1404
  static async generatePluginManifestSchema(spec, specRelativePath, apiPluginFilePath, appName, authInfo, options) {
1415
- var _a, _b, _c, _d, _e;
1405
+ var _a, _b, _c, _d;
1416
1406
  const functions = [];
1417
1407
  const functionNames = [];
1418
1408
  const conversationStarters = [];
@@ -1428,7 +1418,8 @@ class ManifestUpdater {
1428
1418
  pluginAuthObj.type = "ApiKeyPluginVault";
1429
1419
  }
1430
1420
  if (pluginAuthObj.type !== "None") {
1431
- pluginAuthObj.reference_id = `${Utils.getSafeRegistrationIdEnvName(authInfo.name)}_REGISTRATION_ID`;
1421
+ const safeRegistrationIdName = Utils.getSafeRegistrationIdEnvName(`${authInfo.name}_${ConstantString.RegistrationIdPostfix[authInfo.authScheme.type]}`);
1422
+ pluginAuthObj.reference_id = `\${{${safeRegistrationIdName}}}`;
1432
1423
  }
1433
1424
  }
1434
1425
  for (const pathUrl in paths) {
@@ -1442,37 +1433,24 @@ class ManifestUpdater {
1442
1433
  if (operationItem) {
1443
1434
  const operationId = operationItem.operationId;
1444
1435
  const description = (_a = operationItem.description) !== null && _a !== void 0 ? _a : "";
1436
+ const summary = operationItem.summary;
1445
1437
  const paramObject = operationItem.parameters;
1446
1438
  const requestBody = operationItem.requestBody;
1447
- const parameters = {
1448
- type: "object",
1449
- properties: {},
1450
- required: [],
1451
- };
1452
1439
  if (paramObject) {
1453
1440
  for (let i = 0; i < paramObject.length; i++) {
1454
1441
  const param = paramObject[i];
1455
1442
  const schema = param.schema;
1456
- parameters.properties[param.name] = ManifestUpdater.mapOpenAPISchemaToFuncParam(schema, method, pathUrl);
1443
+ ManifestUpdater.checkSchema(schema, method, pathUrl);
1457
1444
  confirmationBodies.push(ManifestUpdater.getConfirmationBodyItem(param.name));
1458
- if (param.required) {
1459
- parameters.required.push(param.name);
1460
- }
1461
- if (!parameters.properties[param.name].description) {
1462
- parameters.properties[param.name].description = (_b = param.description) !== null && _b !== void 0 ? _b : "";
1463
- }
1464
1445
  }
1465
1446
  }
1466
1447
  if (requestBody) {
1467
1448
  const requestJsonBody = requestBody.content["application/json"];
1468
1449
  const requestBodySchema = requestJsonBody.schema;
1469
1450
  if (requestBodySchema.type === "object") {
1470
- if (requestBodySchema.required) {
1471
- parameters.required.push(...requestBodySchema.required);
1472
- }
1473
1451
  for (const property in requestBodySchema.properties) {
1474
1452
  const schema = requestBodySchema.properties[property];
1475
- parameters.properties[property] = ManifestUpdater.mapOpenAPISchemaToFuncParam(schema, method, pathUrl);
1453
+ ManifestUpdater.checkSchema(schema, method, pathUrl);
1476
1454
  confirmationBodies.push(ManifestUpdater.getConfirmationBodyItem(property));
1477
1455
  }
1478
1456
  }
@@ -1484,15 +1462,15 @@ class ManifestUpdater {
1484
1462
  name: operationId,
1485
1463
  description: description,
1486
1464
  };
1487
- if (paramObject || requestBody) {
1488
- funcObj.parameters = parameters;
1489
- }
1490
1465
  if (options.allowResponseSemantics) {
1491
- const [card, jsonPath] = AdaptiveCardGenerator.generateAdaptiveCard(operationItem);
1492
- const responseSemantic = wrapResponseSemantics(card, jsonPath);
1493
- funcObj.capabilities = {
1494
- response_semantics: responseSemantic,
1495
- };
1466
+ const { json } = Utils.getResponseJson(operationItem);
1467
+ if (json.schema) {
1468
+ const [card, jsonPath] = AdaptiveCardGenerator.generateAdaptiveCard(operationItem);
1469
+ const responseSemantic = wrapResponseSemantics(card, jsonPath);
1470
+ funcObj.capabilities = {
1471
+ response_semantics: responseSemantic,
1472
+ };
1473
+ }
1496
1474
  }
1497
1475
  if (options.allowConfirmation && method !== ConstantString.GetMethod) {
1498
1476
  if (!funcObj.capabilities) {
@@ -1500,7 +1478,7 @@ class ManifestUpdater {
1500
1478
  }
1501
1479
  funcObj.capabilities.confirmation = {
1502
1480
  type: "AdaptiveCard",
1503
- title: (_c = operationItem.summary) !== null && _c !== void 0 ? _c : description,
1481
+ title: (_b = operationItem.summary) !== null && _b !== void 0 ? _b : description,
1504
1482
  };
1505
1483
  if (confirmationBodies.length > 0) {
1506
1484
  funcObj.capabilities.confirmation.body = confirmationBodies.join("\n");
@@ -1508,8 +1486,9 @@ class ManifestUpdater {
1508
1486
  }
1509
1487
  functions.push(funcObj);
1510
1488
  functionNames.push(operationId);
1511
- if (description) {
1512
- conversationStarters.push(description);
1489
+ const conversationStarterStr = (summary !== null && summary !== void 0 ? summary : description).slice(0, ConstantString.ConversationStarterMaxLens);
1490
+ if (conversationStarterStr) {
1491
+ conversationStarters.push(conversationStarterStr);
1513
1492
  }
1514
1493
  }
1515
1494
  }
@@ -1532,7 +1511,7 @@ class ManifestUpdater {
1532
1511
  }
1533
1512
  apiPlugin.functions = apiPlugin.functions || [];
1534
1513
  for (const func of functions) {
1535
- const index = (_d = apiPlugin.functions) === null || _d === void 0 ? void 0 : _d.findIndex((f) => f.name === func.name);
1514
+ const index = (_c = apiPlugin.functions) === null || _c === void 0 ? void 0 : _c.findIndex((f) => f.name === func.name);
1536
1515
  if (index === -1) {
1537
1516
  apiPlugin.functions.push(func);
1538
1517
  }
@@ -1568,7 +1547,7 @@ class ManifestUpdater {
1568
1547
  }
1569
1548
  if (!apiPlugin.description_for_human) {
1570
1549
  apiPlugin.description_for_human =
1571
- (_e = spec.info.description) !== null && _e !== void 0 ? _e : "<Please add description of the plugin>";
1550
+ (_d = spec.info.description) !== null && _d !== void 0 ? _d : "<Please add description of the plugin>";
1572
1551
  }
1573
1552
  if (options.allowConversationStarters && conversationStarters.length > 0) {
1574
1553
  if (!apiPlugin.capabilities) {
@@ -1601,21 +1580,21 @@ class ManifestUpdater {
1601
1580
  };
1602
1581
  if (authInfo) {
1603
1582
  const auth = authInfo.authScheme;
1583
+ const safeRegistrationIdName = Utils.getSafeRegistrationIdEnvName(`${authInfo.name}_${ConstantString.RegistrationIdPostfix[authInfo.authScheme.type]}`);
1604
1584
  if (Utils.isAPIKeyAuth(auth) || Utils.isBearerTokenAuth(auth)) {
1605
- const safeApiSecretRegistrationId = Utils.getSafeRegistrationIdEnvName(`${authInfo.name}_${ConstantString.RegistrationIdPostfix}`);
1585
+ const safeApiSecretRegistrationId = Utils.getSafeRegistrationIdEnvName(`${authInfo.name}_${ConstantString.RegistrationIdPostfix[authInfo.authScheme.type]}`);
1606
1586
  composeExtension.authorization = {
1607
1587
  authType: "apiSecretServiceAuth",
1608
1588
  apiSecretServiceAuthConfiguration: {
1609
- apiSecretRegistrationId: `\${{${safeApiSecretRegistrationId}}}`,
1589
+ apiSecretRegistrationId: `\${{${safeRegistrationIdName}}}`,
1610
1590
  },
1611
1591
  };
1612
1592
  }
1613
1593
  else if (Utils.isOAuthWithAuthCodeFlow(auth)) {
1614
- const safeOAuth2RegistrationId = Utils.getSafeRegistrationIdEnvName(`${authInfo.name}_${ConstantString.OAuthRegistrationIdPostFix}`);
1615
1594
  composeExtension.authorization = {
1616
1595
  authType: "oAuth2.0",
1617
1596
  oAuthConfiguration: {
1618
- oauthConfigurationId: `\${{${safeOAuth2RegistrationId}}}`,
1597
+ oauthConfigurationId: `\${{${safeRegistrationIdName}}}`,
1619
1598
  },
1620
1599
  };
1621
1600
  updatedPart.webApplicationInfo = {
@@ -1723,6 +1702,7 @@ class SpecParser {
1723
1702
  allowResponseSemantics: false,
1724
1703
  allowConfirmation: false,
1725
1704
  projectType: ProjectType.SME,
1705
+ isGptPlugin: false,
1726
1706
  };
1727
1707
  this.pathOrSpec = pathOrDoc;
1728
1708
  this.parser = new SwaggerParser();