@microsoft/m365-spec-parser 0.2.0 → 0.2.1-alpha.20d61baa8.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";
@@ -562,6 +564,19 @@ class Utils {
562
564
 
563
565
  // Copyright (c) Microsoft Corporation.
564
566
  class Validator {
567
+ constructor() {
568
+ this.hasCircularReference = false;
569
+ }
570
+ checkCircularReference() {
571
+ try {
572
+ JSON.stringify(this.spec);
573
+ }
574
+ catch (e) {
575
+ if (e.message.includes("Converting circular structure to JSON")) {
576
+ this.hasCircularReference = true;
577
+ }
578
+ }
579
+ }
565
580
  listAPIs() {
566
581
  var _a;
567
582
  if (this.apiMap) {
@@ -657,6 +672,22 @@ class Validator {
657
672
  }
658
673
  return result;
659
674
  }
675
+ validateCircularReference(method, path) {
676
+ const result = { isValid: true, reason: [] };
677
+ if (this.hasCircularReference) {
678
+ const operationObject = this.spec.paths[path][method];
679
+ try {
680
+ JSON.stringify(operationObject);
681
+ }
682
+ catch (e) {
683
+ if (e.message.includes("Converting circular structure to JSON")) {
684
+ result.isValid = false;
685
+ result.reason.push(ErrorType.CircularReferenceNotSupported);
686
+ }
687
+ }
688
+ }
689
+ return result;
690
+ }
660
691
  validateResponse(method, path) {
661
692
  const result = { isValid: true, reason: [] };
662
693
  const operationObject = this.spec.paths[path][method];
@@ -845,6 +876,7 @@ class CopilotValidator extends Validator {
845
876
  this.projectType = ProjectType.Copilot;
846
877
  this.options = options;
847
878
  this.spec = spec;
879
+ this.checkCircularReference();
848
880
  }
849
881
  validateSpec() {
850
882
  const result = { errors: [], warnings: [] };
@@ -870,6 +902,10 @@ class CopilotValidator extends Validator {
870
902
  if (!methodAndPathResult.isValid) {
871
903
  return methodAndPathResult;
872
904
  }
905
+ const circularReferenceResult = this.validateCircularReference(method, path);
906
+ if (!circularReferenceResult.isValid) {
907
+ return circularReferenceResult;
908
+ }
873
909
  const operationObject = this.spec.paths[path][method];
874
910
  // validate auth
875
911
  const authCheckResult = this.validateAuth(method, path);
@@ -913,6 +949,7 @@ class SMEValidator extends Validator {
913
949
  this.projectType = ProjectType.SME;
914
950
  this.options = options;
915
951
  this.spec = spec;
952
+ this.checkCircularReference();
916
953
  }
917
954
  validateSpec() {
918
955
  const result = { errors: [], warnings: [] };
@@ -940,6 +977,10 @@ class SMEValidator extends Validator {
940
977
  if (!methodAndPathResult.isValid) {
941
978
  return methodAndPathResult;
942
979
  }
980
+ const circularReferenceResult = this.validateCircularReference(method, path);
981
+ if (!circularReferenceResult.isValid) {
982
+ return circularReferenceResult;
983
+ }
943
984
  const operationObject = this.spec.paths[path][method];
944
985
  // validate auth
945
986
  const authCheckResult = this.validateAuth(method, path);
@@ -1010,6 +1051,7 @@ class TeamsAIValidator extends Validator {
1010
1051
  this.projectType = ProjectType.TeamsAi;
1011
1052
  this.options = options;
1012
1053
  this.spec = spec;
1054
+ this.checkCircularReference();
1013
1055
  }
1014
1056
  validateSpec() {
1015
1057
  const result = { errors: [], warnings: [] };
@@ -1029,6 +1071,10 @@ class TeamsAIValidator extends Validator {
1029
1071
  if (!methodAndPathResult.isValid) {
1030
1072
  return methodAndPathResult;
1031
1073
  }
1074
+ const circularReferenceResult = this.validateCircularReference(method, path);
1075
+ if (!circularReferenceResult.isValid) {
1076
+ return circularReferenceResult;
1077
+ }
1032
1078
  const operationObject = this.spec.paths[path][method];
1033
1079
  // validate operationId
1034
1080
  if (!this.options.allowMissingId && !operationObject.operationId) {