@microsoft/m365-spec-parser 0.2.2-rc.0 → 0.2.3-alpha.2269ef021.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 +23 -46
- package/dist/index.esm2017.js.map +1 -1
- package/dist/index.esm2017.mjs +67 -58
- package/dist/index.esm2017.mjs.map +1 -1
- package/dist/index.esm5.js +23 -46
- package/dist/index.esm5.js.map +1 -1
- package/dist/index.node.cjs.js +67 -58
- package/dist/index.node.cjs.js.map +1 -1
- package/dist/src/adaptiveCardGenerator.d.ts +4 -2
- package/dist/src/constants.d.ts +1 -0
- package/dist/src/interfaces.d.ts +1 -0
- package/dist/src/utils.d.ts +1 -2
- package/package.json +3 -3
package/dist/index.esm2017.js
CHANGED
|
@@ -55,6 +55,7 @@ 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";
|
|
58
59
|
WarningType["Unknown"] = "unknown";
|
|
59
60
|
})(WarningType || (WarningType = {}));
|
|
60
61
|
/**
|
|
@@ -100,6 +101,7 @@ ConstantString.ConvertSwaggerToOpenAPI = "The Swagger 2.0 file has been converte
|
|
|
100
101
|
ConstantString.SwaggerNotSupported = "Swagger 2.0 is not supported. Please convert to OpenAPI 3.0 manually before proceeding.";
|
|
101
102
|
ConstantString.SpecVersionNotSupported = "Unsupported OpenAPI version %s. Please use version 3.0.x.";
|
|
102
103
|
ConstantString.MultipleAuthNotSupported = "Multiple authentication methods are unsupported. Ensure all selected APIs use identical authentication.";
|
|
104
|
+
ConstantString.OperationIdContainsSpecialCharacters = "Operation id '%s' in OpenAPI description document contained special characters and was renamed to '%s'.";
|
|
103
105
|
ConstantString.UnsupportedSchema = "Unsupported schema in %s %s: %s";
|
|
104
106
|
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.";
|
|
105
107
|
ConstantString.WrappedCardVersion = "devPreview";
|
|
@@ -543,29 +545,6 @@ class Utils {
|
|
|
543
545
|
const serverUrl = operationServer || methodServer || rootServer;
|
|
544
546
|
return serverUrl;
|
|
545
547
|
}
|
|
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
548
|
}
|
|
570
549
|
|
|
571
550
|
// Copyright (c) Microsoft Corporation.
|
|
@@ -1298,7 +1277,7 @@ class SpecParser {
|
|
|
1298
1277
|
|
|
1299
1278
|
// Copyright (c) Microsoft Corporation.
|
|
1300
1279
|
class AdaptiveCardGenerator {
|
|
1301
|
-
static generateAdaptiveCard(operationItem, allowMultipleMediaType = false) {
|
|
1280
|
+
static generateAdaptiveCard(operationItem, allowMultipleMediaType = false, maxElementCount = Number.MAX_SAFE_INTEGER) {
|
|
1302
1281
|
try {
|
|
1303
1282
|
const { json } = Utils.getResponseJson(operationItem, allowMultipleMediaType);
|
|
1304
1283
|
let cardBody = [];
|
|
@@ -1309,7 +1288,7 @@ class AdaptiveCardGenerator {
|
|
|
1309
1288
|
if (jsonPath !== "$") {
|
|
1310
1289
|
schema = schema.properties[jsonPath];
|
|
1311
1290
|
}
|
|
1312
|
-
cardBody = AdaptiveCardGenerator.generateCardFromResponse(schema, "");
|
|
1291
|
+
cardBody = AdaptiveCardGenerator.generateCardFromResponse(schema, "", "", maxElementCount);
|
|
1313
1292
|
}
|
|
1314
1293
|
// if no schema, try to use example value
|
|
1315
1294
|
if (cardBody.length === 0 && (json.examples || json.example)) {
|
|
@@ -1343,10 +1322,14 @@ class AdaptiveCardGenerator {
|
|
|
1343
1322
|
throw new SpecParserError(err.toString(), ErrorType.GenerateAdaptiveCardFailed);
|
|
1344
1323
|
}
|
|
1345
1324
|
}
|
|
1346
|
-
static generateCardFromResponse(schema, name, parentArrayName = "") {
|
|
1325
|
+
static generateCardFromResponse(schema, name, parentArrayName = "", maxElementCount = Number.MAX_SAFE_INTEGER, counter = { count: 0 }) {
|
|
1326
|
+
if (counter.count >= maxElementCount) {
|
|
1327
|
+
return [];
|
|
1328
|
+
}
|
|
1347
1329
|
if (schema.type === "array") {
|
|
1348
1330
|
// schema.items can be arbitrary object: schema { type: array, items: {} }
|
|
1349
1331
|
if (Object.keys(schema.items).length === 0) {
|
|
1332
|
+
counter.count++;
|
|
1350
1333
|
return [
|
|
1351
1334
|
{
|
|
1352
1335
|
type: ConstantString.TextBlockType,
|
|
@@ -1355,7 +1338,7 @@ class AdaptiveCardGenerator {
|
|
|
1355
1338
|
},
|
|
1356
1339
|
];
|
|
1357
1340
|
}
|
|
1358
|
-
const obj = AdaptiveCardGenerator.generateCardFromResponse(schema.items, "", name);
|
|
1341
|
+
const obj = AdaptiveCardGenerator.generateCardFromResponse(schema.items, "", name, maxElementCount, counter);
|
|
1359
1342
|
const template = {
|
|
1360
1343
|
type: ConstantString.ContainerType,
|
|
1361
1344
|
$data: name ? `\${${name}}` : "${$root}",
|
|
@@ -1369,7 +1352,7 @@ class AdaptiveCardGenerator {
|
|
|
1369
1352
|
const { properties } = schema;
|
|
1370
1353
|
const result = [];
|
|
1371
1354
|
for (const property in properties) {
|
|
1372
|
-
const obj = AdaptiveCardGenerator.generateCardFromResponse(properties[property], name ? `${name}.${property}` : property, parentArrayName);
|
|
1355
|
+
const obj = AdaptiveCardGenerator.generateCardFromResponse(properties[property], name ? `${name}.${property}` : property, parentArrayName, maxElementCount, counter);
|
|
1373
1356
|
result.push(...obj);
|
|
1374
1357
|
}
|
|
1375
1358
|
if (schema.additionalProperties) {
|
|
@@ -1382,6 +1365,7 @@ class AdaptiveCardGenerator {
|
|
|
1382
1365
|
schema.type === "integer" ||
|
|
1383
1366
|
schema.type === "boolean" ||
|
|
1384
1367
|
schema.type === "number") {
|
|
1368
|
+
counter.count++;
|
|
1385
1369
|
if (!AdaptiveCardGenerator.isImageUrlProperty(schema, name, parentArrayName)) {
|
|
1386
1370
|
// string in root: "ddd"
|
|
1387
1371
|
let text = "result: ${$root}";
|
|
@@ -1406,24 +1390,17 @@ class AdaptiveCardGenerator {
|
|
|
1406
1390
|
];
|
|
1407
1391
|
}
|
|
1408
1392
|
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
|
-
}
|
|
1393
|
+
const url = name ? `\${${name}}` : "${$data}";
|
|
1394
|
+
const condition = name
|
|
1395
|
+
? `\${${name} != null && ${name} != ''}`
|
|
1396
|
+
: "${$data != null && $data != ''}";
|
|
1397
|
+
return [
|
|
1398
|
+
{
|
|
1399
|
+
type: "Image",
|
|
1400
|
+
url,
|
|
1401
|
+
$when: condition,
|
|
1402
|
+
},
|
|
1403
|
+
];
|
|
1427
1404
|
}
|
|
1428
1405
|
}
|
|
1429
1406
|
if (schema.oneOf || schema.anyOf || schema.not || schema.allOf) {
|