@microsoft/m365-spec-parser 0.2.0 → 0.2.1-alpha.351870269.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.
@@ -17,6 +17,7 @@ var ErrorType;
17
17
  ErrorType["SwaggerNotSupported"] = "swagger-not-supported";
18
18
  ErrorType["MultipleAuthNotSupported"] = "multiple-auth-not-supported";
19
19
  ErrorType["SpecVersionNotSupported"] = "spec-version-not-supported";
20
+ ErrorType["CircularReferenceNotSupported"] = "circular-reference-not-supported";
20
21
  ErrorType["ListFailed"] = "list-failed";
21
22
  ErrorType["listSupportedAPIInfoFailed"] = "list-supported-api-info-failed";
22
23
  ErrorType["FilterSpecFailed"] = "filter-spec-failed";
@@ -532,6 +533,19 @@ class Utils {
532
533
 
533
534
  // Copyright (c) Microsoft Corporation.
534
535
  class Validator {
536
+ constructor() {
537
+ this.hasCircularReference = false;
538
+ }
539
+ checkCircularReference() {
540
+ try {
541
+ JSON.stringify(this.spec);
542
+ }
543
+ catch (e) {
544
+ if (e.message.includes("Converting circular structure to JSON")) {
545
+ this.hasCircularReference = true;
546
+ }
547
+ }
548
+ }
535
549
  listAPIs() {
536
550
  var _a;
537
551
  if (this.apiMap) {
@@ -627,6 +641,22 @@ class Validator {
627
641
  }
628
642
  return result;
629
643
  }
644
+ validateCircularReference(method, path) {
645
+ const result = { isValid: true, reason: [] };
646
+ if (this.hasCircularReference) {
647
+ const operationObject = this.spec.paths[path][method];
648
+ try {
649
+ JSON.stringify(operationObject);
650
+ }
651
+ catch (e) {
652
+ if (e.message.includes("Converting circular structure to JSON")) {
653
+ result.isValid = false;
654
+ result.reason.push(ErrorType.CircularReferenceNotSupported);
655
+ }
656
+ }
657
+ }
658
+ return result;
659
+ }
630
660
  validateResponse(method, path) {
631
661
  const result = { isValid: true, reason: [] };
632
662
  const operationObject = this.spec.paths[path][method];
@@ -815,6 +845,7 @@ class CopilotValidator extends Validator {
815
845
  this.projectType = ProjectType.Copilot;
816
846
  this.options = options;
817
847
  this.spec = spec;
848
+ this.checkCircularReference();
818
849
  }
819
850
  validateSpec() {
820
851
  const result = { errors: [], warnings: [] };
@@ -840,6 +871,10 @@ class CopilotValidator extends Validator {
840
871
  if (!methodAndPathResult.isValid) {
841
872
  return methodAndPathResult;
842
873
  }
874
+ const circularReferenceResult = this.validateCircularReference(method, path);
875
+ if (!circularReferenceResult.isValid) {
876
+ return circularReferenceResult;
877
+ }
843
878
  const operationObject = this.spec.paths[path][method];
844
879
  // validate auth
845
880
  const authCheckResult = this.validateAuth(method, path);
@@ -883,6 +918,7 @@ class SMEValidator extends Validator {
883
918
  this.projectType = ProjectType.SME;
884
919
  this.options = options;
885
920
  this.spec = spec;
921
+ this.checkCircularReference();
886
922
  }
887
923
  validateSpec() {
888
924
  const result = { errors: [], warnings: [] };
@@ -910,6 +946,10 @@ class SMEValidator extends Validator {
910
946
  if (!methodAndPathResult.isValid) {
911
947
  return methodAndPathResult;
912
948
  }
949
+ const circularReferenceResult = this.validateCircularReference(method, path);
950
+ if (!circularReferenceResult.isValid) {
951
+ return circularReferenceResult;
952
+ }
913
953
  const operationObject = this.spec.paths[path][method];
914
954
  // validate auth
915
955
  const authCheckResult = this.validateAuth(method, path);
@@ -980,6 +1020,7 @@ class TeamsAIValidator extends Validator {
980
1020
  this.projectType = ProjectType.TeamsAi;
981
1021
  this.options = options;
982
1022
  this.spec = spec;
1023
+ this.checkCircularReference();
983
1024
  }
984
1025
  validateSpec() {
985
1026
  const result = { errors: [], warnings: [] };
@@ -999,6 +1040,10 @@ class TeamsAIValidator extends Validator {
999
1040
  if (!methodAndPathResult.isValid) {
1000
1041
  return methodAndPathResult;
1001
1042
  }
1043
+ const circularReferenceResult = this.validateCircularReference(method, path);
1044
+ if (!circularReferenceResult.isValid) {
1045
+ return circularReferenceResult;
1046
+ }
1002
1047
  const operationObject = this.spec.paths[path][method];
1003
1048
  // validate operationId
1004
1049
  if (!this.options.allowMissingId && !operationObject.operationId) {