@microsoft/m365-spec-parser 0.2.3-alpha.c3772a0e8.0 → 0.2.3-alpha.e623f48bd.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 +138 -1
- package/dist/index.esm2017.js.map +1 -1
- package/dist/index.esm2017.mjs +140 -141
- package/dist/index.esm2017.mjs.map +1 -1
- package/dist/index.esm5.js +138 -1
- package/dist/index.esm5.js.map +1 -1
- package/dist/index.node.cjs.js +140 -141
- package/dist/index.node.cjs.js.map +1 -1
- package/dist/src/adaptiveCardGenerator.d.ts +2 -2
- package/package.json +3 -3
package/dist/index.esm2017.js
CHANGED
|
@@ -1277,15 +1277,152 @@ class SpecParser {
|
|
|
1277
1277
|
}
|
|
1278
1278
|
}
|
|
1279
1279
|
|
|
1280
|
+
// Copyright (c) Microsoft Corporation.
|
|
1281
|
+
class JsonDataGenerator {
|
|
1282
|
+
static generate(schema) {
|
|
1283
|
+
return this.generateMockData(schema);
|
|
1284
|
+
}
|
|
1285
|
+
static generateMockData(schema) {
|
|
1286
|
+
if (this.visitedSchemas.has(schema)) {
|
|
1287
|
+
return null; // Prevent circular reference
|
|
1288
|
+
}
|
|
1289
|
+
this.visitedSchemas.add(schema);
|
|
1290
|
+
let result;
|
|
1291
|
+
if (schema.anyOf) {
|
|
1292
|
+
// Select the first schema in anyOf
|
|
1293
|
+
const selectedSchema = schema.anyOf[0];
|
|
1294
|
+
result = this.generateMockData(selectedSchema);
|
|
1295
|
+
}
|
|
1296
|
+
else if (schema.oneOf) {
|
|
1297
|
+
// Select the first schema in oneOf
|
|
1298
|
+
const selectedSchema = schema.oneOf[0];
|
|
1299
|
+
result = this.generateMockData(selectedSchema);
|
|
1300
|
+
}
|
|
1301
|
+
else if (schema.allOf) {
|
|
1302
|
+
// merge all schemas in allOf
|
|
1303
|
+
result = {};
|
|
1304
|
+
for (const subschema of schema.allOf) {
|
|
1305
|
+
const data = this.generateMockData(subschema);
|
|
1306
|
+
result = Object.assign(Object.assign({}, result), data);
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
else {
|
|
1310
|
+
switch (schema.type) {
|
|
1311
|
+
case "string":
|
|
1312
|
+
if (schema.example !== undefined) {
|
|
1313
|
+
result = schema.example;
|
|
1314
|
+
}
|
|
1315
|
+
else if (schema.format) {
|
|
1316
|
+
switch (schema.format) {
|
|
1317
|
+
case "date-time":
|
|
1318
|
+
result = "2024-11-01T05:25:43.593Z";
|
|
1319
|
+
break;
|
|
1320
|
+
case "email":
|
|
1321
|
+
result = "example@example.com";
|
|
1322
|
+
break;
|
|
1323
|
+
case "uuid":
|
|
1324
|
+
result = "123e4567-e89b-12d3-a456-426614174000";
|
|
1325
|
+
break;
|
|
1326
|
+
case "ipv4":
|
|
1327
|
+
result = "192.168.0.1";
|
|
1328
|
+
break;
|
|
1329
|
+
case "ipv6":
|
|
1330
|
+
result = "2001:0db8:85a3:0000:0000:8a2e:0370:7334";
|
|
1331
|
+
break;
|
|
1332
|
+
default:
|
|
1333
|
+
result = "example string";
|
|
1334
|
+
}
|
|
1335
|
+
}
|
|
1336
|
+
else {
|
|
1337
|
+
result = "example string";
|
|
1338
|
+
}
|
|
1339
|
+
break;
|
|
1340
|
+
case "number":
|
|
1341
|
+
if (schema.example !== undefined) {
|
|
1342
|
+
result = schema.example;
|
|
1343
|
+
}
|
|
1344
|
+
else if (schema.format) {
|
|
1345
|
+
switch (schema.format) {
|
|
1346
|
+
case "float":
|
|
1347
|
+
result = 3.14;
|
|
1348
|
+
break;
|
|
1349
|
+
case "double":
|
|
1350
|
+
result = 3.14159;
|
|
1351
|
+
break;
|
|
1352
|
+
default:
|
|
1353
|
+
result = 123;
|
|
1354
|
+
}
|
|
1355
|
+
}
|
|
1356
|
+
else {
|
|
1357
|
+
result = 123;
|
|
1358
|
+
}
|
|
1359
|
+
break;
|
|
1360
|
+
case "integer":
|
|
1361
|
+
if (schema.example !== undefined) {
|
|
1362
|
+
result = schema.example;
|
|
1363
|
+
}
|
|
1364
|
+
else if (schema.format) {
|
|
1365
|
+
switch (schema.format) {
|
|
1366
|
+
case "int32":
|
|
1367
|
+
result = 123456;
|
|
1368
|
+
break;
|
|
1369
|
+
case "int64":
|
|
1370
|
+
result = 123456789;
|
|
1371
|
+
break;
|
|
1372
|
+
default:
|
|
1373
|
+
result = 123;
|
|
1374
|
+
}
|
|
1375
|
+
}
|
|
1376
|
+
else {
|
|
1377
|
+
result = 123;
|
|
1378
|
+
}
|
|
1379
|
+
break;
|
|
1380
|
+
case "boolean":
|
|
1381
|
+
result = schema.example !== undefined ? schema.example : true;
|
|
1382
|
+
break;
|
|
1383
|
+
case "array":
|
|
1384
|
+
result = [this.generateMockData(schema.items)];
|
|
1385
|
+
break;
|
|
1386
|
+
case "object":
|
|
1387
|
+
result = {};
|
|
1388
|
+
if (schema.properties) {
|
|
1389
|
+
for (const key in schema.properties) {
|
|
1390
|
+
result[key] = this.generateMockData(schema.properties[key]);
|
|
1391
|
+
}
|
|
1392
|
+
}
|
|
1393
|
+
break;
|
|
1394
|
+
default:
|
|
1395
|
+
result = schema.example || null;
|
|
1396
|
+
}
|
|
1397
|
+
}
|
|
1398
|
+
this.visitedSchemas.delete(schema);
|
|
1399
|
+
return result;
|
|
1400
|
+
}
|
|
1401
|
+
}
|
|
1402
|
+
JsonDataGenerator.visitedSchemas = new Set();
|
|
1403
|
+
|
|
1280
1404
|
// Copyright (c) Microsoft Corporation.
|
|
1281
1405
|
class AdaptiveCardGenerator {
|
|
1282
1406
|
static generateAdaptiveCard(operationItem, allowMultipleMediaType = false, maxElementCount = Number.MAX_SAFE_INTEGER) {
|
|
1283
1407
|
try {
|
|
1284
1408
|
const { json } = Utils.getResponseJson(operationItem, allowMultipleMediaType);
|
|
1285
1409
|
let cardBody = [];
|
|
1410
|
+
let jsonData = {};
|
|
1411
|
+
const warnings = [];
|
|
1412
|
+
const operationId = operationItem.operationId;
|
|
1286
1413
|
let schema = json.schema;
|
|
1287
1414
|
let jsonPath = "$";
|
|
1288
1415
|
if (schema && Object.keys(schema).length > 0) {
|
|
1416
|
+
try {
|
|
1417
|
+
jsonData = JsonDataGenerator.generate(schema);
|
|
1418
|
+
}
|
|
1419
|
+
catch (err) {
|
|
1420
|
+
warnings.push({
|
|
1421
|
+
type: WarningType.GenerateJsonDataFailed,
|
|
1422
|
+
content: Utils.format(ConstantString.GenerateJsonDataFailed, operationId, err.toString()),
|
|
1423
|
+
data: operationId,
|
|
1424
|
+
});
|
|
1425
|
+
}
|
|
1289
1426
|
jsonPath = AdaptiveCardGenerator.getResponseJsonPathFromSchema(schema);
|
|
1290
1427
|
if (jsonPath !== "$") {
|
|
1291
1428
|
schema = schema.properties[jsonPath];
|
|
@@ -1318,7 +1455,7 @@ class AdaptiveCardGenerator {
|
|
|
1318
1455
|
version: ConstantString.AdaptiveCardVersion,
|
|
1319
1456
|
body: cardBody,
|
|
1320
1457
|
};
|
|
1321
|
-
return [fullCard, jsonPath];
|
|
1458
|
+
return [fullCard, jsonPath, jsonData, warnings];
|
|
1322
1459
|
}
|
|
1323
1460
|
catch (err) {
|
|
1324
1461
|
throw new SpecParserError(err.toString(), ErrorType.GenerateAdaptiveCardFailed);
|