@microsoft/m365-spec-parser 0.2.2-rc.0 → 0.2.2

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.
@@ -218,19 +218,16 @@ ConstantString.PluginManifestSchema = "https://developer.microsoft.com/json-sche
218
218
  // Copyright (c) Microsoft Corporation.
219
219
  class Utils {
220
220
  static hasNestedObjectInSchema(schema) {
221
- if (this.isObjectSchema(schema)) {
221
+ if (schema.type === "object") {
222
222
  for (const property in schema.properties) {
223
223
  const nestedSchema = schema.properties[property];
224
- if (this.isObjectSchema(nestedSchema)) {
224
+ if (nestedSchema.type === "object") {
225
225
  return true;
226
226
  }
227
227
  }
228
228
  }
229
229
  return false;
230
230
  }
231
- static isObjectSchema(schema) {
232
- return schema.type === "object" || (!schema.type && !!schema.properties);
233
- }
234
231
  static containMultipleMediaTypes(bodyObject) {
235
232
  return Object.keys((bodyObject === null || bodyObject === void 0 ? void 0 : bodyObject.content) || {}).length > 1;
236
233
  }
@@ -459,7 +456,7 @@ class Utils {
459
456
  optionalParams.push(parameter);
460
457
  }
461
458
  }
462
- else if (Utils.isObjectSchema(schema)) {
459
+ else if (schema.type === "object") {
463
460
  const { properties } = schema;
464
461
  for (const property in properties) {
465
462
  let isRequired = false;
@@ -797,7 +794,7 @@ class Validator {
797
794
  }
798
795
  const isRequiredWithoutDefault = isRequired && schema.default === undefined;
799
796
  const isCopilot = this.projectType === ProjectType.Copilot;
800
- if (isCopilot && Utils.hasNestedObjectInSchema(schema)) {
797
+ if (isCopilot && this.hasNestedObjectInSchema(schema)) {
801
798
  paramResult.isValid = false;
802
799
  paramResult.reason = [ErrorType.RequestBodyContainsNestedObject];
803
800
  return paramResult;
@@ -813,7 +810,7 @@ class Validator {
813
810
  paramResult.optionalNum = paramResult.optionalNum + 1;
814
811
  }
815
812
  }
816
- else if (Utils.isObjectSchema(schema)) {
813
+ else if (schema.type === "object") {
817
814
  const { properties } = schema;
818
815
  for (const property in properties) {
819
816
  let isRequired = false;
@@ -849,7 +846,7 @@ class Validator {
849
846
  for (let i = 0; i < paramObject.length; i++) {
850
847
  const param = paramObject[i];
851
848
  const schema = param.schema;
852
- if (isCopilot && Utils.hasNestedObjectInSchema(schema)) {
849
+ if (isCopilot && this.hasNestedObjectInSchema(schema)) {
853
850
  paramResult.isValid = false;
854
851
  paramResult.reason.push(ErrorType.ParamsContainsNestedObject);
855
852
  continue;
@@ -892,6 +889,17 @@ class Validator {
892
889
  }
893
890
  return paramResult;
894
891
  }
892
+ hasNestedObjectInSchema(schema) {
893
+ if (schema.type === "object") {
894
+ for (const property in schema.properties) {
895
+ const nestedSchema = schema.properties[property];
896
+ if (nestedSchema.type === "object") {
897
+ return true;
898
+ }
899
+ }
900
+ }
901
+ return false;
902
+ }
895
903
  }
896
904
 
897
905
  // Copyright (c) Microsoft Corporation.
@@ -950,7 +958,7 @@ class CopilotValidator extends Validator {
950
958
  const requestJsonBody = requestBody === null || requestBody === void 0 ? void 0 : requestBody.content["application/json"];
951
959
  if (requestJsonBody) {
952
960
  const requestBodySchema = requestJsonBody.schema;
953
- if (!Utils.isObjectSchema(requestBodySchema)) {
961
+ if (requestBodySchema.type !== "object") {
954
962
  result.reason.push(ErrorType.PostBodySchemaIsNotJson);
955
963
  }
956
964
  const requestBodyParamResult = this.checkPostBodySchema(requestBodySchema, requestBody.required);
@@ -1409,7 +1417,7 @@ class AdaptiveCardGenerator {
1409
1417
  return [template];
1410
1418
  }
1411
1419
  // some schema may not contain type but contain properties
1412
- if (Utils.isObjectSchema(schema)) {
1420
+ if (schema.type === "object" || (!schema.type && schema.properties)) {
1413
1421
  const { properties } = schema;
1414
1422
  const result = [];
1415
1423
  for (const property in properties) {
@@ -1477,7 +1485,7 @@ class AdaptiveCardGenerator {
1477
1485
  }
1478
1486
  // Find the first array property in the response schema object with the well-known name
1479
1487
  static getResponseJsonPathFromSchema(schema) {
1480
- if (Utils.isObjectSchema(schema)) {
1488
+ if (schema.type === "object" || (!schema.type && schema.properties)) {
1481
1489
  const { properties } = schema;
1482
1490
  for (const property in properties) {
1483
1491
  const schema = properties[property];