@microsoft/m365-spec-parser 0.2.1 → 0.2.2-alpha.6e69e41c0.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.
@@ -13,10 +13,12 @@ var ErrorType;
13
13
  ErrorType["RelativeServerUrlNotSupported"] = "relative-server-url-not-supported";
14
14
  ErrorType["NoSupportedApi"] = "no-supported-api";
15
15
  ErrorType["NoExtraAPICanBeAdded"] = "no-extra-api-can-be-added";
16
+ ErrorType["AddedAPINotInOriginalSpec"] = "added-api-not-in-original-spec";
16
17
  ErrorType["ResolveServerUrlFailed"] = "resolve-server-url-failed";
17
18
  ErrorType["SwaggerNotSupported"] = "swagger-not-supported";
18
19
  ErrorType["MultipleAuthNotSupported"] = "multiple-auth-not-supported";
19
20
  ErrorType["SpecVersionNotSupported"] = "spec-version-not-supported";
21
+ ErrorType["CircularReferenceNotSupported"] = "circular-reference-not-supported";
20
22
  ErrorType["ListFailed"] = "list-failed";
21
23
  ErrorType["listSupportedAPIInfoFailed"] = "list-supported-api-info-failed";
22
24
  ErrorType["FilterSpecFailed"] = "filter-spec-failed";
@@ -253,7 +255,7 @@ class Utils {
253
255
  static updateFirstLetter(str) {
254
256
  return str.charAt(0).toUpperCase() + str.slice(1);
255
257
  }
256
- static getResponseJson(operationObject) {
258
+ static getResponseJson(operationObject, allowMultipleMediaType = false) {
257
259
  var _a, _b;
258
260
  let json = {};
259
261
  let multipleMediaType = false;
@@ -264,7 +266,9 @@ class Utils {
264
266
  json = responseObject.content["application/json"];
265
267
  if (Utils.containMultipleMediaTypes(responseObject)) {
266
268
  multipleMediaType = true;
267
- json = {};
269
+ if (!allowMultipleMediaType) {
270
+ json = {};
271
+ }
268
272
  }
269
273
  else {
270
274
  break;
@@ -532,6 +536,19 @@ class Utils {
532
536
 
533
537
  // Copyright (c) Microsoft Corporation.
534
538
  class Validator {
539
+ constructor() {
540
+ this.hasCircularReference = false;
541
+ }
542
+ checkCircularReference() {
543
+ try {
544
+ JSON.stringify(this.spec);
545
+ }
546
+ catch (e) {
547
+ if (e.message.includes("Converting circular structure to JSON")) {
548
+ this.hasCircularReference = true;
549
+ }
550
+ }
551
+ }
535
552
  listAPIs() {
536
553
  var _a;
537
554
  if (this.apiMap) {
@@ -627,6 +644,22 @@ class Validator {
627
644
  }
628
645
  return result;
629
646
  }
647
+ validateCircularReference(method, path) {
648
+ const result = { isValid: true, reason: [] };
649
+ if (this.hasCircularReference) {
650
+ const operationObject = this.spec.paths[path][method];
651
+ try {
652
+ JSON.stringify(operationObject);
653
+ }
654
+ catch (e) {
655
+ if (e.message.includes("Converting circular structure to JSON")) {
656
+ result.isValid = false;
657
+ result.reason.push(ErrorType.CircularReferenceNotSupported);
658
+ }
659
+ }
660
+ }
661
+ return result;
662
+ }
630
663
  validateResponse(method, path) {
631
664
  const result = { isValid: true, reason: [] };
632
665
  const operationObject = this.spec.paths[path][method];
@@ -815,6 +848,7 @@ class CopilotValidator extends Validator {
815
848
  this.projectType = ProjectType.Copilot;
816
849
  this.options = options;
817
850
  this.spec = spec;
851
+ this.checkCircularReference();
818
852
  }
819
853
  validateSpec() {
820
854
  const result = { errors: [], warnings: [] };
@@ -840,6 +874,10 @@ class CopilotValidator extends Validator {
840
874
  if (!methodAndPathResult.isValid) {
841
875
  return methodAndPathResult;
842
876
  }
877
+ const circularReferenceResult = this.validateCircularReference(method, path);
878
+ if (!circularReferenceResult.isValid) {
879
+ return circularReferenceResult;
880
+ }
843
881
  const operationObject = this.spec.paths[path][method];
844
882
  // validate auth
845
883
  const authCheckResult = this.validateAuth(method, path);
@@ -883,6 +921,7 @@ class SMEValidator extends Validator {
883
921
  this.projectType = ProjectType.SME;
884
922
  this.options = options;
885
923
  this.spec = spec;
924
+ this.checkCircularReference();
886
925
  }
887
926
  validateSpec() {
888
927
  const result = { errors: [], warnings: [] };
@@ -910,6 +949,10 @@ class SMEValidator extends Validator {
910
949
  if (!methodAndPathResult.isValid) {
911
950
  return methodAndPathResult;
912
951
  }
952
+ const circularReferenceResult = this.validateCircularReference(method, path);
953
+ if (!circularReferenceResult.isValid) {
954
+ return circularReferenceResult;
955
+ }
913
956
  const operationObject = this.spec.paths[path][method];
914
957
  // validate auth
915
958
  const authCheckResult = this.validateAuth(method, path);
@@ -980,6 +1023,7 @@ class TeamsAIValidator extends Validator {
980
1023
  this.projectType = ProjectType.TeamsAi;
981
1024
  this.options = options;
982
1025
  this.spec = spec;
1026
+ this.checkCircularReference();
983
1027
  }
984
1028
  validateSpec() {
985
1029
  const result = { errors: [], warnings: [] };
@@ -999,6 +1043,10 @@ class TeamsAIValidator extends Validator {
999
1043
  if (!methodAndPathResult.isValid) {
1000
1044
  return methodAndPathResult;
1001
1045
  }
1046
+ const circularReferenceResult = this.validateCircularReference(method, path);
1047
+ if (!circularReferenceResult.isValid) {
1048
+ return circularReferenceResult;
1049
+ }
1002
1050
  const operationObject = this.spec.paths[path][method];
1003
1051
  // validate operationId
1004
1052
  if (!this.options.allowMissingId && !operationObject.operationId) {
@@ -1227,9 +1275,9 @@ class SpecParser {
1227
1275
 
1228
1276
  // Copyright (c) Microsoft Corporation.
1229
1277
  class AdaptiveCardGenerator {
1230
- static generateAdaptiveCard(operationItem) {
1278
+ static generateAdaptiveCard(operationItem, allowMultipleMediaType = false) {
1231
1279
  try {
1232
- const { json } = Utils.getResponseJson(operationItem);
1280
+ const { json } = Utils.getResponseJson(operationItem, allowMultipleMediaType);
1233
1281
  let cardBody = [];
1234
1282
  let schema = json.schema;
1235
1283
  let jsonPath = "$";