@microsoft/m365-spec-parser 0.2.1 → 0.2.2-alpha.089f82c02.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.
@@ -43,10 +43,12 @@ var ErrorType;
43
43
  ErrorType["RelativeServerUrlNotSupported"] = "relative-server-url-not-supported";
44
44
  ErrorType["NoSupportedApi"] = "no-supported-api";
45
45
  ErrorType["NoExtraAPICanBeAdded"] = "no-extra-api-can-be-added";
46
+ ErrorType["AddedAPINotInOriginalSpec"] = "added-api-not-in-original-spec";
46
47
  ErrorType["ResolveServerUrlFailed"] = "resolve-server-url-failed";
47
48
  ErrorType["SwaggerNotSupported"] = "swagger-not-supported";
48
49
  ErrorType["MultipleAuthNotSupported"] = "multiple-auth-not-supported";
49
50
  ErrorType["SpecVersionNotSupported"] = "spec-version-not-supported";
51
+ ErrorType["CircularReferenceNotSupported"] = "circular-reference-not-supported";
50
52
  ErrorType["ListFailed"] = "list-failed";
51
53
  ErrorType["listSupportedAPIInfoFailed"] = "list-supported-api-info-failed";
52
54
  ErrorType["FilterSpecFailed"] = "filter-spec-failed";
@@ -283,7 +285,7 @@ class Utils {
283
285
  static updateFirstLetter(str) {
284
286
  return str.charAt(0).toUpperCase() + str.slice(1);
285
287
  }
286
- static getResponseJson(operationObject) {
288
+ static getResponseJson(operationObject, allowMultipleMediaType = false) {
287
289
  var _a, _b;
288
290
  let json = {};
289
291
  let multipleMediaType = false;
@@ -294,7 +296,9 @@ class Utils {
294
296
  json = responseObject.content["application/json"];
295
297
  if (Utils.containMultipleMediaTypes(responseObject)) {
296
298
  multipleMediaType = true;
297
- json = {};
299
+ if (!allowMultipleMediaType) {
300
+ json = {};
301
+ }
298
302
  }
299
303
  else {
300
304
  break;
@@ -562,6 +566,19 @@ class Utils {
562
566
 
563
567
  // Copyright (c) Microsoft Corporation.
564
568
  class Validator {
569
+ constructor() {
570
+ this.hasCircularReference = false;
571
+ }
572
+ checkCircularReference() {
573
+ try {
574
+ JSON.stringify(this.spec);
575
+ }
576
+ catch (e) {
577
+ if (e.message.includes("Converting circular structure to JSON")) {
578
+ this.hasCircularReference = true;
579
+ }
580
+ }
581
+ }
565
582
  listAPIs() {
566
583
  var _a;
567
584
  if (this.apiMap) {
@@ -657,6 +674,22 @@ class Validator {
657
674
  }
658
675
  return result;
659
676
  }
677
+ validateCircularReference(method, path) {
678
+ const result = { isValid: true, reason: [] };
679
+ if (this.hasCircularReference) {
680
+ const operationObject = this.spec.paths[path][method];
681
+ try {
682
+ JSON.stringify(operationObject);
683
+ }
684
+ catch (e) {
685
+ if (e.message.includes("Converting circular structure to JSON")) {
686
+ result.isValid = false;
687
+ result.reason.push(ErrorType.CircularReferenceNotSupported);
688
+ }
689
+ }
690
+ }
691
+ return result;
692
+ }
660
693
  validateResponse(method, path) {
661
694
  const result = { isValid: true, reason: [] };
662
695
  const operationObject = this.spec.paths[path][method];
@@ -845,6 +878,7 @@ class CopilotValidator extends Validator {
845
878
  this.projectType = ProjectType.Copilot;
846
879
  this.options = options;
847
880
  this.spec = spec;
881
+ this.checkCircularReference();
848
882
  }
849
883
  validateSpec() {
850
884
  const result = { errors: [], warnings: [] };
@@ -870,6 +904,10 @@ class CopilotValidator extends Validator {
870
904
  if (!methodAndPathResult.isValid) {
871
905
  return methodAndPathResult;
872
906
  }
907
+ const circularReferenceResult = this.validateCircularReference(method, path);
908
+ if (!circularReferenceResult.isValid) {
909
+ return circularReferenceResult;
910
+ }
873
911
  const operationObject = this.spec.paths[path][method];
874
912
  // validate auth
875
913
  const authCheckResult = this.validateAuth(method, path);
@@ -913,6 +951,7 @@ class SMEValidator extends Validator {
913
951
  this.projectType = ProjectType.SME;
914
952
  this.options = options;
915
953
  this.spec = spec;
954
+ this.checkCircularReference();
916
955
  }
917
956
  validateSpec() {
918
957
  const result = { errors: [], warnings: [] };
@@ -940,6 +979,10 @@ class SMEValidator extends Validator {
940
979
  if (!methodAndPathResult.isValid) {
941
980
  return methodAndPathResult;
942
981
  }
982
+ const circularReferenceResult = this.validateCircularReference(method, path);
983
+ if (!circularReferenceResult.isValid) {
984
+ return circularReferenceResult;
985
+ }
943
986
  const operationObject = this.spec.paths[path][method];
944
987
  // validate auth
945
988
  const authCheckResult = this.validateAuth(method, path);
@@ -1010,6 +1053,7 @@ class TeamsAIValidator extends Validator {
1010
1053
  this.projectType = ProjectType.TeamsAi;
1011
1054
  this.options = options;
1012
1055
  this.spec = spec;
1056
+ this.checkCircularReference();
1013
1057
  }
1014
1058
  validateSpec() {
1015
1059
  const result = { errors: [], warnings: [] };
@@ -1029,6 +1073,10 @@ class TeamsAIValidator extends Validator {
1029
1073
  if (!methodAndPathResult.isValid) {
1030
1074
  return methodAndPathResult;
1031
1075
  }
1076
+ const circularReferenceResult = this.validateCircularReference(method, path);
1077
+ if (!circularReferenceResult.isValid) {
1078
+ return circularReferenceResult;
1079
+ }
1032
1080
  const operationObject = this.spec.paths[path][method];
1033
1081
  // validate operationId
1034
1082
  if (!this.options.allowMissingId && !operationObject.operationId) {
@@ -1271,9 +1319,9 @@ class SpecParser {
1271
1319
 
1272
1320
  // Copyright (c) Microsoft Corporation.
1273
1321
  class AdaptiveCardGenerator {
1274
- static generateAdaptiveCard(operationItem) {
1322
+ static generateAdaptiveCard(operationItem, allowMultipleMediaType = false) {
1275
1323
  try {
1276
- const { json } = Utils.getResponseJson(operationItem);
1324
+ const { json } = Utils.getResponseJson(operationItem, allowMultipleMediaType);
1277
1325
  let cardBody = [];
1278
1326
  let schema = json.schema;
1279
1327
  let jsonPath = "$";