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