@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.node.cjs.js
CHANGED
|
@@ -1327,15 +1327,152 @@ class SpecFilter {
|
|
|
1327
1327
|
}
|
|
1328
1328
|
}
|
|
1329
1329
|
|
|
1330
|
+
// Copyright (c) Microsoft Corporation.
|
|
1331
|
+
class JsonDataGenerator {
|
|
1332
|
+
static generate(schema) {
|
|
1333
|
+
return this.generateMockData(schema);
|
|
1334
|
+
}
|
|
1335
|
+
static generateMockData(schema) {
|
|
1336
|
+
if (this.visitedSchemas.has(schema)) {
|
|
1337
|
+
return null; // Prevent circular reference
|
|
1338
|
+
}
|
|
1339
|
+
this.visitedSchemas.add(schema);
|
|
1340
|
+
let result;
|
|
1341
|
+
if (schema.anyOf) {
|
|
1342
|
+
// Select the first schema in anyOf
|
|
1343
|
+
const selectedSchema = schema.anyOf[0];
|
|
1344
|
+
result = this.generateMockData(selectedSchema);
|
|
1345
|
+
}
|
|
1346
|
+
else if (schema.oneOf) {
|
|
1347
|
+
// Select the first schema in oneOf
|
|
1348
|
+
const selectedSchema = schema.oneOf[0];
|
|
1349
|
+
result = this.generateMockData(selectedSchema);
|
|
1350
|
+
}
|
|
1351
|
+
else if (schema.allOf) {
|
|
1352
|
+
// merge all schemas in allOf
|
|
1353
|
+
result = {};
|
|
1354
|
+
for (const subschema of schema.allOf) {
|
|
1355
|
+
const data = this.generateMockData(subschema);
|
|
1356
|
+
result = Object.assign(Object.assign({}, result), data);
|
|
1357
|
+
}
|
|
1358
|
+
}
|
|
1359
|
+
else {
|
|
1360
|
+
switch (schema.type) {
|
|
1361
|
+
case "string":
|
|
1362
|
+
if (schema.example !== undefined) {
|
|
1363
|
+
result = schema.example;
|
|
1364
|
+
}
|
|
1365
|
+
else if (schema.format) {
|
|
1366
|
+
switch (schema.format) {
|
|
1367
|
+
case "date-time":
|
|
1368
|
+
result = "2024-11-01T05:25:43.593Z";
|
|
1369
|
+
break;
|
|
1370
|
+
case "email":
|
|
1371
|
+
result = "example@example.com";
|
|
1372
|
+
break;
|
|
1373
|
+
case "uuid":
|
|
1374
|
+
result = "123e4567-e89b-12d3-a456-426614174000";
|
|
1375
|
+
break;
|
|
1376
|
+
case "ipv4":
|
|
1377
|
+
result = "192.168.0.1";
|
|
1378
|
+
break;
|
|
1379
|
+
case "ipv6":
|
|
1380
|
+
result = "2001:0db8:85a3:0000:0000:8a2e:0370:7334";
|
|
1381
|
+
break;
|
|
1382
|
+
default:
|
|
1383
|
+
result = "example string";
|
|
1384
|
+
}
|
|
1385
|
+
}
|
|
1386
|
+
else {
|
|
1387
|
+
result = "example string";
|
|
1388
|
+
}
|
|
1389
|
+
break;
|
|
1390
|
+
case "number":
|
|
1391
|
+
if (schema.example !== undefined) {
|
|
1392
|
+
result = schema.example;
|
|
1393
|
+
}
|
|
1394
|
+
else if (schema.format) {
|
|
1395
|
+
switch (schema.format) {
|
|
1396
|
+
case "float":
|
|
1397
|
+
result = 3.14;
|
|
1398
|
+
break;
|
|
1399
|
+
case "double":
|
|
1400
|
+
result = 3.14159;
|
|
1401
|
+
break;
|
|
1402
|
+
default:
|
|
1403
|
+
result = 123;
|
|
1404
|
+
}
|
|
1405
|
+
}
|
|
1406
|
+
else {
|
|
1407
|
+
result = 123;
|
|
1408
|
+
}
|
|
1409
|
+
break;
|
|
1410
|
+
case "integer":
|
|
1411
|
+
if (schema.example !== undefined) {
|
|
1412
|
+
result = schema.example;
|
|
1413
|
+
}
|
|
1414
|
+
else if (schema.format) {
|
|
1415
|
+
switch (schema.format) {
|
|
1416
|
+
case "int32":
|
|
1417
|
+
result = 123456;
|
|
1418
|
+
break;
|
|
1419
|
+
case "int64":
|
|
1420
|
+
result = 123456789;
|
|
1421
|
+
break;
|
|
1422
|
+
default:
|
|
1423
|
+
result = 123;
|
|
1424
|
+
}
|
|
1425
|
+
}
|
|
1426
|
+
else {
|
|
1427
|
+
result = 123;
|
|
1428
|
+
}
|
|
1429
|
+
break;
|
|
1430
|
+
case "boolean":
|
|
1431
|
+
result = schema.example !== undefined ? schema.example : true;
|
|
1432
|
+
break;
|
|
1433
|
+
case "array":
|
|
1434
|
+
result = [this.generateMockData(schema.items)];
|
|
1435
|
+
break;
|
|
1436
|
+
case "object":
|
|
1437
|
+
result = {};
|
|
1438
|
+
if (schema.properties) {
|
|
1439
|
+
for (const key in schema.properties) {
|
|
1440
|
+
result[key] = this.generateMockData(schema.properties[key]);
|
|
1441
|
+
}
|
|
1442
|
+
}
|
|
1443
|
+
break;
|
|
1444
|
+
default:
|
|
1445
|
+
result = schema.example || null;
|
|
1446
|
+
}
|
|
1447
|
+
}
|
|
1448
|
+
this.visitedSchemas.delete(schema);
|
|
1449
|
+
return result;
|
|
1450
|
+
}
|
|
1451
|
+
}
|
|
1452
|
+
JsonDataGenerator.visitedSchemas = new Set();
|
|
1453
|
+
|
|
1330
1454
|
// Copyright (c) Microsoft Corporation.
|
|
1331
1455
|
class AdaptiveCardGenerator {
|
|
1332
1456
|
static generateAdaptiveCard(operationItem, allowMultipleMediaType = false, maxElementCount = Number.MAX_SAFE_INTEGER) {
|
|
1333
1457
|
try {
|
|
1334
1458
|
const { json } = Utils.getResponseJson(operationItem, allowMultipleMediaType);
|
|
1335
1459
|
let cardBody = [];
|
|
1460
|
+
let jsonData = {};
|
|
1461
|
+
const warnings = [];
|
|
1462
|
+
const operationId = operationItem.operationId;
|
|
1336
1463
|
let schema = json.schema;
|
|
1337
1464
|
let jsonPath = "$";
|
|
1338
1465
|
if (schema && Object.keys(schema).length > 0) {
|
|
1466
|
+
try {
|
|
1467
|
+
jsonData = JsonDataGenerator.generate(schema);
|
|
1468
|
+
}
|
|
1469
|
+
catch (err) {
|
|
1470
|
+
warnings.push({
|
|
1471
|
+
type: exports.WarningType.GenerateJsonDataFailed,
|
|
1472
|
+
content: Utils.format(ConstantString.GenerateJsonDataFailed, operationId, err.toString()),
|
|
1473
|
+
data: operationId,
|
|
1474
|
+
});
|
|
1475
|
+
}
|
|
1339
1476
|
jsonPath = AdaptiveCardGenerator.getResponseJsonPathFromSchema(schema);
|
|
1340
1477
|
if (jsonPath !== "$") {
|
|
1341
1478
|
schema = schema.properties[jsonPath];
|
|
@@ -1368,7 +1505,7 @@ class AdaptiveCardGenerator {
|
|
|
1368
1505
|
version: ConstantString.AdaptiveCardVersion,
|
|
1369
1506
|
body: cardBody,
|
|
1370
1507
|
};
|
|
1371
|
-
return [fullCard, jsonPath];
|
|
1508
|
+
return [fullCard, jsonPath, jsonData, warnings];
|
|
1372
1509
|
}
|
|
1373
1510
|
catch (err) {
|
|
1374
1511
|
throw new SpecParserError(err.toString(), exports.ErrorType.GenerateAdaptiveCardFailed);
|
|
@@ -1983,130 +2120,6 @@ class ManifestUpdater {
|
|
|
1983
2120
|
}
|
|
1984
2121
|
}
|
|
1985
2122
|
|
|
1986
|
-
// Copyright (c) Microsoft Corporation.
|
|
1987
|
-
class JsonDataGenerator {
|
|
1988
|
-
static generate(schema) {
|
|
1989
|
-
return this.generateMockData(schema);
|
|
1990
|
-
}
|
|
1991
|
-
static generateMockData(schema) {
|
|
1992
|
-
if (this.visitedSchemas.has(schema)) {
|
|
1993
|
-
return null; // Prevent circular reference
|
|
1994
|
-
}
|
|
1995
|
-
this.visitedSchemas.add(schema);
|
|
1996
|
-
let result;
|
|
1997
|
-
if (schema.anyOf) {
|
|
1998
|
-
// Select the first schema in anyOf
|
|
1999
|
-
const selectedSchema = schema.anyOf[0];
|
|
2000
|
-
result = this.generateMockData(selectedSchema);
|
|
2001
|
-
}
|
|
2002
|
-
else if (schema.oneOf) {
|
|
2003
|
-
// Select the first schema in oneOf
|
|
2004
|
-
const selectedSchema = schema.oneOf[0];
|
|
2005
|
-
result = this.generateMockData(selectedSchema);
|
|
2006
|
-
}
|
|
2007
|
-
else if (schema.allOf) {
|
|
2008
|
-
// merge all schemas in allOf
|
|
2009
|
-
result = {};
|
|
2010
|
-
for (const subschema of schema.allOf) {
|
|
2011
|
-
const data = this.generateMockData(subschema);
|
|
2012
|
-
result = Object.assign(Object.assign({}, result), data);
|
|
2013
|
-
}
|
|
2014
|
-
}
|
|
2015
|
-
else {
|
|
2016
|
-
switch (schema.type) {
|
|
2017
|
-
case "string":
|
|
2018
|
-
if (schema.example !== undefined) {
|
|
2019
|
-
result = schema.example;
|
|
2020
|
-
}
|
|
2021
|
-
else if (schema.format) {
|
|
2022
|
-
switch (schema.format) {
|
|
2023
|
-
case "date-time":
|
|
2024
|
-
result = "2024-11-01T05:25:43.593Z";
|
|
2025
|
-
break;
|
|
2026
|
-
case "email":
|
|
2027
|
-
result = "example@example.com";
|
|
2028
|
-
break;
|
|
2029
|
-
case "uuid":
|
|
2030
|
-
result = "123e4567-e89b-12d3-a456-426614174000";
|
|
2031
|
-
break;
|
|
2032
|
-
case "ipv4":
|
|
2033
|
-
result = "192.168.0.1";
|
|
2034
|
-
break;
|
|
2035
|
-
case "ipv6":
|
|
2036
|
-
result = "2001:0db8:85a3:0000:0000:8a2e:0370:7334";
|
|
2037
|
-
break;
|
|
2038
|
-
default:
|
|
2039
|
-
result = "example string";
|
|
2040
|
-
}
|
|
2041
|
-
}
|
|
2042
|
-
else {
|
|
2043
|
-
result = "example string";
|
|
2044
|
-
}
|
|
2045
|
-
break;
|
|
2046
|
-
case "number":
|
|
2047
|
-
if (schema.example !== undefined) {
|
|
2048
|
-
result = schema.example;
|
|
2049
|
-
}
|
|
2050
|
-
else if (schema.format) {
|
|
2051
|
-
switch (schema.format) {
|
|
2052
|
-
case "float":
|
|
2053
|
-
result = 3.14;
|
|
2054
|
-
break;
|
|
2055
|
-
case "double":
|
|
2056
|
-
result = 3.14159;
|
|
2057
|
-
break;
|
|
2058
|
-
default:
|
|
2059
|
-
result = 123;
|
|
2060
|
-
}
|
|
2061
|
-
}
|
|
2062
|
-
else {
|
|
2063
|
-
result = 123;
|
|
2064
|
-
}
|
|
2065
|
-
break;
|
|
2066
|
-
case "integer":
|
|
2067
|
-
if (schema.example !== undefined) {
|
|
2068
|
-
result = schema.example;
|
|
2069
|
-
}
|
|
2070
|
-
else if (schema.format) {
|
|
2071
|
-
switch (schema.format) {
|
|
2072
|
-
case "int32":
|
|
2073
|
-
result = 123456;
|
|
2074
|
-
break;
|
|
2075
|
-
case "int64":
|
|
2076
|
-
result = 123456789;
|
|
2077
|
-
break;
|
|
2078
|
-
default:
|
|
2079
|
-
result = 123;
|
|
2080
|
-
}
|
|
2081
|
-
}
|
|
2082
|
-
else {
|
|
2083
|
-
result = 123;
|
|
2084
|
-
}
|
|
2085
|
-
break;
|
|
2086
|
-
case "boolean":
|
|
2087
|
-
result = schema.example !== undefined ? schema.example : true;
|
|
2088
|
-
break;
|
|
2089
|
-
case "array":
|
|
2090
|
-
result = [this.generateMockData(schema.items)];
|
|
2091
|
-
break;
|
|
2092
|
-
case "object":
|
|
2093
|
-
result = {};
|
|
2094
|
-
if (schema.properties) {
|
|
2095
|
-
for (const key in schema.properties) {
|
|
2096
|
-
result[key] = this.generateMockData(schema.properties[key]);
|
|
2097
|
-
}
|
|
2098
|
-
}
|
|
2099
|
-
break;
|
|
2100
|
-
default:
|
|
2101
|
-
result = schema.example || null;
|
|
2102
|
-
}
|
|
2103
|
-
}
|
|
2104
|
-
this.visitedSchemas.delete(schema);
|
|
2105
|
-
return result;
|
|
2106
|
-
}
|
|
2107
|
-
}
|
|
2108
|
-
JsonDataGenerator.visitedSchemas = new Set();
|
|
2109
|
-
|
|
2110
2123
|
// Copyright (c) Microsoft Corporation.
|
|
2111
2124
|
/**
|
|
2112
2125
|
* A class that parses an OpenAPI specification file and provides methods to validate, list, and generate artifacts.
|
|
@@ -2415,25 +2428,11 @@ class SpecParser {
|
|
|
2415
2428
|
if (this.options.allowMethods.includes(method)) {
|
|
2416
2429
|
const operation = newSpec.paths[url][method];
|
|
2417
2430
|
try {
|
|
2418
|
-
const [card, jsonPath] = AdaptiveCardGenerator.generateAdaptiveCard(operation);
|
|
2431
|
+
const [card, jsonPath, jsonData, warnings] = AdaptiveCardGenerator.generateAdaptiveCard(operation);
|
|
2432
|
+
result.warnings.push(...warnings);
|
|
2419
2433
|
const safeAdaptiveCardName = operation.operationId.replace(/[^a-zA-Z0-9]/g, "_");
|
|
2420
2434
|
const fileName = path__default['default'].join(adaptiveCardFolder, `${safeAdaptiveCardName}.json`);
|
|
2421
2435
|
const wrappedCard = wrapAdaptiveCard(card, jsonPath);
|
|
2422
|
-
const { json } = Utils.getResponseJson(operation, false);
|
|
2423
|
-
const schema = json.schema;
|
|
2424
|
-
let jsonData = {};
|
|
2425
|
-
if (schema && Object.keys(schema).length > 0) {
|
|
2426
|
-
try {
|
|
2427
|
-
jsonData = JsonDataGenerator.generate(schema);
|
|
2428
|
-
}
|
|
2429
|
-
catch (err) {
|
|
2430
|
-
result.warnings.push({
|
|
2431
|
-
type: exports.WarningType.GenerateJsonDataFailed,
|
|
2432
|
-
content: Utils.format(ConstantString.GenerateJsonDataFailed, operation.operationId, err.toString()),
|
|
2433
|
-
data: operation.operationId,
|
|
2434
|
-
});
|
|
2435
|
-
}
|
|
2436
|
-
}
|
|
2437
2436
|
yield fs__default['default'].outputJSON(fileName, wrappedCard, { spaces: 2 });
|
|
2438
2437
|
const dataFileName = path__default['default'].join(adaptiveCardFolder, `${safeAdaptiveCardName}.data.json`);
|
|
2439
2438
|
yield fs__default['default'].outputJSON(dataFileName, jsonData, { spaces: 2 });
|