@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.
- package/dist/index.esm2017.js +25 -46
- package/dist/index.esm2017.js.map +1 -1
- package/dist/index.esm2017.mjs +184 -49
- package/dist/index.esm2017.mjs.map +1 -1
- package/dist/index.esm5.js +25 -46
- package/dist/index.esm5.js.map +1 -1
- package/dist/index.node.cjs.js +184 -49
- package/dist/index.node.cjs.js.map +1 -1
- package/dist/src/adaptiveCardGenerator.d.ts +4 -2
- package/dist/src/constants.d.ts +2 -0
- package/dist/src/interfaces.d.ts +2 -0
- package/dist/src/jsonDataGenerator.d.ts +6 -0
- package/dist/src/utils.d.ts +1 -2
- package/package.json +3 -3
package/dist/index.esm2017.js
CHANGED
|
@@ -55,6 +55,8 @@ var WarningType;
|
|
|
55
55
|
WarningType["OperationOnlyContainsOptionalParam"] = "operation-only-contains-optional-param";
|
|
56
56
|
WarningType["ConvertSwaggerToOpenAPI"] = "convert-swagger-to-openapi";
|
|
57
57
|
WarningType["FuncDescriptionTooLong"] = "function-description-too-long";
|
|
58
|
+
WarningType["OperationIdContainsSpecialCharacters"] = "operationid-contains-special-characters";
|
|
59
|
+
WarningType["GenerateJsonDataFailed"] = "generate-json-data-failed";
|
|
58
60
|
WarningType["Unknown"] = "unknown";
|
|
59
61
|
})(WarningType || (WarningType = {}));
|
|
60
62
|
/**
|
|
@@ -100,8 +102,10 @@ ConstantString.ConvertSwaggerToOpenAPI = "The Swagger 2.0 file has been converte
|
|
|
100
102
|
ConstantString.SwaggerNotSupported = "Swagger 2.0 is not supported. Please convert to OpenAPI 3.0 manually before proceeding.";
|
|
101
103
|
ConstantString.SpecVersionNotSupported = "Unsupported OpenAPI version %s. Please use version 3.0.x.";
|
|
102
104
|
ConstantString.MultipleAuthNotSupported = "Multiple authentication methods are unsupported. Ensure all selected APIs use identical authentication.";
|
|
105
|
+
ConstantString.OperationIdContainsSpecialCharacters = "Operation id '%s' in OpenAPI description document contained special characters and was renamed to '%s'.";
|
|
103
106
|
ConstantString.UnsupportedSchema = "Unsupported schema in %s %s: %s";
|
|
104
107
|
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.";
|
|
108
|
+
ConstantString.GenerateJsonDataFailed = "Failed to generate JSON data for api: %s due to %s.";
|
|
105
109
|
ConstantString.WrappedCardVersion = "devPreview";
|
|
106
110
|
ConstantString.WrappedCardSchema = "https://developer.microsoft.com/json-schemas/teams/vDevPreview/MicrosoftTeams.ResponseRenderingTemplate.schema.json";
|
|
107
111
|
ConstantString.WrappedCardResponseLayout = "list";
|
|
@@ -543,29 +547,6 @@ class Utils {
|
|
|
543
547
|
const serverUrl = operationServer || methodServer || rootServer;
|
|
544
548
|
return serverUrl;
|
|
545
549
|
}
|
|
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
|
-
}
|
|
569
550
|
}
|
|
570
551
|
|
|
571
552
|
// Copyright (c) Microsoft Corporation.
|
|
@@ -1298,7 +1279,7 @@ class SpecParser {
|
|
|
1298
1279
|
|
|
1299
1280
|
// Copyright (c) Microsoft Corporation.
|
|
1300
1281
|
class AdaptiveCardGenerator {
|
|
1301
|
-
static generateAdaptiveCard(operationItem, allowMultipleMediaType = false) {
|
|
1282
|
+
static generateAdaptiveCard(operationItem, allowMultipleMediaType = false, maxElementCount = Number.MAX_SAFE_INTEGER) {
|
|
1302
1283
|
try {
|
|
1303
1284
|
const { json } = Utils.getResponseJson(operationItem, allowMultipleMediaType);
|
|
1304
1285
|
let cardBody = [];
|
|
@@ -1309,7 +1290,7 @@ class AdaptiveCardGenerator {
|
|
|
1309
1290
|
if (jsonPath !== "$") {
|
|
1310
1291
|
schema = schema.properties[jsonPath];
|
|
1311
1292
|
}
|
|
1312
|
-
cardBody = AdaptiveCardGenerator.generateCardFromResponse(schema, "");
|
|
1293
|
+
cardBody = AdaptiveCardGenerator.generateCardFromResponse(schema, "", "", maxElementCount);
|
|
1313
1294
|
}
|
|
1314
1295
|
// if no schema, try to use example value
|
|
1315
1296
|
if (cardBody.length === 0 && (json.examples || json.example)) {
|
|
@@ -1343,10 +1324,14 @@ class AdaptiveCardGenerator {
|
|
|
1343
1324
|
throw new SpecParserError(err.toString(), ErrorType.GenerateAdaptiveCardFailed);
|
|
1344
1325
|
}
|
|
1345
1326
|
}
|
|
1346
|
-
static generateCardFromResponse(schema, name, parentArrayName = "") {
|
|
1327
|
+
static generateCardFromResponse(schema, name, parentArrayName = "", maxElementCount = Number.MAX_SAFE_INTEGER, counter = { count: 0 }) {
|
|
1328
|
+
if (counter.count >= maxElementCount) {
|
|
1329
|
+
return [];
|
|
1330
|
+
}
|
|
1347
1331
|
if (schema.type === "array") {
|
|
1348
1332
|
// schema.items can be arbitrary object: schema { type: array, items: {} }
|
|
1349
1333
|
if (Object.keys(schema.items).length === 0) {
|
|
1334
|
+
counter.count++;
|
|
1350
1335
|
return [
|
|
1351
1336
|
{
|
|
1352
1337
|
type: ConstantString.TextBlockType,
|
|
@@ -1355,7 +1340,7 @@ class AdaptiveCardGenerator {
|
|
|
1355
1340
|
},
|
|
1356
1341
|
];
|
|
1357
1342
|
}
|
|
1358
|
-
const obj = AdaptiveCardGenerator.generateCardFromResponse(schema.items, "", name);
|
|
1343
|
+
const obj = AdaptiveCardGenerator.generateCardFromResponse(schema.items, "", name, maxElementCount, counter);
|
|
1359
1344
|
const template = {
|
|
1360
1345
|
type: ConstantString.ContainerType,
|
|
1361
1346
|
$data: name ? `\${${name}}` : "${$root}",
|
|
@@ -1369,7 +1354,7 @@ class AdaptiveCardGenerator {
|
|
|
1369
1354
|
const { properties } = schema;
|
|
1370
1355
|
const result = [];
|
|
1371
1356
|
for (const property in properties) {
|
|
1372
|
-
const obj = AdaptiveCardGenerator.generateCardFromResponse(properties[property], name ? `${name}.${property}` : property, parentArrayName);
|
|
1357
|
+
const obj = AdaptiveCardGenerator.generateCardFromResponse(properties[property], name ? `${name}.${property}` : property, parentArrayName, maxElementCount, counter);
|
|
1373
1358
|
result.push(...obj);
|
|
1374
1359
|
}
|
|
1375
1360
|
if (schema.additionalProperties) {
|
|
@@ -1382,6 +1367,7 @@ class AdaptiveCardGenerator {
|
|
|
1382
1367
|
schema.type === "integer" ||
|
|
1383
1368
|
schema.type === "boolean" ||
|
|
1384
1369
|
schema.type === "number") {
|
|
1370
|
+
counter.count++;
|
|
1385
1371
|
if (!AdaptiveCardGenerator.isImageUrlProperty(schema, name, parentArrayName)) {
|
|
1386
1372
|
// string in root: "ddd"
|
|
1387
1373
|
let text = "result: ${$root}";
|
|
@@ -1406,24 +1392,17 @@ class AdaptiveCardGenerator {
|
|
|
1406
1392
|
];
|
|
1407
1393
|
}
|
|
1408
1394
|
else {
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
{
|
|
1421
|
-
type: "Image",
|
|
1422
|
-
url: "${$data}",
|
|
1423
|
-
$when: "${$data != null && $data != ''}",
|
|
1424
|
-
},
|
|
1425
|
-
];
|
|
1426
|
-
}
|
|
1395
|
+
const url = name ? `\${${name}}` : "${$data}";
|
|
1396
|
+
const condition = name
|
|
1397
|
+
? `\${${name} != null && ${name} != ''}`
|
|
1398
|
+
: "${$data != null && $data != ''}";
|
|
1399
|
+
return [
|
|
1400
|
+
{
|
|
1401
|
+
type: "Image",
|
|
1402
|
+
url,
|
|
1403
|
+
$when: condition,
|
|
1404
|
+
},
|
|
1405
|
+
];
|
|
1427
1406
|
}
|
|
1428
1407
|
}
|
|
1429
1408
|
if (schema.oneOf || schema.anyOf || schema.not || schema.allOf) {
|