@microsoft/m365-spec-parser 0.2.2-alpha.1fac52ff4.0 → 0.2.2-alpha.2beeded72.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.
@@ -180,7 +180,7 @@ ConstantString.ParameterTitleMaxLens = 32;
180
180
  ConstantString.SMERequiredParamsMaxNum = 5;
181
181
  ConstantString.FunctionDescriptionMaxLens = 100;
182
182
  ConstantString.DefaultPluginId = "plugin_1";
183
- ConstantString.PluginManifestSchema = "https://aka.ms/json-schemas/copilot-extensions/v2.1/plugin.schema.json";
183
+ ConstantString.PluginManifestSchema = "https://developer.microsoft.com/json-schemas/copilot/plugin/v2.1/schema.json";
184
184
 
185
185
  // Copyright (c) Microsoft Corporation.
186
186
  class SpecParserError extends Error {
@@ -193,16 +193,19 @@ class SpecParserError extends Error {
193
193
  // Copyright (c) Microsoft Corporation.
194
194
  class Utils {
195
195
  static hasNestedObjectInSchema(schema) {
196
- if (schema.type === "object") {
196
+ if (this.isObjectSchema(schema)) {
197
197
  for (const property in schema.properties) {
198
198
  const nestedSchema = schema.properties[property];
199
- if (nestedSchema.type === "object") {
199
+ if (this.isObjectSchema(nestedSchema)) {
200
200
  return true;
201
201
  }
202
202
  }
203
203
  }
204
204
  return false;
205
205
  }
206
+ static isObjectSchema(schema) {
207
+ return schema.type === "object" || (!schema.type && !!schema.properties);
208
+ }
206
209
  static containMultipleMediaTypes(bodyObject) {
207
210
  return Object.keys((bodyObject === null || bodyObject === void 0 ? void 0 : bodyObject.content) || {}).length > 1;
208
211
  }
@@ -431,7 +434,7 @@ class Utils {
431
434
  optionalParams.push(parameter);
432
435
  }
433
436
  }
434
- else if (schema.type === "object") {
437
+ else if (Utils.isObjectSchema(schema)) {
435
438
  const { properties } = schema;
436
439
  for (const property in properties) {
437
440
  let isRequired = false;
@@ -769,7 +772,7 @@ class Validator {
769
772
  }
770
773
  const isRequiredWithoutDefault = isRequired && schema.default === undefined;
771
774
  const isCopilot = this.projectType === ProjectType.Copilot;
772
- if (isCopilot && this.hasNestedObjectInSchema(schema)) {
775
+ if (isCopilot && Utils.hasNestedObjectInSchema(schema)) {
773
776
  paramResult.isValid = false;
774
777
  paramResult.reason = [ErrorType.RequestBodyContainsNestedObject];
775
778
  return paramResult;
@@ -785,7 +788,7 @@ class Validator {
785
788
  paramResult.optionalNum = paramResult.optionalNum + 1;
786
789
  }
787
790
  }
788
- else if (schema.type === "object") {
791
+ else if (Utils.isObjectSchema(schema)) {
789
792
  const { properties } = schema;
790
793
  for (const property in properties) {
791
794
  let isRequired = false;
@@ -821,7 +824,7 @@ class Validator {
821
824
  for (let i = 0; i < paramObject.length; i++) {
822
825
  const param = paramObject[i];
823
826
  const schema = param.schema;
824
- if (isCopilot && this.hasNestedObjectInSchema(schema)) {
827
+ if (isCopilot && Utils.hasNestedObjectInSchema(schema)) {
825
828
  paramResult.isValid = false;
826
829
  paramResult.reason.push(ErrorType.ParamsContainsNestedObject);
827
830
  continue;
@@ -864,17 +867,6 @@ class Validator {
864
867
  }
865
868
  return paramResult;
866
869
  }
867
- hasNestedObjectInSchema(schema) {
868
- if (schema.type === "object") {
869
- for (const property in schema.properties) {
870
- const nestedSchema = schema.properties[property];
871
- if (nestedSchema.type === "object") {
872
- return true;
873
- }
874
- }
875
- }
876
- return false;
877
- }
878
870
  }
879
871
 
880
872
  // Copyright (c) Microsoft Corporation.
@@ -933,7 +925,7 @@ class CopilotValidator extends Validator {
933
925
  const requestJsonBody = requestBody === null || requestBody === void 0 ? void 0 : requestBody.content["application/json"];
934
926
  if (requestJsonBody) {
935
927
  const requestBodySchema = requestJsonBody.schema;
936
- if (requestBodySchema.type !== "object") {
928
+ if (!Utils.isObjectSchema(requestBodySchema)) {
937
929
  result.reason.push(ErrorType.PostBodySchemaIsNotJson);
938
930
  }
939
931
  const requestBodyParamResult = this.checkPostBodySchema(requestBodySchema, requestBody.required);
@@ -1380,7 +1372,7 @@ class AdaptiveCardGenerator {
1380
1372
  return [template];
1381
1373
  }
1382
1374
  // some schema may not contain type but contain properties
1383
- if (schema.type === "object" || (!schema.type && schema.properties)) {
1375
+ if (Utils.isObjectSchema(schema)) {
1384
1376
  const { properties } = schema;
1385
1377
  const result = [];
1386
1378
  for (const property in properties) {
@@ -1448,7 +1440,7 @@ class AdaptiveCardGenerator {
1448
1440
  }
1449
1441
  // Find the first array property in the response schema object with the well-known name
1450
1442
  static getResponseJsonPathFromSchema(schema) {
1451
- if (schema.type === "object" || (!schema.type && schema.properties)) {
1443
+ if (Utils.isObjectSchema(schema)) {
1452
1444
  const { properties } = schema;
1453
1445
  for (const property in properties) {
1454
1446
  const schema = properties[property];
@@ -1686,7 +1678,7 @@ class ManifestUpdater {
1686
1678
  if (requestBody) {
1687
1679
  const requestJsonBody = requestBody.content["application/json"];
1688
1680
  const requestBodySchema = requestJsonBody.schema;
1689
- if (requestBodySchema.type === "object") {
1681
+ if (Utils.isObjectSchema(requestBodySchema)) {
1690
1682
  for (const property in requestBodySchema.properties) {
1691
1683
  const schema = requestBodySchema.properties[property];
1692
1684
  ManifestUpdater.checkSchema(schema, method, pathUrl);