@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.
@@ -59,10 +59,12 @@ exports.ErrorType = void 0;
59
59
  ErrorType["RelativeServerUrlNotSupported"] = "relative-server-url-not-supported";
60
60
  ErrorType["NoSupportedApi"] = "no-supported-api";
61
61
  ErrorType["NoExtraAPICanBeAdded"] = "no-extra-api-can-be-added";
62
+ ErrorType["AddedAPINotInOriginalSpec"] = "added-api-not-in-original-spec";
62
63
  ErrorType["ResolveServerUrlFailed"] = "resolve-server-url-failed";
63
64
  ErrorType["SwaggerNotSupported"] = "swagger-not-supported";
64
65
  ErrorType["MultipleAuthNotSupported"] = "multiple-auth-not-supported";
65
66
  ErrorType["SpecVersionNotSupported"] = "spec-version-not-supported";
67
+ ErrorType["CircularReferenceNotSupported"] = "circular-reference-not-supported";
66
68
  ErrorType["ListFailed"] = "list-failed";
67
69
  ErrorType["listSupportedAPIInfoFailed"] = "list-supported-api-info-failed";
68
70
  ErrorType["FilterSpecFailed"] = "filter-spec-failed";
@@ -578,6 +580,19 @@ class Utils {
578
580
 
579
581
  // Copyright (c) Microsoft Corporation.
580
582
  class Validator {
583
+ constructor() {
584
+ this.hasCircularReference = false;
585
+ }
586
+ checkCircularReference() {
587
+ try {
588
+ JSON.stringify(this.spec);
589
+ }
590
+ catch (e) {
591
+ if (e.message.includes("Converting circular structure to JSON")) {
592
+ this.hasCircularReference = true;
593
+ }
594
+ }
595
+ }
581
596
  listAPIs() {
582
597
  var _a;
583
598
  if (this.apiMap) {
@@ -673,6 +688,22 @@ class Validator {
673
688
  }
674
689
  return result;
675
690
  }
691
+ validateCircularReference(method, path) {
692
+ const result = { isValid: true, reason: [] };
693
+ if (this.hasCircularReference) {
694
+ const operationObject = this.spec.paths[path][method];
695
+ try {
696
+ JSON.stringify(operationObject);
697
+ }
698
+ catch (e) {
699
+ if (e.message.includes("Converting circular structure to JSON")) {
700
+ result.isValid = false;
701
+ result.reason.push(exports.ErrorType.CircularReferenceNotSupported);
702
+ }
703
+ }
704
+ }
705
+ return result;
706
+ }
676
707
  validateResponse(method, path) {
677
708
  const result = { isValid: true, reason: [] };
678
709
  const operationObject = this.spec.paths[path][method];
@@ -861,6 +892,7 @@ class CopilotValidator extends Validator {
861
892
  this.projectType = exports.ProjectType.Copilot;
862
893
  this.options = options;
863
894
  this.spec = spec;
895
+ this.checkCircularReference();
864
896
  }
865
897
  validateSpec() {
866
898
  const result = { errors: [], warnings: [] };
@@ -886,6 +918,10 @@ class CopilotValidator extends Validator {
886
918
  if (!methodAndPathResult.isValid) {
887
919
  return methodAndPathResult;
888
920
  }
921
+ const circularReferenceResult = this.validateCircularReference(method, path);
922
+ if (!circularReferenceResult.isValid) {
923
+ return circularReferenceResult;
924
+ }
889
925
  const operationObject = this.spec.paths[path][method];
890
926
  // validate auth
891
927
  const authCheckResult = this.validateAuth(method, path);
@@ -929,6 +965,7 @@ class SMEValidator extends Validator {
929
965
  this.projectType = exports.ProjectType.SME;
930
966
  this.options = options;
931
967
  this.spec = spec;
968
+ this.checkCircularReference();
932
969
  }
933
970
  validateSpec() {
934
971
  const result = { errors: [], warnings: [] };
@@ -956,6 +993,10 @@ class SMEValidator extends Validator {
956
993
  if (!methodAndPathResult.isValid) {
957
994
  return methodAndPathResult;
958
995
  }
996
+ const circularReferenceResult = this.validateCircularReference(method, path);
997
+ if (!circularReferenceResult.isValid) {
998
+ return circularReferenceResult;
999
+ }
959
1000
  const operationObject = this.spec.paths[path][method];
960
1001
  // validate auth
961
1002
  const authCheckResult = this.validateAuth(method, path);
@@ -1026,6 +1067,7 @@ class TeamsAIValidator extends Validator {
1026
1067
  this.projectType = exports.ProjectType.TeamsAi;
1027
1068
  this.options = options;
1028
1069
  this.spec = spec;
1070
+ this.checkCircularReference();
1029
1071
  }
1030
1072
  validateSpec() {
1031
1073
  const result = { errors: [], warnings: [] };
@@ -1045,6 +1087,10 @@ class TeamsAIValidator extends Validator {
1045
1087
  if (!methodAndPathResult.isValid) {
1046
1088
  return methodAndPathResult;
1047
1089
  }
1090
+ const circularReferenceResult = this.validateCircularReference(method, path);
1091
+ if (!circularReferenceResult.isValid) {
1092
+ return circularReferenceResult;
1093
+ }
1048
1094
  const operationObject = this.spec.paths[path][method];
1049
1095
  // validate operationId
1050
1096
  if (!this.options.allowMissingId && !operationObject.operationId) {
@@ -1782,7 +1828,13 @@ class SpecParser {
1782
1828
  try {
1783
1829
  try {
1784
1830
  yield this.loadSpec();
1785
- yield this.parser.validate(this.spec);
1831
+ if (!this.parser.$refs.circular) {
1832
+ yield this.parser.validate(this.spec);
1833
+ }
1834
+ else {
1835
+ const clonedUnResolveSpec = JSON.parse(JSON.stringify(this.unResolveSpec));
1836
+ yield this.parser.validate(clonedUnResolveSpec);
1837
+ }
1786
1838
  }
1787
1839
  catch (e) {
1788
1840
  return {
@@ -1919,7 +1971,8 @@ class SpecParser {
1919
1971
  if (signal === null || signal === void 0 ? void 0 : signal.aborted) {
1920
1972
  throw new SpecParserError(ConstantString.CancelledMessage, exports.ErrorType.Cancelled);
1921
1973
  }
1922
- const newSpec = (yield this.parser.dereference(newUnResolvedSpec));
1974
+ const clonedUnResolveSpec = JSON.parse(JSON.stringify(this.unResolveSpec));
1975
+ const newSpec = (yield this.parser.dereference(clonedUnResolveSpec));
1923
1976
  return [newUnResolvedSpec, newSpec];
1924
1977
  }
1925
1978
  catch (err) {