@microsoft/m365-spec-parser 0.1.1-alpha.78701ec6a.0 → 0.1.1-alpha.8d8f5a0bb.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.
@@ -27,6 +27,7 @@ var ErrorType;
27
27
  ErrorType["GenerateAdaptiveCardFailed"] = "generate-adaptive-card-failed";
28
28
  ErrorType["GenerateFailed"] = "generate-failed";
29
29
  ErrorType["ValidateFailed"] = "validate-failed";
30
+ ErrorType["GetSpecFailed"] = "get-spec-failed";
30
31
  ErrorType["Cancelled"] = "cancelled";
31
32
  ErrorType["Unknown"] = "unknown";
32
33
  })(ErrorType || (ErrorType = {}));
@@ -69,6 +70,7 @@ ConstantString.OperationOnlyContainsOptionalParam = "Operation %s contains multi
69
70
  ConstantString.ConvertSwaggerToOpenAPI = "The Swagger 2.0 file has been converted to OpenAPI 3.0.";
70
71
  ConstantString.SwaggerNotSupported = "Swagger 2.0 is not supported. Please convert to OpenAPI 3.0 manually before proceeding.";
71
72
  ConstantString.MultipleAPIKeyNotSupported = "Multiple API keys are not supported. Please make sure that all selected APIs use the same API key.";
73
+ ConstantString.UnsupportedSchema = "Unsupported schema in %s %s: %s";
72
74
  ConstantString.WrappedCardVersion = "devPreview";
73
75
  ConstantString.WrappedCardSchema = "https://developer.microsoft.com/json-schemas/teams/vDevPreview/MicrosoftTeams.ResponseRenderingTemplate.schema.json";
74
76
  ConstantString.WrappedCardResponseLayout = "list";
