@microsoft/m365-spec-parser 0.1.1-alpha.8d8f5a0bb.0 → 0.1.1-alpha.a372ccf67.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.
@@ -19,7 +19,7 @@ var ErrorType;
19
19
  ErrorType["NoExtraAPICanBeAdded"] = "no-extra-api-can-be-added";
20
20
  ErrorType["ResolveServerUrlFailed"] = "resolve-server-url-failed";
21
21
  ErrorType["SwaggerNotSupported"] = "swagger-not-supported";
22
- ErrorType["MultipleAPIKeyNotSupported"] = "multiple-api-key-not-supported";
22
+ ErrorType["MultipleAuthNotSupported"] = "multiple-auth-not-supported";
23
23
  ErrorType["ListFailed"] = "list-failed";
24
24
  ErrorType["listSupportedAPIInfoFailed"] = "list-supported-api-info-failed";
25
25
  ErrorType["FilterSpecFailed"] = "filter-spec-failed";
@@ -50,7 +50,13 @@ var ValidationStatus;
50
50
  ValidationStatus[ValidationStatus["Valid"] = 0] = "Valid";
51
51
  ValidationStatus[ValidationStatus["Warning"] = 1] = "Warning";
52
52
  ValidationStatus[ValidationStatus["Error"] = 2] = "Error";
53
- })(ValidationStatus || (ValidationStatus = {}));
53
+ })(ValidationStatus || (ValidationStatus = {}));
54
+ var ProjectType;
55
+ (function (ProjectType) {
56
+ ProjectType[ProjectType["Copilot"] = 0] = "Copilot";
57
+ ProjectType[ProjectType["SME"] = 1] = "SME";
58
+ ProjectType[ProjectType["TeamsAi"] = 2] = "TeamsAi";
59
+ })(ProjectType || (ProjectType = {}));
54
60
 
55
61
  // Copyright (c) Microsoft Corporation.
