@microsoft/m365-spec-parser 0.2.2-alpha.288b4cdfa.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.
@@ -54,6 +54,7 @@ var WarningType;
54
54
  WarningType["GenerateCardFailed"] = "generate-card-failed";
55
55
  WarningType["OperationOnlyContainsOptionalParam"] = "operation-only-contains-optional-param";
56
56
  WarningType["ConvertSwaggerToOpenAPI"] = "convert-swagger-to-openapi";
57
+ WarningType["FuncDescriptionTooLong"] = "function-description-too-long";
57
58
  WarningType["Unknown"] = "unknown";
58
59
  })(WarningType || (WarningType = {}));
59
60
  /**
@@ -100,6 +101,7 @@ ConstantString.SwaggerNotSupported = "Swagger 2.0 is not supported. Please conve
100
101
  ConstantString.SpecVersionNotSupported = "Unsupported OpenAPI version %s. Please use version 3.0.x.";
101
102
  ConstantString.MultipleAuthNotSupported = "Multiple authentication methods are unsupported. Ensure all selected APIs use identical authentication.";
102
103
  ConstantString.UnsupportedSchema = "Unsupported schema in %s %s: %s";
104
+ ConstantString.FuncDescriptionTooLong = "The description of the function '%s' is too long. The current length is %s characters, while the maximum allowed length is %s characters.";
103
105
  ConstantString.WrappedCardVersion = "devPreview";
104
106
  ConstantString.WrappedCardSchema = "https://developer.microsoft.com/json-schemas/teams/vDevPreview/MicrosoftTeams.ResponseRenderingTemplate.schema.json";
105
107
  ConstantString.WrappedCardResponseLayout = "list";
@@ -179,22 +181,26 @@ ConstantString.ConversationStarterMaxLens = 50;
179
181
  ConstantString.CommandTitleMaxLens = 32;
180
182
  ConstantString.ParameterTitleMaxLens = 32;
181
183
  ConstantString.SMERequiredParamsMaxNum = 5;
184
+ ConstantString.FunctionDescriptionMaxLens = 100;
182
185
  ConstantString.DefaultPluginId = "plugin_1";
183
- ConstantString.PluginManifestSchema = "https://aka.ms/json-schemas/copilot-extensions/v2.1/plugin.schema.json";
186
+ ConstantString.PluginManifestSchema = "https://developer.microsoft.com/json-schemas/copilot/plugin/v2.1/schema.json";
184
187
 
185
188
  // Copyright (c) Microsoft Corporation.
186
189
  class Utils {
187
190
  static hasNestedObjectInSchema(schema) {
188
- if (schema.type === "object") {
191
+ if (this.isObjectSchema(schema)) {
189
192
  for (const property in schema.properties) {
190
193
  const nestedSchema = schema.properties[property];
191
- if (nestedSchema.type === "object") {
194
+ if (this.isObjectSchema(nestedSchema)) {
192
195
  return true;
193
196
  }
194
197
  }
195
198
  }
196
199
  return false;
197
200
  }
201
+ static isObjectSchema(schema) {
202
+ return schema.type === "object" || (!schema.type && !!schema.properties);
203
+ }
198
204
  static containMultipleMediaTypes(bodyObject) {
199
205
  return Object.keys((bodyObject === null || bodyObject === void 0 ? void 0 : bodyObject.content) || {}).length > 1;
200
206
  }
@@ -256,23 +262,28 @@ class Utils {
256
262
  return str.charAt(0).toUpperCase() + str.slice(1);
257
263
  }
258
264
  static getResponseJson(operationObject, allowMultipleMediaType = false) {
259
- var _a, _b;
265
+ var _a;
260
266
  let json = {};
261
267
  let multipleMediaType = false;
262
268
  for (const code of ConstantString.ResponseCodeFor20X) {
263
269
  const responseObject = (_a = operationObject === null || operationObject === void 0 ? void 0 : operationObject.responses) === null || _a === void 0 ? void 0 : _a[code];
264
- if ((_b = responseObject === null || responseObject === void 0 ? void 0 : responseObject.content) === null || _b === void 0 ? void 0 : _b["application/json"]) {
265
- multipleMediaType = false;
266
- json = responseObject.content["application/json"];
267
- if (Utils.containMultipleMediaTypes(responseObject)) {
268
- multipleMediaType = true;
269
- if (!allowMultipleMediaType) {
270
- json = {};
270
+ if (responseObject === null || responseObject === void 0 ? void 0 : responseObject.content) {
271
+ for (const contentType of Object.keys(responseObject.content)) {
272
+ // json media type can also be "application/json; charset=utf-8"
273
+ if (contentType.indexOf("application/json") >= 0) {
274
+ multipleMediaType = false;
275
+ json = responseObject.content[contentType];
276
+ if (Utils.containMultipleMediaTypes(responseObject)) {
277
+ multipleMediaType = true;
278
+ if (!allowMultipleMediaType) {
279
+ json = {};
280
+ }
281
+ }
282
+ else {
283
+ return { json, multipleMediaType };
284
+ }
271
285
  }
272
286
  }
273
- else {
274
- break;
275
- }
276
287
  }
277
288
  }
278
289
  return { json, multipleMediaType };
@@ -418,7 +429,7 @@ class Utils {
418
429
  optionalParams.push(parameter);
419
430
  }
420
431
  }
421
- else if (schema.type === "object") {
432
+ else if (Utils.isObjectSchema(schema)) {
422
433
  const { properties } = schema;
423
434
  for (const property in properties) {
424
435
  let isRequired = false;
@@ -532,6 +543,29 @@ class Utils {
532
543
  const serverUrl = operationServer || methodServer || rootServer;
533
544
  return serverUrl;
534
545
  }
546
+ static limitACBodyProperties(body, maxCount) {
547
+ const result = [];
548
+ let currentCount = 0;
549
+ for (const element of body) {
550
+ if (element.type === ConstantString.ContainerType) {
551
+ const items = this.limitACBodyProperties(element.items, maxCount - currentCount);
552
+ result.push({
553
+ type: ConstantString.ContainerType,
554
+ $data: element.$data,
555
+ items: items,
556
+ });
557
+ currentCount += items.length;
558
+ }
559
+ else {
560
+ result.push(element);
561
+ currentCount++;
562
+ }
563
+ if (currentCount >= maxCount) {
564
+ break;
565
+ }
566
+ }
567
+ return result;
568
+ }
535
569
  }
536
570
 
537
571
  // Copyright (c) Microsoft Corporation.
@@ -733,7 +767,7 @@ class Validator {
733
767
  }
734
768
  const isRequiredWithoutDefault = isRequired && schema.default === undefined;
735
769
  const isCopilot = this.projectType === ProjectType.Copilot;
736
- if (isCopilot && this.hasNestedObjectInSchema(schema)) {
770
+ if (isCopilot && Utils.hasNestedObjectInSchema(schema)) {
737
771
  paramResult.isValid = false;
738
772
  paramResult.reason = [ErrorType.RequestBodyContainsNestedObject];
739
773
  return paramResult;
@@ -749,7 +783,7 @@ class Validator {
749
783
  paramResult.optionalNum = paramResult.optionalNum + 1;
750
784
  }
751
785
  }
752
- else if (schema.type === "object") {
786
+ else if (Utils.isObjectSchema(schema)) {
753
787
  const { properties } = schema;
754
788
  for (const property in properties) {
755
789
  let isRequired = false;
@@ -785,7 +819,7 @@ class Validator {
785
819
  for (let i = 0; i < paramObject.length; i++) {
786
820
  const param = paramObject[i];
787
821
  const schema = param.schema;
788
- if (isCopilot && this.hasNestedObjectInSchema(schema)) {
822
+ if (isCopilot && Utils.hasNestedObjectInSchema(schema)) {
789
823
  paramResult.isValid = false;
790
824
  paramResult.reason.push(ErrorType.ParamsContainsNestedObject);
791
825
  continue;
@@ -828,17 +862,6 @@ class Validator {
828
862
  }
829
863
  return paramResult;
830
864
  }
831
- hasNestedObjectInSchema(schema) {
832
- if (schema.type === "object") {
833
- for (const property in schema.properties) {
834
- const nestedSchema = schema.properties[property];
835
- if (nestedSchema.type === "object") {
836
- return true;
837
- }
838
- }
839
- }
840
- return false;
841
- }
842
865
  }
843
866
 
844
867
  // Copyright (c) Microsoft Corporation.
@@ -897,7 +920,7 @@ class CopilotValidator extends Validator {
897
920
  const requestJsonBody = requestBody === null || requestBody === void 0 ? void 0 : requestBody.content["application/json"];
898
921
  if (requestJsonBody) {
899
922
  const requestBodySchema = requestJsonBody.schema;
900
- if (requestBodySchema.type !== "object") {
923
+ if (!Utils.isObjectSchema(requestBodySchema)) {
901
924
  result.reason.push(ErrorType.PostBodySchemaIsNotJson);
902
925
  }
903
926
  const requestBodyParamResult = this.checkPostBodySchema(requestBodySchema, requestBody.required);
@@ -1342,7 +1365,7 @@ class AdaptiveCardGenerator {
1342
1365
  return [template];
1343
1366
  }
1344
1367
  // some schema may not contain type but contain properties
1345
- if (schema.type === "object" || (!schema.type && schema.properties)) {
1368
+ if (Utils.isObjectSchema(schema)) {
1346
1369
  const { properties } = schema;
1347
1370
  const result = [];
1348
1371
  for (const property in properties) {
@@ -1388,7 +1411,7 @@ class AdaptiveCardGenerator {
1388
1411
  {
1389
1412
  type: "Image",
1390
1413
  url: `\${${name}}`,
1391
- $when: `\${${name} != null}`,
1414
+ $when: `\${${name} != null && ${name} != ''}`,
1392
1415
  },
1393
1416
  ];
1394
1417
  }
@@ -1397,7 +1420,7 @@ class AdaptiveCardGenerator {
1397
1420
  {
1398
1421
  type: "Image",
1399
1422
  url: "${$data}",
1400
- $when: "${$data != null}",
1423
+ $when: "${$data != null && $data != ''}",
1401
1424
  },
1402
1425
  ];
1403
1426
  }
@@ -1410,7 +1433,7 @@ class AdaptiveCardGenerator {
1410
1433
  }
1411
1434
  // Find the first array property in the response schema object with the well-known name
1412
1435
  static getResponseJsonPathFromSchema(schema) {
1413
- if (schema.type === "object" || (!schema.type && schema.properties)) {
1436
+ if (Utils.isObjectSchema(schema)) {
1414
1437
  const { properties } = schema;
1415
1438
  for (const property in properties) {
1416
1439
  const schema = properties[property];