@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.
@@ -188,19 +188,16 @@ ConstantString.PluginManifestSchema = "https://developer.microsoft.com/json-sche
188
188
  // Copyright (c) Microsoft Corporation.
189
189
  class Utils {
190
190
  static hasNestedObjectInSchema(schema) {
191
- if (this.isObjectSchema(schema)) {
191
+ if (schema.type === "object") {
192
192
  for (const property in schema.properties) {
193
193
  const nestedSchema = schema.properties[property];
194
- if (this.isObjectSchema(nestedSchema)) {
194
+ if (nestedSchema.type === "object") {
195
195
  return true;
196
196
  }
197
197
  }
198
198
  }
199
199
  return false;
200
200
  }
201
- static isObjectSchema(schema) {
202
- return schema.type === "object" || (!schema.type && !!schema.properties);
203
- }
204
201
  static containMultipleMediaTypes(bodyObject) {
205
202
  return Object.keys((bodyObject === null || bodyObject === void 0 ? void 0 : bodyObject.content) || {}).length > 1;
206
203
  }
@@ -429,7 +426,7 @@ class Utils {
429
426
  optionalParams.push(parameter);
430
427
  }
431
428
  }
432
- else if (Utils.isObjectSchema(schema)) {
429
+ else if (schema.type === "object") {
433
430
  const { properties } = schema;
434
431
  for (const property in properties) {
435
432
  let isRequired = false;
@@ -767,7 +764,7 @@ class Validator {
767
764
  }
768
765
  const isRequiredWithoutDefault = isRequired && schema.default === undefined;
769
766
  const isCopilot = this.projectType === ProjectType.Copilot;
770
- if (isCopilot && Utils.hasNestedObjectInSchema(schema)) {
767
+ if (isCopilot && this.hasNestedObjectInSchema(schema)) {
771
768
  paramResult.isValid = false;
772
769
  paramResult.reason = [ErrorType.RequestBodyContainsNestedObject];
773
770
  return paramResult;
@@ -783,7 +780,7 @@ class Validator {
783
780
  paramResult.optionalNum = paramResult.optionalNum + 1;
784
781
  }
785
782
  }
786
- else if (Utils.isObjectSchema(schema)) {
783
+ else if (schema.type === "object") {
787
784
  const { properties } = schema;
788
785
  for (const property in properties) {
789
786
  let isRequired = false;
@@ -819,7 +816,7 @@ class Validator {
819
816
  for (let i = 0; i < paramObject.length; i++) {
820
817
  const param = paramObject[i];
821
818
  const schema = param.schema;
822
- if (isCopilot && Utils.hasNestedObjectInSchema(schema)) {
819
+ if (isCopilot && this.hasNestedObjectInSchema(schema)) {
823
820
  paramResult.isValid = false;
824
821
  paramResult.reason.push(ErrorType.ParamsContainsNestedObject);
825
822
  continue;
@@ -862,6 +859,17 @@ class Validator {
862
859
  }
863
860
  return paramResult;
864
861
  }
862
+ hasNestedObjectInSchema(schema) {
863
+ if (schema.type === "object") {
864
+ for (const property in schema.properties) {
865
+ const nestedSchema = schema.properties[property];
866
+ if (nestedSchema.type === "object") {
867
+ return true;
868
+ }
869
+ }
870
+ }
871
+ return false;
872
+ }
865
873
  }
866
874
 
867
875
  // Copyright (c) Microsoft Corporation.
@@ -920,7 +928,7 @@ class CopilotValidator extends Validator {
920
928
  const requestJsonBody = requestBody === null || requestBody === void 0 ? void 0 : requestBody.content["application/json"];
921
929
  if (requestJsonBody) {
922
930
  const requestBodySchema = requestJsonBody.schema;
923
- if (!Utils.isObjectSchema(requestBodySchema)) {
931
+ if (requestBodySchema.type !== "object") {
924
932
  result.reason.push(ErrorType.PostBodySchemaIsNotJson);
925
933
  }
926
934
  const requestBodyParamResult = this.checkPostBodySchema(requestBodySchema, requestBody.required);
@@ -1365,7 +1373,7 @@ class AdaptiveCardGenerator {
1365
1373
  return [template];
1366
1374
  }
1367
1375
  // some schema may not contain type but contain properties
1368
- if (Utils.isObjectSchema(schema)) {
1376
+ if (schema.type === "object" || (!schema.type && schema.properties)) {
1369
1377
  const { properties } = schema;
1370
1378
  const result = [];
1371
1379
  for (const property in properties) {
@@ -1433,7 +1441,7 @@ class AdaptiveCardGenerator {
1433
1441
  }
1434
1442
  // Find the first array property in the response schema object with the well-known name
1435
1443
  static getResponseJsonPathFromSchema(schema) {
1436
- if (Utils.isObjectSchema(schema)) {
1444
+ if (schema.type === "object" || (!schema.type && schema.properties)) {
1437
1445
  const { properties } = schema;
1438
1446
  for (const property in properties) {
1439
1447
  const schema = properties[property];