@microsoft/m365-spec-parser 0.2.3-alpha.9432e5ed4.0 → 0.2.3-alpha.9aa2f037e.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.
@@ -85,6 +85,8 @@ var WarningType;
85
85
  WarningType["OperationOnlyContainsOptionalParam"] = "operation-only-contains-optional-param";
86
86
  WarningType["ConvertSwaggerToOpenAPI"] = "convert-swagger-to-openapi";
87
87
  WarningType["FuncDescriptionTooLong"] = "function-description-too-long";
88
+ WarningType["OperationIdContainsSpecialCharacters"] = "operationid-contains-special-characters";
89
+ WarningType["GenerateJsonDataFailed"] = "generate-json-data-failed";
88
90
  WarningType["Unknown"] = "unknown";
89
91
  })(WarningType || (WarningType = {}));
90
92
  /**
@@ -130,8 +132,10 @@ ConstantString.ConvertSwaggerToOpenAPI = "The Swagger 2.0 file has been converte
130
132
  ConstantString.SwaggerNotSupported = "Swagger 2.0 is not supported. Please convert to OpenAPI 3.0 manually before proceeding.";
131
133
  ConstantString.SpecVersionNotSupported = "Unsupported OpenAPI version %s. Please use version 3.0.x.";
132
134
  ConstantString.MultipleAuthNotSupported = "Multiple authentication methods are unsupported. Ensure all selected APIs use identical authentication.";
135
+ ConstantString.OperationIdContainsSpecialCharacters = "Operation id '%s' in OpenAPI description document contained special characters and was renamed to '%s'.";
133
136
  ConstantString.UnsupportedSchema = "Unsupported schema in %s %s: %s";
134
137
  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.";
138
+ ConstantString.GenerateJsonDataFailed = "Failed to generate JSON data for api: %s due to %s.";
135
139
  ConstantString.WrappedCardVersion = "devPreview";
136
140
  ConstantString.WrappedCardSchema = "https://developer.microsoft.com/json-schemas/teams/vDevPreview/MicrosoftTeams.ResponseRenderingTemplate.schema.json";
137
141
  ConstantString.WrappedCardResponseLayout = "list";
@@ -573,29 +577,6 @@ class Utils {
573
577
  const serverUrl = operationServer || methodServer || rootServer;
574
578
  return serverUrl;
575
579
  }
576
- static limitACBodyProperties(body, maxCount) {
577
- const result = [];
578
- let currentCount = 0;
579
- for (const element of body) {
580
- if (element.type === ConstantString.ContainerType) {
581
- const items = this.limitACBodyProperties(element.items, maxCount - currentCount);
582
- result.push({
583
- type: ConstantString.ContainerType,
584
- $data: element.$data,
585
- items: items,
586
- });
587
- currentCount += items.length;
588
- }
589
- else {
590
- result.push(element);
591
- currentCount++;
592
- }
593
- if (currentCount >= maxCount) {
594
- break;
595
- }
596
- }
597
- return result;
598
- }
599
580
  }
600
581
 
601
582
  // Copyright (c) Microsoft Corporation.
@@ -1342,7 +1323,7 @@ class SpecParser {
1342
1323
 
1343
1324
  // Copyright (c) Microsoft Corporation.
1344
1325
  class AdaptiveCardGenerator {
1345
- static generateAdaptiveCard(operationItem, allowMultipleMediaType = false) {
1326
+ static generateAdaptiveCard(operationItem, allowMultipleMediaType = false, maxElementCount = Number.MAX_SAFE_INTEGER) {
1346
1327
  try {
1347
1328
  const { json } = Utils.getResponseJson(operationItem, allowMultipleMediaType);
1348
1329
  let cardBody = [];
@@ -1353,7 +1334,7 @@ class AdaptiveCardGenerator {
1353
1334
  if (jsonPath !== "$") {
1354
1335
  schema = schema.properties[jsonPath];
1355
1336
  }
1356
- cardBody = AdaptiveCardGenerator.generateCardFromResponse(schema, "");
1337
+ cardBody = AdaptiveCardGenerator.generateCardFromResponse(schema, "", "", maxElementCount);
1357
1338
  }
1358
1339
  // if no schema, try to use example value
1359
1340
  if (cardBody.length === 0 && (json.examples || json.example)) {
@@ -1387,10 +1368,14 @@ class AdaptiveCardGenerator {
1387
1368
  throw new SpecParserError(err.toString(), ErrorType.GenerateAdaptiveCardFailed);
1388
1369
  }
1389
1370
  }
1390
- static generateCardFromResponse(schema, name, parentArrayName = "") {
1371
+ static generateCardFromResponse(schema, name, parentArrayName = "", maxElementCount = Number.MAX_SAFE_INTEGER, counter = { count: 0 }) {
1372
+ if (counter.count >= maxElementCount) {
1373
+ return [];
1374
+ }
1391
1375
  if (schema.type === "array") {
1392
1376
  // schema.items can be arbitrary object: schema { type: array, items: {} }
1393
1377
  if (Object.keys(schema.items).length === 0) {
1378
+ counter.count++;
1394
1379
  return [
1395
1380
  {
1396
1381
  type: ConstantString.TextBlockType,
@@ -1399,7 +1384,7 @@ class AdaptiveCardGenerator {
1399
1384
  },
1400
1385
  ];
1401
1386
  }
1402
- const obj = AdaptiveCardGenerator.generateCardFromResponse(schema.items, "", name);
1387
+ const obj = AdaptiveCardGenerator.generateCardFromResponse(schema.items, "", name, maxElementCount, counter);
1403
1388
  const template = {
1404
1389
  type: ConstantString.ContainerType,
1405
1390
  $data: name ? `\${${name}}` : "${$root}",
@@ -1413,7 +1398,7 @@ class AdaptiveCardGenerator {
1413
1398
  const { properties } = schema;
1414
1399
  const result = [];
1415
1400
  for (const property in properties) {
1416
- const obj = AdaptiveCardGenerator.generateCardFromResponse(properties[property], name ? `${name}.${property}` : property, parentArrayName);
1401
+ const obj = AdaptiveCardGenerator.generateCardFromResponse(properties[property], name ? `${name}.${property}` : property, parentArrayName, maxElementCount, counter);
1417
1402
  result.push(...obj);
1418
1403
  }
1419
1404
  if (schema.additionalProperties) {
@@ -1426,6 +1411,7 @@ class AdaptiveCardGenerator {
1426
1411
  schema.type === "integer" ||
1427
1412
  schema.type === "boolean" ||
1428
1413
  schema.type === "number") {
1414
+ counter.count++;
1429
1415
  if (!AdaptiveCardGenerator.isImageUrlProperty(schema, name, parentArrayName)) {
1430
1416
  // string in root: "ddd"
1431
1417
  let text = "result: ${$root}";
@@ -1450,24 +1436,17 @@ class AdaptiveCardGenerator {
1450
1436
  ];
1451
1437
  }
1452
1438
  else {
1453
- if (name) {
1454
- return [
1455
- {
1456
- type: "Image",
1457
- url: `\${${name}}`,
1458
- $when: `\${${name} != null && ${name} != ''}`,
1459
- },
1460
- ];
1461
- }
1462
- else {
1463
- return [
1464
- {
1465
- type: "Image",
1466
- url: "${$data}",
1467
- $when: "${$data != null && $data != ''}",
1468
- },
1469
- ];
1470
- }
1439
+ const url = name ? `\${${name}}` : "${$data}";
1440
+ const condition = name
1441
+ ? `\${${name} != null && ${name} != ''}`
1442
+ : "${$data != null && $data != ''}";
1443
+ return [
1444
+ {
1445
+ type: "Image",
1446
+ url,
1447
+ $when: condition,
1448
+ },
1449
+ ];
1471
1450
  }
1472
1451
  }
1473
1452
  if (schema.oneOf || schema.anyOf || schema.not || schema.allOf) {