@@ -151,7 +153,18 @@ class SpecParserError extends Error {
151
153
 
152
154
  // Copyright (c) Microsoft Corporation.
153
155
  class Utils {
154
- static checkParameters(paramObject) {
156
+ static hasNestedObjectInSchema(schema) {
157
+ if (schema.type === "object") {
158
+ for (const property in schema.properties) {
159
+ const nestedSchema = schema.properties[property];
160
+ if (nestedSchema.type === "object") {
161
+ return true;
162
+ }
163
+ }
164
+ }
165
+ return false;
166
+ }
167
+ static checkParameters(paramObject, isCopilot) {
155
168
  const paramResult = {
156
169
  requiredNum: 0,
157
170
  optionalNum: 0,
@@ -163,7 +176,20 @@ class Utils {
163
176
  for (let i = 0; i < paramObject.length; i++) {
164
177
  const param = paramObject[i];
165
178
  const schema = param.schema;
179
+ if (isCopilot && this.hasNestedObjectInSchema(schema)) {
180
+ paramResult.isValid = false;
181
+ continue;
182
+ }
166
183
  const isRequiredWithoutDefault = param.required && schema.default === undefined;
184
+ if (isCopilot) {
185
+ if (isRequiredWithoutDefault) {
186
+ paramResult.requiredNum = paramResult.requiredNum + 1;
187
+ }
188
+ else {
189
+ paramResult.optionalNum = paramResult.optionalNum + 1;
190
+ }
191
+ continue;
192
+ }
167
193
  if (param.in === "header" || param.in === "cookie") {
168
194
  if (isRequiredWithoutDefault) {
169
195
  paramResult.isValid = false;
@@ -190,7 +216,7 @@ class Utils {
190
216
  }
191
217
  return paramResult;
192
218
  }
193
- static checkPostBody(schema, isRequired = false) {
219
+ static checkPostBody(schema, isRequired = false, isCopilot = false) {
194
220
  var _a;
195
221
  const paramResult = {
196
222
  requiredNum: 0,
@@ -201,6 +227,10 @@ class Utils {
201
227
  return paramResult;
202
228
  }
203
229
  const isRequiredWithoutDefault = isRequired && schema.default === undefined;
230
+ if (isCopilot && this.hasNestedObjectInSchema(schema)) {
231
+ paramResult.isValid = false;
232
+ return paramResult;
233
+ }
204
234
  if (schema.type === "string" ||
205
235
  schema.type === "integer" ||
206
236
  schema.type === "boolean" ||
@@ -219,14 +249,14 @@ class Utils {
219
249
  if (schema.required && ((_a = schema.required) === null || _a === void 0 ? void 0 : _a.indexOf(property)) >= 0) {
220
250
  isRequired = true;
221
251
  }
222
- const result = Utils.checkPostBody(properties[property], isRequired);
252
+ const result = Utils.checkPostBody(properties[property], isRequired, isCopilot);
223
253
  paramResult.requiredNum += result.requiredNum;
224
254
  paramResult.optionalNum += result.optionalNum;
225
255
  paramResult.isValid = paramResult.isValid && result.isValid;
226
256
  }
227
257
  }
228
258
  else {
229
- if (isRequiredWithoutDefault) {
259
+ if (isRequiredWithoutDefault && !isCopilot) {
230
260
  paramResult.isValid = false;
231
261
  }
232
262
  }
@@ -246,7 +276,7 @@ class Utils {
246
276
  * 5. response body should be “application/json” and not empty, and response code should be 20X
247
277
  * 6. only support request body with “application/json” content type
248
278
  */
249
- static isSupportedApi(method, path, spec, allowMissingId, allowAPIKeyAuth, allowMultipleParameters, allowOauth2) {
279
+ static isSupportedApi(method, path, spec, allowMissingId, allowAPIKeyAuth, allowMultipleParameters, allowOauth2, isCopilot) {
250
280
  const pathObj = spec.paths[path];
251
281
  method = method.toLocaleLowerCase();
252
282
  if (pathObj) {
@@ -279,15 +309,22 @@ class Utils {
279
309
  };
280
310
  if (requestJsonBody) {
281
311
  const requestBodySchema = requestJsonBody.schema;
282
- requestBodyParamResult = Utils.checkPostBody(requestBodySchema, requestBody.required);
312
+ if (isCopilot && requestBodySchema.type !== "object") {
313
+ return false;
314
+ }
315
+ requestBodyParamResult = Utils.checkPostBody(requestBodySchema, requestBody.required, isCopilot);
283
316
  }
284
317
  if (!requestBodyParamResult.isValid) {
285
318
  return false;
286
319
  }
287
- const paramResult = Utils.checkParameters(paramObject);
320
+ const paramResult = Utils.checkParameters(paramObject, isCopilot);
288
321
  if (!paramResult.isValid) {
289
322
  return false;
290
323
  }
324
+ // Copilot support arbitrary parameters
325
+ if (isCopilot) {
326
+ return true;
327
+ }
291
328
  if (requestBodyParamResult.requiredNum + paramResult.requiredNum > 1) {
292
329
  if (allowMultipleParameters &&
293
330
  requestBodyParamResult.requiredNum + paramResult.requiredNum <= 5) {
@@ -458,7 +495,7 @@ class Utils {
458
495
  }
459
496
  return errors;
460
497
  }
461
- static validateServer(spec, allowMissingId, allowAPIKeyAuth, allowMultipleParameters, allowOauth2) {
498
+ static validateServer(spec, allowMissingId, allowAPIKeyAuth, allowMultipleParameters, allowOauth2, isCopilot) {
462
499
  const errors = [];
463
500
  let hasTopLevelServers = false;
464
501
  let hasPathLevelServers = false;
@@ -479,7 +516,7 @@ class Utils {
479
516
  }
480
517
  for (const method in methods) {
481
518
  const operationObject = methods[method];
482
- if (Utils.isSupportedApi(method, path, spec, allowMissingId, allowAPIKeyAuth, allowMultipleParameters, allowOauth2)) {
519
+ if (Utils.isSupportedApi(method, path, spec, allowMissingId, allowAPIKeyAuth, allowMultipleParameters, allowOauth2, isCopilot)) {
483
520
  if ((operationObject === null || operationObject === void 0 ? void 0 : operationObject.servers) && operationObject.servers.length >= 1) {
484
521
  hasOperationLevelServers = true;
485
522
  const serverErrors = Utils.checkServerUrl(operationObject.servers);
@@ -629,14 +666,14 @@ class Utils {
629
666
  }
630
667
  return [command, warning];
631
668
  }
632
- static listSupportedAPIs(spec, allowMissingId, allowAPIKeyAuth, allowMultipleParameters, allowOauth2) {
669
+ static listSupportedAPIs(spec, allowMissingId, allowAPIKeyAuth, allowMultipleParameters, allowOauth2, isCopilot) {
633
670
  const paths = spec.paths;
634
671
  const result = {};
635
672
  for (const path in paths) {
636
673
  const methods = paths[path];
637
674
  for (const method in methods) {
638
675
  // For developer preview, only support GET operation with only 1 parameter without auth
639
- if (Utils.isSupportedApi(method, path, spec, allowMissingId, allowAPIKeyAuth, allowMultipleParameters, allowOauth2)) {
676
+ if (Utils.isSupportedApi(method, path, spec, allowMissingId, allowAPIKeyAuth, allowMultipleParameters, allowOauth2, isCopilot)) {
640
677
  const operationObject = methods[method];
641
678
  result[`${method.toUpperCase()} ${path}`] = operationObject;
642
679
  }
@@ -644,7 +681,7 @@ class Utils {
644
681
  }
645
682
  return result;
646
683
  }
647
- static validateSpec(spec, parser, isSwaggerFile, allowMissingId, allowAPIKeyAuth, allowMultipleParameters, allowOauth2) {
684
+ static validateSpec(spec, parser, isSwaggerFile, allowMissingId, allowAPIKeyAuth, allowMultipleParameters, allowOauth2, isCopilot) {
648
685
  const errors = [];
649
686
  const warnings = [];
650
687
  if (isSwaggerFile) {
@@ -654,7 +691,7 @@ class Utils {
654
691
  });
655
692
  }
656
693
  // Server validation
657
- const serverErrors = Utils.validateServer(spec, allowMissingId, allowAPIKeyAuth, allowMultipleParameters, allowOauth2);
694
+ const serverErrors = Utils.validateServer(spec, allowMissingId, allowAPIKeyAuth, allowMultipleParameters, allowOauth2, isCopilot);
658
695
  errors.push(...serverErrors);
659
696
  // Remote reference not supported
660
697
  const refPaths = parser.$refs.paths();
@@ -667,7 +704,7 @@ class Utils {
667
704
  });
668
705
  }
669
706
  // No supported API
670
- const apiMap = Utils.listSupportedAPIs(spec, allowMissingId, allowAPIKeyAuth, allowMultipleParameters, allowOauth2);
707
+ const apiMap = Utils.listSupportedAPIs(spec, allowMissingId, allowAPIKeyAuth, allowMultipleParameters, allowOauth2, isCopilot);
671
708
  if (Object.keys(apiMap).length === 0) {
672
709
  errors.push({
673
710
  type: ErrorType.NoSupportedApi,
@@ -723,14 +760,14 @@ class Utils {
723
760
 
724
761
  // Copyright (c) Microsoft Corporation.
725
762
  class SpecFilter {
726
- static specFilter(filter, unResolveSpec, resolvedSpec, allowMissingId, allowAPIKeyAuth, allowMultipleParameters, allowOauth2) {
763
+ static specFilter(filter, unResolveSpec, resolvedSpec, allowMissingId, allowAPIKeyAuth, allowMultipleParameters, allowOauth2, isCopilot) {
727
764
  try {
728
765
  const newSpec = Object.assign({}, unResolveSpec);
729
766
  const newPaths = {};
730
767
  for (const filterItem of filter) {
731
768
  const [method, path] = filterItem.split(" ");
732
769
  const methodName = method.toLowerCase();
733
- if (!Utils.isSupportedApi(methodName, path, resolvedSpec, allowMissingId, allowAPIKeyAuth, allowMultipleParameters, allowOauth2)) {
770
+ if (!Utils.isSupportedApi(methodName, path, resolvedSpec, allowMissingId, allowAPIKeyAuth, allowMultipleParameters, allowOauth2, isCopilot)) {
734
771
  continue;
735
772
  }
736
773
  if (!newPaths[path]) {
@@ -756,8 +793,124 @@ class SpecFilter {
756
793
 
757
794
  // Copyright (c) Microsoft Corporation.
758
795
  class ManifestUpdater {
759
- static async updateManifest(manifestPath, outputSpecPath, adaptiveCardFolder, spec, allowMultipleParameters, auth) {
796
+ static async updateManifestWithAiPlugin(manifestPath, outputSpecPath, apiPluginFilePath, spec) {
797
+ const manifest = await fs.readJSON(manifestPath);
798
+ const apiPluginRelativePath = ManifestUpdater.getRelativePath(manifestPath, apiPluginFilePath);
799
+ manifest.plugins = [
800
+ {
801
+ pluginFile: apiPluginRelativePath,
802
+ },
803
+ ];
804
+ ManifestUpdater.updateManifestDescription(manifest, spec);
805
+ const specRelativePath = ManifestUpdater.getRelativePath(manifestPath, outputSpecPath);
806
+ const apiPlugin = ManifestUpdater.generatePluginManifestSchema(spec, specRelativePath);
807
+ return [manifest, apiPlugin];
808
+ }
809
+ static updateManifestDescription(manifest, spec) {
760
810
  var _a, _b;
811
+ manifest.description = {
812
+ short: spec.info.title.slice(0, ConstantString.ShortDescriptionMaxLens),
813
+ 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),
814
+ };
815
+ }
816
+ static mapOpenAPISchemaToFuncParam(schema, method, pathUrl) {
817
+ let parameter;
818
+ if (schema.type === "string" ||
819
+ schema.type === "boolean" ||
820
+ schema.type === "integer" ||
821
+ schema.type === "number" ||
822
+ schema.type === "array") {
823
+ parameter = schema;
824
+ }
825
+ else {
826
+ throw new SpecParserError(Utils.format(ConstantString.UnsupportedSchema, method, pathUrl, JSON.stringify(schema)), ErrorType.UpdateManifestFailed);
827
+ }
828
+ return parameter;
829
+ }
830
+ static generatePluginManifestSchema(spec, specRelativePath) {
831
+ var _a, _b, _c;
832
+ const functions = [];
833
+ const functionNames = [];
834
+ const paths = spec.paths;
835
+ for (const pathUrl in paths) {
836
+ const pathItem = paths[pathUrl];
837
+ if (pathItem) {
838
+ const operations = pathItem;
839
+ for (const method in operations) {
840
+ if (ConstantString.AllOperationMethods.includes(method)) {
841
+ const operationItem = operations[method];
842
+ if (operationItem) {
843
+ const operationId = operationItem.operationId;
844
+ const description = (_a = operationItem.description) !== null && _a !== void 0 ? _a : "";
845
+ const paramObject = operationItem.parameters;
846
+ const requestBody = operationItem.requestBody;
847
+ const parameters = {
848
+ type: "object",
849
+ properties: {},
850
+ required: [],
851
+ };
852
+ if (paramObject) {
853
+ for (let i = 0; i < paramObject.length; i++) {
854
+ const param = paramObject[i];
855
+ const schema = param.schema;
856
+ parameters.properties[param.name] = ManifestUpdater.mapOpenAPISchemaToFuncParam(schema, method, pathUrl);
857
+ if (param.required) {
858
+ parameters.required.push(param.name);
859
+ }
860
+ if (!parameters.properties[param.name].description) {
861
+ parameters.properties[param.name].description = (_b = param.description) !== null && _b !== void 0 ? _b : "";
862
+ }
863
+ }
864
+ }
865
+ if (requestBody) {
866
+ const requestJsonBody = requestBody.content["application/json"];
867
+ const requestBodySchema = requestJsonBody.schema;
868
+ if (requestBodySchema.type === "object") {
869
+ if (requestBodySchema.required) {
870
+ parameters.required.push(...requestBodySchema.required);
871
+ }
872
+ for (const property in requestBodySchema.properties) {
873
+ const schema = requestBodySchema.properties[property];
874
+ parameters.properties[property] = ManifestUpdater.mapOpenAPISchemaToFuncParam(schema, method, pathUrl);
875
+ }
876
+ }
877
+ else {
878
+ throw new SpecParserError(Utils.format(ConstantString.UnsupportedSchema, method, pathUrl, JSON.stringify(requestBodySchema)), ErrorType.UpdateManifestFailed);
879
+ }
880
+ }
881
+ const funcObj = {
882
+ name: operationId,
883
+ description: description,
884
+ parameters: parameters,
885
+ };
886
+ functions.push(funcObj);
887
+ functionNames.push(operationId);
888
+ }
889
+ }
890
+ }
891
+ }
892
+ }
893
+ const apiPlugin = {
894
+ schema_version: "v2",
895
+ name_for_human: spec.info.title,
896
+ description_for_human: (_c = spec.info.description) !== null && _c !== void 0 ? _c : "<Please add description of the plugin>",
897
+ functions: functions,
898
+ runtimes: [
899
+ {
900
+ type: "OpenApi",
901
+ auth: {
902
+ type: "none", // TODO, support auth in the future
903
+ },
904
+ spec: {
905
+ url: specRelativePath,
906
+ },
907
+ run_for_functions: functionNames,
908
+ },
909
+ ],
910
+ };
911
+ return apiPlugin;
912
+ }
913
+ static async updateManifest(manifestPath, outputSpecPath, adaptiveCardFolder, spec, allowMultipleParameters, auth, isMe) {
761
914
  try {
762
915
  const originalManifest = await fs.readJSON(manifestPath);
763
916
  const updatedPart = {};
@@ -791,11 +944,9 @@ class ManifestUpdater {
791
944
  };
792
945
  }
793
946
  }
794
- updatedPart.description = {
795
- short: spec.info.title.slice(0, ConstantString.ShortDescriptionMaxLens),
796
- full: (_b = ((_a = spec.info.description) !== null && _a !== void 0 ? _a : originalManifest.description.full)) === null || _b === void 0 ? void 0 : _b.slice(0, ConstantString.FullDescriptionMaxLens),
797
- };
798
- updatedPart.composeExtensions = [composeExtension];
947
+ updatedPart.description = originalManifest.description;
948
+ ManifestUpdater.updateManifestDescription(updatedPart, spec);
949
+ updatedPart.composeExtensions = isMe === undefined || isMe === true ? [composeExtension] : [];
799
950
  const updatedManifest = Object.assign(Object.assign({}, originalManifest), updatedPart);
800
951
  return [updatedManifest, warnings];
801
952
  }
@@ -1106,6 +1257,7 @@ class SpecParser {
1106
1257
  allowAPIKeyAuth: false,
1107
1258
  allowMultipleParameters: false,
1108
1259
  allowOauth2: false,
1260
+ isCopilot: false,
1109
1261
  };
1110
1262
  this.pathOrSpec = pathOrDoc;
1111
1263
  this.parser = new SwaggerParser();
@@ -1138,7 +1290,7 @@ class SpecParser {
1138
1290
  ],
1139
1291
  };
1140
1292
  }
1141
- return Utils.validateSpec(this.spec, this.parser, !!this.isSwaggerFile, this.options.allowMissingId, this.options.allowAPIKeyAuth, this.options.allowMultipleParameters, this.options.allowOauth2);
1293
+ return Utils.validateSpec(this.spec, this.parser, !!this.isSwaggerFile, this.options.allowMissingId, this.options.allowAPIKeyAuth, this.options.allowMultipleParameters, this.options.allowOauth2, this.options.isCopilot);
1142
1294
  }
1143
1295
  catch (err) {
1144
1296
  throw new SpecParserError(err.toString(), ErrorType.ValidateFailed);
@@ -1200,31 +1352,89 @@ class SpecParser {
1200
1352
  throw new SpecParserError(err.toString(), ErrorType.ListFailed);
1201
1353
  }
1202
1354
  }
1355
+ /**
1356
+ * Generate specs according to the filters.
1357
+ * @param filter An array of strings that represent the filters to apply when generating the artifacts. If filter is empty, it would process nothing.
1358
+ */
1359
+ async getFilteredSpecs(filter, signal) {
1360
+ try {
1361
+ if (signal === null || signal === void 0 ? void 0 : signal.aborted) {
1362
+ throw new SpecParserError(ConstantString.CancelledMessage, ErrorType.Cancelled);
1363
+ }
1364
+ await this.loadSpec();
1365
+ if (signal === null || signal === void 0 ? void 0 : signal.aborted) {
1366
+ throw new SpecParserError(ConstantString.CancelledMessage, ErrorType.Cancelled);
1367
+ }
1368
+ const newUnResolvedSpec = SpecFilter.specFilter(filter, this.unResolveSpec, this.spec, this.options.allowMissingId, this.options.allowAPIKeyAuth, this.options.allowMultipleParameters, this.options.allowOauth2, this.options.isCopilot);
1369
+ if (signal === null || signal === void 0 ? void 0 : signal.aborted) {
1370
+ throw new SpecParserError(ConstantString.CancelledMessage, ErrorType.Cancelled);
1371
+ }
1372
+ const newSpec = (await this.parser.dereference(newUnResolvedSpec));
1373
+ return [newUnResolvedSpec, newSpec];
1374
+ }
1375
+ catch (err) {
1376
+ if (err instanceof SpecParserError) {
1377
+ throw err;
1378
+ }
1379
+ throw new SpecParserError(err.toString(), ErrorType.GetSpecFailed);
1380
+ }
1381
+ }
1203
1382
  /**
1204
1383
  * Generates and update artifacts from the OpenAPI specification file. Generate Adaptive Cards, update Teams app manifest, and generate a new OpenAPI specification file.
1205
1384
  * @param manifestPath A file path of the Teams app manifest file to update.
1206
1385
  * @param filter An array of strings that represent the filters to apply when generating the artifacts. If filter is empty, it would process nothing.
1207
1386
  * @param outputSpecPath File path of the new OpenAPI specification file to generate. If not specified or empty, no spec file will be generated.
1208
- * @param adaptiveCardFolder Folder path where the Adaptive Card files will be generated. If not specified or empty, Adaptive Card files will not be generated.
1387
+ * @param pluginFilePath File path of the api plugin file to generate.
1209
1388
  */
1210
- async generate(manifestPath, filter, outputSpecPath, adaptiveCardFolder, signal) {
1389
+ async generateForCopilot(manifestPath, filter, outputSpecPath, pluginFilePath, signal) {
1211
1390
  const result = {
1212
1391
  allSuccess: true,
1213
1392
  warnings: [],
1214
1393
  };
1215
1394
  try {
1216
- if (signal === null || signal === void 0 ? void 0 : signal.aborted) {
1217
- throw new SpecParserError(ConstantString.CancelledMessage, ErrorType.Cancelled);
1395
+ const newSpecs = await this.getFilteredSpecs(filter, signal);
1396
+ const newUnResolvedSpec = newSpecs[0];
1397
+ const newSpec = newSpecs[1];
1398
+ let resultStr;
1399
+ if (outputSpecPath.endsWith(".yaml") || outputSpecPath.endsWith(".yml")) {
1400
+ resultStr = jsyaml.dump(newUnResolvedSpec);
1218
1401
  }
1219
- await this.loadSpec();
1220
- if (signal === null || signal === void 0 ? void 0 : signal.aborted) {
1221
- throw new SpecParserError(ConstantString.CancelledMessage, ErrorType.Cancelled);
1402
+ else {
1403
+ resultStr = JSON.stringify(newUnResolvedSpec, null, 2);
1222
1404
  }
1223
- const newUnResolvedSpec = SpecFilter.specFilter(filter, this.unResolveSpec, this.spec, this.options.allowMissingId, this.options.allowAPIKeyAuth, this.options.allowMultipleParameters, this.options.allowOauth2);
1405
+ await fs.outputFile(outputSpecPath, resultStr);
1224
1406
  if (signal === null || signal === void 0 ? void 0 : signal.aborted) {
1225
1407
  throw new SpecParserError(ConstantString.CancelledMessage, ErrorType.Cancelled);
1226
1408
  }
1227
- const newSpec = (await this.parser.dereference(newUnResolvedSpec));
1409
+ const [updatedManifest, apiPlugin] = await ManifestUpdater.updateManifestWithAiPlugin(manifestPath, outputSpecPath, pluginFilePath, newSpec);
1410
+ await fs.outputJSON(manifestPath, updatedManifest, { spaces: 2 });
1411
+ await fs.outputJSON(pluginFilePath, apiPlugin, { spaces: 2 });
1412
+ }
1413
+ catch (err) {
1414
+ if (err instanceof SpecParserError) {
1415
+ throw err;
1416
+ }
1417
+ throw new SpecParserError(err.toString(), ErrorType.GenerateFailed);
1418
+ }
1419
+ return result;
1420
+ }
1421
+ /**
1422
+ * Generates and update artifacts from the OpenAPI specification file. Generate Adaptive Cards, update Teams app manifest, and generate a new OpenAPI specification file.
1423
+ * @param manifestPath A file path of the Teams app manifest file to update.
1424
+ * @param filter An array of strings that represent the filters to apply when generating the artifacts. If filter is empty, it would process nothing.
1425
+ * @param outputSpecPath File path of the new OpenAPI specification file to generate. If not specified or empty, no spec file will be generated.
1426
+ * @param adaptiveCardFolder Folder path where the Adaptive Card files will be generated. If not specified or empty, Adaptive Card files will not be generated.
1427
+ * @param isMe Boolean that indicates whether the project is an Messaging Extension. For Messaging Extension, composeExtensions will be added in Teams app manifest.
1428
+ */
1429
+ async generate(manifestPath, filter, outputSpecPath, adaptiveCardFolder, signal, isMe) {
1430
+ const result = {
1431
+ allSuccess: true,
1432
+ warnings: [],
1433
+ };
1434
+ try {
1435
+ const newSpecs = await this.getFilteredSpecs(filter, signal);
1436
+ const newUnResolvedSpec = newSpecs[0];
1437
+ const newSpec = newSpecs[1];
1228
1438
  const AuthSet = new Set();
1229
1439
  let hasMultipleAPIKeyAuth = false;
1230
1440
  for (const url in newSpec.paths) {
@@ -1251,26 +1461,29 @@ class SpecParser {
1251
1461
  resultStr = JSON.stringify(newUnResolvedSpec, null, 2);
1252
1462
  }
1253
1463
  await fs.outputFile(outputSpecPath, resultStr);
1254
- for (const url in newSpec.paths) {
1255
- for (const method in newSpec.paths[url]) {
1256
- // paths object may contain description/summary, so we need to check if it is a operation object
1257
- if (method === ConstantString.PostMethod || method === ConstantString.GetMethod) {
1258
- const operation = newSpec.paths[url][method];
1259
- try {
1260
- const [card, jsonPath] = AdaptiveCardGenerator.generateAdaptiveCard(operation);
1261
- const fileName = path.join(adaptiveCardFolder, `${operation.operationId}.json`);
1262
- const wrappedCard = wrapAdaptiveCard(card, jsonPath);
1263
- await fs.outputJSON(fileName, wrappedCard, { spaces: 2 });
1264
- const dataFileName = path.join(adaptiveCardFolder, `${operation.operationId}.data.json`);
1265
- await fs.outputJSON(dataFileName, {}, { spaces: 2 });
1266
- }
1267
- catch (err) {
1268
- result.allSuccess = false;
1269
- result.warnings.push({
1270
- type: WarningType.GenerateCardFailed,
1271
- content: err.toString(),
1272
- data: operation.operationId,
1273
- });
1464
+ if (isMe === undefined || isMe === true) {
1465
+ // Only generate adaptive card for Messaging Extension
1466
+ for (const url in newSpec.paths) {
1467
+ for (const method in newSpec.paths[url]) {
1468
+ // paths object may contain description/summary, so we need to check if it is a operation object
1469
+ if (method === ConstantString.PostMethod || method === ConstantString.GetMethod) {
1470
+ const operation = newSpec.paths[url][method];
1471
+ try {
1472
+ const [card, jsonPath] = AdaptiveCardGenerator.generateAdaptiveCard(operation);
1473
+ const fileName = path.join(adaptiveCardFolder, `${operation.operationId}.json`);
1474
+ const wrappedCard = wrapAdaptiveCard(card, jsonPath);
1475
+ await fs.outputJSON(fileName, wrappedCard, { spaces: 2 });
1476
+ const dataFileName = path.join(adaptiveCardFolder, `${operation.operationId}.data.json`);
1477
+ await fs.outputJSON(dataFileName, {}, { spaces: 2 });
1478
+ }
1479
+ catch (err) {
1480
+ result.allSuccess = false;
1481
+ result.warnings.push({
1482
+ type: WarningType.GenerateCardFailed,
1483
+ content: err.toString(),
1484
+ data: operation.operationId,
1485
+ });
1486
+ }
1274
1487
  }
1275
1488
  }
1276
1489
  }
@@ -1279,7 +1492,7 @@ class SpecParser {
1279
1492
  throw new SpecParserError(ConstantString.CancelledMessage, ErrorType.Cancelled);
1280
1493
  }
1281
1494
  const auth = Array.from(AuthSet)[0];
1282
- const [updatedManifest, warnings] = await ManifestUpdater.updateManifest(manifestPath, outputSpecPath, adaptiveCardFolder, newSpec, this.options.allowMultipleParameters, auth);
1495
+ const [updatedManifest, warnings] = await ManifestUpdater.updateManifest(manifestPath, outputSpecPath, adaptiveCardFolder, newSpec, this.options.allowMultipleParameters, auth, isMe);
1283
1496
  await fs.outputJSON(manifestPath, updatedManifest, { spaces: 2 });
1284
1497
  result.warnings.push(...warnings);
1285
1498
  }
@@ -1308,11 +1521,11 @@ class SpecParser {
1308
1521
  if (this.apiMap !== undefined) {
1309
1522
  return this.apiMap;
1310
1523
  }
1311
- const result = Utils.listSupportedAPIs(spec, this.options.allowMissingId, this.options.allowAPIKeyAuth, this.options.allowMultipleParameters, this.options.allowOauth2);
1524
+ const result = Utils.listSupportedAPIs(spec, this.options.allowMissingId, this.options.allowAPIKeyAuth, this.options.allowMultipleParameters, this.options.allowOauth2, this.options.isCopilot);
1312
1525
  this.apiMap = result;
1313
1526
  return result;
1314
1527
  }
1315
1528
  }
1316
1529
 
1317
- export { ConstantString, ErrorType, SpecParser, SpecParserError, Utils, ValidationStatus, WarningType };
1530
+ export { AdaptiveCardGenerator, ConstantString, ErrorType, SpecParser, SpecParserError, Utils, ValidationStatus, WarningType };
1318
1531
  //# sourceMappingURL=index.esm2017.mjs.map