56
62
  class ConstantString {
@@ -69,7 +75,7 @@ ConstantString.ResolveServerUrlFailed = "Unable to resolve the server URL: pleas
69
75
  ConstantString.OperationOnlyContainsOptionalParam = "Operation %s contains multiple optional parameters. The first optional parameter is used for this command.";
70
76
  ConstantString.ConvertSwaggerToOpenAPI = "The Swagger 2.0 file has been converted to OpenAPI 3.0.";
71
77
  ConstantString.SwaggerNotSupported = "Swagger 2.0 is not supported. Please convert to OpenAPI 3.0 manually before proceeding.";
72
- ConstantString.MultipleAPIKeyNotSupported = "Multiple API keys are not supported. Please make sure that all selected APIs use the same API key.";
78
+ ConstantString.MultipleAuthNotSupported = "Multiple authentication methods are unsupported. Ensure all selected APIs use identical authentication.";
73
79
  ConstantString.UnsupportedSchema = "Unsupported schema in %s %s: %s";
74
80
  ConstantString.WrappedCardVersion = "devPreview";
75
81
  ConstantString.WrappedCardSchema = "https://developer.microsoft.com/json-schemas/teams/vDevPreview/MicrosoftTeams.ResponseRenderingTemplate.schema.json";
@@ -82,6 +88,7 @@ ConstantString.AdaptiveCardType = "AdaptiveCard";
82
88
  ConstantString.TextBlockType = "TextBlock";
83
89
  ConstantString.ContainerType = "Container";
84
90
  ConstantString.RegistrationIdPostfix = "REGISTRATION_ID";
91
+ ConstantString.OAuthRegistrationIdPostFix = "OAUTH_REGISTRATION_ID";
85
92
  ConstantString.ResponseCodeFor20X = [
86
93
  "200",
87
94
  "201",
@@ -141,7 +148,8 @@ ConstantString.FullDescriptionMaxLens = 4000;
141
148
  ConstantString.CommandDescriptionMaxLens = 128;
142
149
  ConstantString.ParameterDescriptionMaxLens = 128;
143
150
  ConstantString.CommandTitleMaxLens = 32;
144
- ConstantString.ParameterTitleMaxLens = 32;
151
+ ConstantString.ParameterTitleMaxLens = 32;
152
+ ConstantString.SMERequiredParamsMaxNum = 5;
145
153
 
146
154
  // Copyright (c) Microsoft Corporation.
147
155
  class SpecParserError extends Error {
@@ -262,6 +270,9 @@ class Utils {
262
270
  }
263
271
  return paramResult;
264
272
  }
273
+ static containMultipleMediaTypes(bodyObject) {
274
+ return Object.keys((bodyObject === null || bodyObject === void 0 ? void 0 : bodyObject.content) || {}).length > 1;
275
+ }
265
276
  /**
266
277
  * Checks if the given API is supported.
267
278
  * @param {string} method - The HTTP method of the API.
@@ -276,32 +287,40 @@ class Utils {
276
287
  * 5. response body should be “application/json” and not empty, and response code should be 20X
277
288
  * 6. only support request body with “application/json” content type
278
289
  */
279
- static isSupportedApi(method, path, spec, allowMissingId, allowAPIKeyAuth, allowMultipleParameters, allowOauth2, isCopilot) {
290
+ static isSupportedApi(method, path, spec, options) {
291
+ var _a;
280
292
  const pathObj = spec.paths[path];
281
293
  method = method.toLocaleLowerCase();
282
294
  if (pathObj) {
283
- if ((method === ConstantString.PostMethod || method === ConstantString.GetMethod) &&
284
- pathObj[method]) {
295
+ if (((_a = options.allowMethods) === null || _a === void 0 ? void 0 : _a.includes(method)) && pathObj[method]) {
285
296
  const securities = pathObj[method].security;
286
- const authArray = Utils.getAuthArray(securities, spec);
287
- if (!Utils.isSupportedAuth(authArray, allowAPIKeyAuth, allowOauth2)) {
288
- return false;
297
+ const isTeamsAi = options.projectType === ProjectType.TeamsAi;
298
+ const isCopilot = options.projectType === ProjectType.Copilot;
299
+ // Teams AI project doesn't care about auth, it will use authProvider for user to implement
300
+ if (!isTeamsAi) {
301
+ const authArray = Utils.getAuthArray(securities, spec);
302
+ if (!Utils.isSupportedAuth(authArray, options)) {
303
+ return false;
304
+ }
289
305
  }
290
306
  const operationObject = pathObj[method];
291
- if (!allowMissingId && !operationObject.operationId) {
307
+ if (!options.allowMissingId && !operationObject.operationId) {
292
308
  return false;
293
309
  }
294
310
  const paramObject = operationObject.parameters;
295
311
  const requestBody = operationObject.requestBody;
296
312
  const requestJsonBody = requestBody === null || requestBody === void 0 ? void 0 : requestBody.content["application/json"];
297
- const mediaTypesCount = Object.keys((requestBody === null || requestBody === void 0 ? void 0 : requestBody.content) || {}).length;
298
- if (mediaTypesCount > 1) {
313
+ if (!isTeamsAi && Utils.containMultipleMediaTypes(requestBody)) {
299
314
  return false;
300
315
  }
301
- const responseJson = Utils.getResponseJson(operationObject);
316
+ const responseJson = Utils.getResponseJson(operationObject, isTeamsAi);
302
317
  if (Object.keys(responseJson).length === 0) {
303
318
  return false;
304
319
  }
320
+ // Teams AI project doesn't care about request parameters/body
321
+ if (isTeamsAi) {
322
+ return true;
323
+ }
305
324
  let requestBodyParamResult = {
306
325
  requiredNum: 0,
307
326
  optionalNum: 0,
@@ -326,8 +345,9 @@ class Utils {
326
345
  return true;
327
346
  }
328
347
  if (requestBodyParamResult.requiredNum + paramResult.requiredNum > 1) {
329
- if (allowMultipleParameters &&
330
- requestBodyParamResult.requiredNum + paramResult.requiredNum <= 5) {
348
+ if (options.allowMultipleParameters &&
349
+ requestBodyParamResult.requiredNum + paramResult.requiredNum <=
350
+ ConstantString.SMERequiredParamsMaxNum) {
331
351
  return true;
332
352
  }
333
353
  return false;
@@ -346,29 +366,31 @@ class Utils {
346
366
  }
347
367
  return false;
348
368
  }
349
- static isSupportedAuth(authSchemaArray, allowAPIKeyAuth, allowOauth2) {
369
+ static isSupportedAuth(authSchemaArray, options) {
350
370
  if (authSchemaArray.length === 0) {
351
371
  return true;
352
372
  }
353
- if (allowAPIKeyAuth || allowOauth2) {
373
+ if (options.allowAPIKeyAuth || options.allowOauth2) {
354
374
  // Currently we don't support multiple auth in one operation
355
375
  if (authSchemaArray.length > 0 && authSchemaArray.every((auths) => auths.length > 1)) {
356
376
  return false;
357
377
  }
358
378
  for (const auths of authSchemaArray) {
359
379
  if (auths.length === 1) {
360
- if (!allowOauth2 && allowAPIKeyAuth && Utils.isAPIKeyAuth(auths[0].authSchema)) {
380
+ if (!options.allowOauth2 &&
381
+ options.allowAPIKeyAuth &&
382
+ Utils.isAPIKeyAuth(auths[0].authSchema)) {
361
383
  return true;
362
384
  }
363
- else if (!allowAPIKeyAuth &&
364
- allowOauth2 &&
365
- Utils.isBearerTokenAuth(auths[0].authSchema)) {
385
+ else if (!options.allowAPIKeyAuth &&
386
+ options.allowOauth2 &&
387
+ Utils.isOAuthWithAuthCodeFlow(auths[0].authSchema)) {
366
388
  return true;
367
389
  }
368
- else if (allowAPIKeyAuth &&
369
- allowOauth2 &&
390
+ else if (options.allowAPIKeyAuth &&
391
+ options.allowOauth2 &&
370
392
  (Utils.isAPIKeyAuth(auths[0].authSchema) ||
371
- Utils.isBearerTokenAuth(auths[0].authSchema))) {
393
+ Utils.isOAuthWithAuthCodeFlow(auths[0].authSchema))) {
372
394
  return true;
373
395
  }
374
396
  }
@@ -379,10 +401,11 @@ class Utils {
379
401
  static isAPIKeyAuth(authSchema) {
380
402
  return authSchema.type === "apiKey";
381
403
  }
382
- static isBearerTokenAuth(authSchema) {
383
- return (authSchema.type === "oauth2" ||
384
- authSchema.type === "openIdConnect" ||
385
- (authSchema.type === "http" && authSchema.scheme === "bearer"));
404
+ static isOAuthWithAuthCodeFlow(authSchema) {
405
+ if (authSchema.type === "oauth2" && authSchema.flows && authSchema.flows.authorizationCode) {
406
+ return true;
407
+ }
408
+ return false;
386
409
  }
387
410
  static getAuthArray(securities, spec) {
388
411
  var _a;
@@ -410,18 +433,19 @@ class Utils {
410
433
  static updateFirstLetter(str) {
411
434
  return str.charAt(0).toUpperCase() + str.slice(1);
412
435
  }
413
- static getResponseJson(operationObject) {
436
+ static getResponseJson(operationObject, isTeamsAiProject = false) {
414
437
  var _a, _b;
415
438
  let json = {};
416
439
  for (const code of ConstantString.ResponseCodeFor20X) {
417
440
  const responseObject = (_a = operationObject === null || operationObject === void 0 ? void 0 : operationObject.responses) === null || _a === void 0 ? void 0 : _a[code];
418
- const mediaTypesCount = Object.keys((responseObject === null || responseObject === void 0 ? void 0 : responseObject.content) || {}).length;
419
- if (mediaTypesCount > 1) {
420
- return {};
421
- }
422
441
  if ((_b = responseObject === null || responseObject === void 0 ? void 0 : responseObject.content) === null || _b === void 0 ? void 0 : _b["application/json"]) {
423
442
  json = responseObject.content["application/json"];
424
- break;
443
+ if (!isTeamsAiProject && Utils.containMultipleMediaTypes(responseObject)) {
444
+ json = {};
445
+ }
446
+ else {
447
+ break;
448
+ }
425
449
  }
426
450
  }
427
451
  return json;
@@ -495,7 +519,7 @@ class Utils {
495
519
  }
496
520
  return errors;
497
521
  }
498
- static validateServer(spec, allowMissingId, allowAPIKeyAuth, allowMultipleParameters, allowOauth2, isCopilot) {
522
+ static validateServer(spec, options) {
499
523
  const errors = [];
500
524
  let hasTopLevelServers = false;
501
525
  let hasPathLevelServers = false;
@@ -516,7 +540,7 @@ class Utils {
516
540
  }
517
541
  for (const method in methods) {
518
542
  const operationObject = methods[method];
519
- if (Utils.isSupportedApi(method, path, spec, allowMissingId, allowAPIKeyAuth, allowMultipleParameters, allowOauth2, isCopilot)) {
543
+ if (Utils.isSupportedApi(method, path, spec, options)) {
520
544
  if ((operationObject === null || operationObject === void 0 ? void 0 : operationObject.servers) && operationObject.servers.length >= 1) {
521
545
  hasOperationLevelServers = true;
522
546
  const serverErrors = Utils.checkServerUrl(operationObject.servers);
@@ -603,7 +627,7 @@ class Utils {
603
627
  param.value = schema.default;
604
628
  }
605
629
  }
606
- static parseApiInfo(operationItem, allowMultipleParameters) {
630
+ static parseApiInfo(operationItem, options) {
607
631
  var _a, _b;
608
632
  const requiredParams = [];
609
633
  const optionalParams = [];
@@ -617,7 +641,7 @@ class Utils {
617
641
  description: ((_a = param.description) !== null && _a !== void 0 ? _a : "").slice(0, ConstantString.ParameterDescriptionMaxLens),
618
642
  };
619
643
  const schema = param.schema;
620
- if (allowMultipleParameters && schema) {
644
+ if (options.allowMultipleParameters && schema) {
621
645
  Utils.updateParameterWithInputType(schema, parameter);
622
646
  }
623
647
  if (param.in !== "header" && param.in !== "cookie") {
@@ -635,7 +659,7 @@ class Utils {
635
659
  const requestJson = requestBody.content["application/json"];
636
660
  if (Object.keys(requestJson).length !== 0) {
637
661
  const schema = requestJson.schema;
638
- const [requiredP, optionalP] = Utils.generateParametersFromSchema(schema, "requestBody", allowMultipleParameters, requestBody.required);
662
+ const [requiredP, optionalP] = Utils.generateParametersFromSchema(schema, "requestBody", !!options.allowMultipleParameters, requestBody.required);
639
663
  requiredParams.push(...requiredP);
640
664
  optionalParams.push(...optionalP);
641
665
  }
@@ -666,14 +690,13 @@ class Utils {
666
690
  }
667
691
  return [command, warning];
668
692
  }
669
- static listSupportedAPIs(spec, allowMissingId, allowAPIKeyAuth, allowMultipleParameters, allowOauth2, isCopilot) {
693
+ static listSupportedAPIs(spec, options) {
670
694
  const paths = spec.paths;
671
695
  const result = {};
672
696
  for (const path in paths) {
673
697
  const methods = paths[path];
674
698
  for (const method in methods) {
675
- // For developer preview, only support GET operation with only 1 parameter without auth
676
- if (Utils.isSupportedApi(method, path, spec, allowMissingId, allowAPIKeyAuth, allowMultipleParameters, allowOauth2, isCopilot)) {
699
+ if (Utils.isSupportedApi(method, path, spec, options)) {
677
700
  const operationObject = methods[method];
678
701
  result[`${method.toUpperCase()} ${path}`] = operationObject;
679
702
  }
@@ -681,7 +704,7 @@ class Utils {
681
704
  }
682
705
  return result;
683
706
  }
684
- static validateSpec(spec, parser, isSwaggerFile, allowMissingId, allowAPIKeyAuth, allowMultipleParameters, allowOauth2, isCopilot) {
707
+ static validateSpec(spec, parser, isSwaggerFile, options) {
685
708
  const errors = [];
686
709
  const warnings = [];
687
710
  if (isSwaggerFile) {
@@ -691,7 +714,7 @@ class Utils {
691
714
  });
692
715
  }
693
716
  // Server validation
694
- const serverErrors = Utils.validateServer(spec, allowMissingId, allowAPIKeyAuth, allowMultipleParameters, allowOauth2, isCopilot);
717
+ const serverErrors = Utils.validateServer(spec, options);
695
718
  errors.push(...serverErrors);
696
719
  // Remote reference not supported
697
720
  const refPaths = parser.$refs.paths();
@@ -704,7 +727,7 @@ class Utils {
704
727
  });
705
728
  }
706
729
  // No supported API
707
- const apiMap = Utils.listSupportedAPIs(spec, allowMissingId, allowAPIKeyAuth, allowMultipleParameters, allowOauth2, isCopilot);
730
+ const apiMap = Utils.listSupportedAPIs(spec, options);
708
731
  if (Object.keys(apiMap).length === 0) {
709
732
  errors.push({
710
733
  type: ErrorType.NoSupportedApi,
@@ -760,14 +783,14 @@ class Utils {
760
783
 
761
784
  // Copyright (c) Microsoft Corporation.
762
785
  class SpecFilter {
763
- static specFilter(filter, unResolveSpec, resolvedSpec, allowMissingId, allowAPIKeyAuth, allowMultipleParameters, allowOauth2, isCopilot) {
786
+ static specFilter(filter, unResolveSpec, resolvedSpec, options) {
764
787
  try {
765
788
  const newSpec = Object.assign({}, unResolveSpec);
766
789
  const newPaths = {};
767
790
  for (const filterItem of filter) {
768
791
  const [method, path] = filterItem.split(" ");
769
792
  const methodName = method.toLowerCase();
770
- if (!Utils.isSupportedApi(methodName, path, resolvedSpec, allowMissingId, allowAPIKeyAuth, allowMultipleParameters, allowOauth2, isCopilot)) {
793
+ if (!Utils.isSupportedApi(methodName, path, resolvedSpec, options)) {
771
794
  continue;
772
795
  }
773
796
  if (!newPaths[path]) {
@@ -793,7 +816,7 @@ class SpecFilter {
793
816
 
794
817
  // Copyright (c) Microsoft Corporation.
795
818
  class ManifestUpdater {
796
- static async updateManifestWithAiPlugin(manifestPath, outputSpecPath, apiPluginFilePath, spec) {
819
+ static async updateManifestWithAiPlugin(manifestPath, outputSpecPath, apiPluginFilePath, spec, options) {
797
820
  const manifest = await fs.readJSON(manifestPath);
798
821
  const apiPluginRelativePath = ManifestUpdater.getRelativePath(manifestPath, apiPluginFilePath);
799
822
  manifest.plugins = [
@@ -803,7 +826,7 @@ class ManifestUpdater {
803
826
  ];
804
827
  ManifestUpdater.updateManifestDescription(manifest, spec);
805
828
  const specRelativePath = ManifestUpdater.getRelativePath(manifestPath, outputSpecPath);
806
- const apiPlugin = ManifestUpdater.generatePluginManifestSchema(spec, specRelativePath);
829
+ const apiPlugin = ManifestUpdater.generatePluginManifestSchema(spec, specRelativePath, options);
807
830
  return [manifest, apiPlugin];
808
831
  }
809
832
  static updateManifestDescription(manifest, spec) {
@@ -827,7 +850,7 @@ class ManifestUpdater {
827
850
  }
828
851
  return parameter;
829
852
  }
830
- static generatePluginManifestSchema(spec, specRelativePath) {
853
+ static generatePluginManifestSchema(spec, specRelativePath, options) {
831
854
  var _a, _b, _c;
832
855
  const functions = [];
833
856
  const functionNames = [];
@@ -837,7 +860,7 @@ class ManifestUpdater {
837
860
  if (pathItem) {
838
861
  const operations = pathItem;
839
862
  for (const method in operations) {
840
- if (ConstantString.AllOperationMethods.includes(method)) {
863
+ if (options.allowMethods.includes(method)) {
841
864
  const operationItem = operations[method];
842
865
  if (operationItem) {
843
866
  const operationId = operationItem.operationId;
@@ -910,43 +933,51 @@ class ManifestUpdater {
910
933
  };
911
934
  return apiPlugin;
912
935
  }
913
- static async updateManifest(manifestPath, outputSpecPath, adaptiveCardFolder, spec, allowMultipleParameters, auth, isMe) {
936
+ static async updateManifest(manifestPath, outputSpecPath, spec, options, adaptiveCardFolder, authInfo) {
914
937
  try {
915
938
  const originalManifest = await fs.readJSON(manifestPath);
916
939
  const updatedPart = {};
917
- const [commands, warnings] = await ManifestUpdater.generateCommands(spec, adaptiveCardFolder, manifestPath, allowMultipleParameters);
918
- const composeExtension = {
919
- composeExtensionType: "apiBased",
920
- apiSpecificationFile: ManifestUpdater.getRelativePath(manifestPath, outputSpecPath),
921
- commands: commands,
922
- };
923
- if (auth) {
924
- if (Utils.isAPIKeyAuth(auth)) {
925
- auth = auth;
926
- const safeApiSecretRegistrationId = Utils.getSafeRegistrationIdEnvName(`${auth.name}_${ConstantString.RegistrationIdPostfix}`);
927
- composeExtension.authorization = {
928
- authType: "apiSecretServiceAuth",
929
- apiSecretServiceAuthConfiguration: {
930
- apiSecretRegistrationId: `\${{${safeApiSecretRegistrationId}}}`,
931
- },
932
- };
933
- }
934
- else if (Utils.isBearerTokenAuth(auth)) {
935
- composeExtension.authorization = {
936
- authType: "microsoftEntra",
937
- microsoftEntraConfiguration: {
938
- supportsSingleSignOn: true,
939
- },
940
- };
941
- updatedPart.webApplicationInfo = {
942
- id: "${{AAD_APP_CLIENT_ID}}",
943
- resource: "api://${{DOMAIN}}/${{AAD_APP_CLIENT_ID}}",
944
- };
940
+ updatedPart.composeExtensions = [];
941
+ let warnings = [];
942
+ if (options.projectType === ProjectType.SME) {
943
+ const updateResult = await ManifestUpdater.generateCommands(spec, manifestPath, options, adaptiveCardFolder);
944
+ const commands = updateResult[0];
945
+ warnings = updateResult[1];
946
+ const composeExtension = {
947
+ composeExtensionType: "apiBased",
948
+ apiSpecificationFile: ManifestUpdater.getRelativePath(manifestPath, outputSpecPath),
949
+ commands: commands,
950
+ };
951
+ if (authInfo) {
952
+ let auth = authInfo.authSchema;
953
+ if (Utils.isAPIKeyAuth(auth)) {
954
+ auth = auth;
955
+ const safeApiSecretRegistrationId = Utils.getSafeRegistrationIdEnvName(`${authInfo.name}_${ConstantString.RegistrationIdPostfix}`);
956
+ composeExtension.authorization = {
957
+ authType: "apiSecretServiceAuth",
958
+ apiSecretServiceAuthConfiguration: {
959
+ apiSecretRegistrationId: `\${{${safeApiSecretRegistrationId}}}`,
960
+ },
961
+ };
962
+ }
963
+ else if (Utils.isOAuthWithAuthCodeFlow(auth)) {
964
+ const safeOAuth2RegistrationId = Utils.getSafeRegistrationIdEnvName(`${authInfo.name}_${ConstantString.OAuthRegistrationIdPostFix}`);
965
+ composeExtension.authorization = {
966
+ authType: "oAuth2.0",
967
+ oAuthConfiguration: {
968
+ oauthConfigurationId: `\${{${safeOAuth2RegistrationId}}}`,
969
+ },
970
+ };
971
+ updatedPart.webApplicationInfo = {
972
+ id: "${{AAD_APP_CLIENT_ID}}",
973
+ resource: "api://${{DOMAIN}}/${{AAD_APP_CLIENT_ID}}",
974
+ };
975
+ }
945
976
  }
977
+ updatedPart.composeExtensions = [composeExtension];
946
978
  }
947
979
  updatedPart.description = originalManifest.description;
948
980
  ManifestUpdater.updateManifestDescription(updatedPart, spec);
949
- updatedPart.composeExtensions = isMe === undefined || isMe === true ? [composeExtension] : [];
950
981
  const updatedManifest = Object.assign(Object.assign({}, originalManifest), updatedPart);
951
982
  return [updatedManifest, warnings];
952
983
  }
@@ -954,7 +985,8 @@ class ManifestUpdater {
954
985
  throw new SpecParserError(err.toString(), ErrorType.UpdateManifestFailed);
955
986
  }
956
987
  }
957
- static async generateCommands(spec, adaptiveCardFolder, manifestPath, allowMultipleParameters) {
988
+ static async generateCommands(spec, manifestPath, options, adaptiveCardFolder) {
989
+ var _a;
958
990
  const paths = spec.paths;
959
991
  const commands = [];
960
992
  const warnings = [];
@@ -965,14 +997,16 @@ class ManifestUpdater {
965
997
  const operations = pathItem;
966
998
  // Currently only support GET and POST method
967
999
  for (const method in operations) {
968
- if (method === ConstantString.PostMethod || method === ConstantString.GetMethod) {
1000
+ if ((_a = options.allowMethods) === null || _a === void 0 ? void 0 : _a.includes(method)) {
969
1001
  const operationItem = operations[method];
970
1002
  if (operationItem) {
971
- const [command, warning] = Utils.parseApiInfo(operationItem, allowMultipleParameters);
972
- const adaptiveCardPath = path.join(adaptiveCardFolder, command.id + ".json");
973
- command.apiResponseRenderingTemplateFile = (await fs.pathExists(adaptiveCardPath))
974
- ? ManifestUpdater.getRelativePath(manifestPath, adaptiveCardPath)
975
- : "";
1003
+ const [command, warning] = Utils.parseApiInfo(operationItem, options);
1004
+ if (adaptiveCardFolder) {
1005
+ const adaptiveCardPath = path.join(adaptiveCardFolder, command.id + ".json");
1006
+ command.apiResponseRenderingTemplateFile = (await fs.pathExists(adaptiveCardPath))
1007
+ ? ManifestUpdater.getRelativePath(manifestPath, adaptiveCardPath)
1008
+ : "";
1009
+ }
976
1010
  if (warning) {
977
1011
  warnings.push(warning);
978
1012
  }
@@ -1257,7 +1291,8 @@ class SpecParser {
1257
1291
  allowAPIKeyAuth: false,
1258
1292
  allowMultipleParameters: false,
1259
1293
  allowOauth2: false,
1260
- isCopilot: false,
1294
+ allowMethods: ["get", "post"],
1295
+ projectType: ProjectType.SME,
1261
1296
  };
1262
1297
  this.pathOrSpec = pathOrDoc;
1263
1298
  this.parser = new SwaggerParser();
@@ -1290,7 +1325,7 @@ class SpecParser {
1290
1325
  ],
1291
1326
  };
1292
1327
  }
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);
1328
+ return Utils.validateSpec(this.spec, this.parser, !!this.isSwaggerFile, this.options);
1294
1329
  }
1295
1330
  catch (err) {
1296
1331
  throw new SpecParserError(err.toString(), ErrorType.ValidateFailed);
@@ -1365,7 +1400,7 @@ class SpecParser {
1365
1400
  if (signal === null || signal === void 0 ? void 0 : signal.aborted) {
1366
1401
  throw new SpecParserError(ConstantString.CancelledMessage, ErrorType.Cancelled);
1367
1402
  }
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);
1403
+ const newUnResolvedSpec = SpecFilter.specFilter(filter, this.unResolveSpec, this.spec, this.options);
1369
1404
  if (signal === null || signal === void 0 ? void 0 : signal.aborted) {
1370
1405
  throw new SpecParserError(ConstantString.CancelledMessage, ErrorType.Cancelled);
1371
1406
  }
@@ -1406,7 +1441,7 @@ class SpecParser {
1406
1441
  if (signal === null || signal === void 0 ? void 0 : signal.aborted) {
1407
1442
  throw new SpecParserError(ConstantString.CancelledMessage, ErrorType.Cancelled);
1408
1443
  }
1409
- const [updatedManifest, apiPlugin] = await ManifestUpdater.updateManifestWithAiPlugin(manifestPath, outputSpecPath, pluginFilePath, newSpec);
1444
+ const [updatedManifest, apiPlugin] = await ManifestUpdater.updateManifestWithAiPlugin(manifestPath, outputSpecPath, pluginFilePath, newSpec, this.options);
1410
1445
  await fs.outputJSON(manifestPath, updatedManifest, { spaces: 2 });
1411
1446
  await fs.outputJSON(pluginFilePath, apiPlugin, { spaces: 2 });
1412
1447
  }
@@ -1424,9 +1459,8 @@ class SpecParser {
1424
1459
  * @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
1460
  * @param outputSpecPath File path of the new OpenAPI specification file to generate. If not specified or empty, no spec file will be generated.
1426
1461
  * @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
1462
  */
1429
- async generate(manifestPath, filter, outputSpecPath, adaptiveCardFolder, signal, isMe) {
1463
+ async generate(manifestPath, filter, outputSpecPath, adaptiveCardFolder, signal) {
1430
1464
  const result = {
1431
1465
  allSuccess: true,
1432
1466
  warnings: [],
@@ -1435,23 +1469,23 @@ class SpecParser {
1435
1469
  const newSpecs = await this.getFilteredSpecs(filter, signal);
1436
1470
  const newUnResolvedSpec = newSpecs[0];
1437
1471
  const newSpec = newSpecs[1];
1438
- const AuthSet = new Set();
1439
- let hasMultipleAPIKeyAuth = false;
1472
+ const authSet = new Set();
1473
+ let hasMultipleAuth = false;
1440
1474
  for (const url in newSpec.paths) {
1441
1475
  for (const method in newSpec.paths[url]) {
1442
1476
  const operation = newSpec.paths[url][method];
1443
1477
  const authArray = Utils.getAuthArray(operation.security, newSpec);
1444
1478
  if (authArray && authArray.length > 0) {
1445
- AuthSet.add(authArray[0][0].authSchema);
1446
- if (AuthSet.size > 1) {
1447
- hasMultipleAPIKeyAuth = true;
1479
+ authSet.add(authArray[0][0]);
1480
+ if (authSet.size > 1) {
1481
+ hasMultipleAuth = true;
1448
1482
  break;
1449
1483
  }
1450
1484
  }
1451
1485
  }
1452
1486
  }
1453
- if (hasMultipleAPIKeyAuth) {
1454
- throw new SpecParserError(ConstantString.MultipleAPIKeyNotSupported, ErrorType.MultipleAPIKeyNotSupported);
1487
+ if (hasMultipleAuth && this.options.projectType !== ProjectType.TeamsAi) {
1488
+ throw new SpecParserError(ConstantString.MultipleAuthNotSupported, ErrorType.MultipleAuthNotSupported);
1455
1489
  }
1456
1490
  let resultStr;
1457
1491
  if (outputSpecPath.endsWith(".yaml") || outputSpecPath.endsWith(".yml")) {
@@ -1461,12 +1495,11 @@ class SpecParser {
1461
1495
  resultStr = JSON.stringify(newUnResolvedSpec, null, 2);
1462
1496
  }
1463
1497
  await fs.outputFile(outputSpecPath, resultStr);
1464
- if (isMe === undefined || isMe === true) {
1465
- // Only generate adaptive card for Messaging Extension
1498
+ if (adaptiveCardFolder) {
1466
1499
  for (const url in newSpec.paths) {
1467
1500
  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) {
1501
+ // paths object may contain description/summary which is not a http method, so we need to check if it is a operation object
1502
+ if (this.options.allowMethods.includes(method)) {
1470
1503
  const operation = newSpec.paths[url][method];
1471
1504
  try {
1472
1505
  const [card, jsonPath] = AdaptiveCardGenerator.generateAdaptiveCard(operation);
@@ -1491,8 +1524,8 @@ class SpecParser {
1491
1524
  if (signal === null || signal === void 0 ? void 0 : signal.aborted) {
1492
1525
  throw new SpecParserError(ConstantString.CancelledMessage, ErrorType.Cancelled);
1493
1526
  }
1494
- const auth = Array.from(AuthSet)[0];
1495
- const [updatedManifest, warnings] = await ManifestUpdater.updateManifest(manifestPath, outputSpecPath, adaptiveCardFolder, newSpec, this.options.allowMultipleParameters, auth, isMe);
1527
+ const authInfo = Array.from(authSet)[0];
1528
+ const [updatedManifest, warnings] = await ManifestUpdater.updateManifest(manifestPath, outputSpecPath, newSpec, this.options, adaptiveCardFolder, authInfo);
1496
1529
  await fs.outputJSON(manifestPath, updatedManifest, { spaces: 2 });
1497
1530
  result.warnings.push(...warnings);
1498
1531
  }
@@ -1521,11 +1554,11 @@ class SpecParser {
1521
1554
  if (this.apiMap !== undefined) {
1522
1555
  return this.apiMap;
1523
1556
  }
1524
- const result = Utils.listSupportedAPIs(spec, this.options.allowMissingId, this.options.allowAPIKeyAuth, this.options.allowMultipleParameters, this.options.allowOauth2, this.options.isCopilot);
1557
+ const result = Utils.listSupportedAPIs(spec, this.options);
1525
1558
  this.apiMap = result;
1526
1559
  return result;
1527
1560
  }
1528
1561
  }
1529
1562
 
1530
- export { AdaptiveCardGenerator, ConstantString, ErrorType, SpecParser, SpecParserError, Utils, ValidationStatus, WarningType };
1563
+ export { AdaptiveCardGenerator, ConstantString, ErrorType, ProjectType, SpecParser, SpecParserError, Utils, ValidationStatus, WarningType };
1531
1564
  //# sourceMappingURL=index.esm2017.mjs.map