@microsoft/m365-spec-parser 0.2.2-alpha.0921562c9.0 → 0.2.2-alpha.0febdaee8.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;
@@ -546,10 +557,11 @@ class Utils {
546
557
  currentCount += items.length;
547
558
  }
548
559
  else {
549
- if (currentCount < maxCount) {
550
- result.push(element);
551
- currentCount++;
552
- }
560
+ result.push(element);
561
+ currentCount++;
562
+ }
563
+ if (currentCount >= maxCount) {
564
+ break;
553
565
  }
554
566
  }
555
567
  return result;
@@ -755,7 +767,7 @@ class Validator {
755
767
  }
756
768
  const isRequiredWithoutDefault = isRequired && schema.default === undefined;
757
769
  const isCopilot = this.projectType === ProjectType.Copilot;
758
- if (isCopilot && this.hasNestedObjectInSchema(schema)) {
770
+ if (isCopilot && Utils.hasNestedObjectInSchema(schema)) {
759
771
  paramResult.isValid = false;
760
772
  paramResult.reason = [ErrorType.RequestBodyContainsNestedObject];
761
773
  return paramResult;
@@ -771,7 +783,7 @@ class Validator {
771
783
  paramResult.optionalNum = paramResult.optionalNum + 1;
772
784
  }
773
785
  }
774
- else if (schema.type === "object") {
786
+ else if (Utils.isObjectSchema(schema)) {
775
787
  const { properties } = schema;
776
788
  for (const property in properties) {
777
789
  let isRequired = false;
@@ -807,7 +819,7 @@ class Validator {
807
819
  for (let i = 0; i < paramObject.length; i++) {
808
820
  const param = paramObject[i];
809
821
  const schema = param.schema;
810
- if (isCopilot && this.hasNestedObjectInSchema(schema)) {
822
+ if (isCopilot && Utils.hasNestedObjectInSchema(schema)) {
811
823
  paramResult.isValid = false;
812
824
  paramResult.reason.push(ErrorType.ParamsContainsNestedObject);
813
825
  continue;
@@ -850,17 +862,6 @@ class Validator {
850
862
  }
851
863
  return paramResult;
852
864
  }
853
- hasNestedObjectInSchema(schema) {
854
- if (schema.type === "object") {
855
- for (const property in schema.properties) {
856
- const nestedSchema = schema.properties[property];
857
- if (nestedSchema.type === "object") {
858
- return true;
859
- }
860
- }
861
- }
862
- return false;
863
- }
864
865
  }
865
866
 
866
867
  // Copyright (c) Microsoft Corporation.
@@ -919,7 +920,7 @@ class CopilotValidator extends Validator {
919
920
  const requestJsonBody = requestBody === null || requestBody === void 0 ? void 0 : requestBody.content["application/json"];
920
921
  if (requestJsonBody) {
921
922
  const requestBodySchema = requestJsonBody.schema;
922
- if (requestBodySchema.type !== "object") {
923
+ if (!Utils.isObjectSchema(requestBodySchema)) {
923
924
  result.reason.push(ErrorType.PostBodySchemaIsNotJson);
924
925
  }
925
926
  const requestBodyParamResult = this.checkPostBodySchema(requestBodySchema, requestBody.required);
@@ -1364,7 +1365,7 @@ class AdaptiveCardGenerator {
1364
1365
  return [template];
1365
1366
  }
1366
1367
  // some schema may not contain type but contain properties
1367
- if (schema.type === "object" || (!schema.type && schema.properties)) {
1368
+ if (Utils.isObjectSchema(schema)) {
1368
1369
  const { properties } = schema;
1369
1370
  const result = [];
1370
1371
  for (const property in properties) {
@@ -1410,7 +1411,7 @@ class AdaptiveCardGenerator {
1410
1411
  {
1411
1412
  type: "Image",
1412
1413
  url: `\${${name}}`,
1413
- $when: `\${${name} != null}`,
1414
+ $when: `\${${name} != null && ${name} != ''}`,
1414
1415
  },
1415
1416
  ];
1416
1417
  }
@@ -1419,7 +1420,7 @@ class AdaptiveCardGenerator {
1419
1420
  {
1420
1421
  type: "Image",
1421
1422
  url: "${$data}",
1422
- $when: "${$data != null}",
1423
+ $when: "${$data != null && $data != ''}",
1423
1424
  },
1424
1425
  ];
1425
1426
  }
@@ -1432,7 +1433,7 @@ class AdaptiveCardGenerator {
1432
1433
  }
1433
1434
  // Find the first array property in the response schema object with the well-known name
1434
1435
  static getResponseJsonPathFromSchema(schema) {
1435
- if (schema.type === "object" || (!schema.type && schema.properties)) {
1436
+ if (Utils.isObjectSchema(schema)) {
1436
1437
  const { properties } = schema;
1437
1438
  for (const property in properties) {
1438
1439
  const schema = properties[property];