@microsoft/m365-spec-parser 0.2.2 → 0.2.3-alpha.09af212fe.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 +35 -66
- package/dist/index.esm2017.js.map +1 -1
- package/dist/index.esm2017.mjs +55 -69
- package/dist/index.esm2017.mjs.map +1 -1
- package/dist/index.esm5.js +35 -66
- package/dist/index.esm5.js.map +1 -1
- package/dist/index.node.cjs.js +55 -69
- 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 +2 -2
- package/package.json +3 -3
package/dist/index.esm5.js
CHANGED
|
@@ -85,6 +85,7 @@ 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";
|
|
88
89
|
WarningType["Unknown"] = "unknown";
|
|
89
90
|
})(WarningType || (WarningType = {}));
|
|
90
91
|
/**
|
|
@@ -130,6 +131,7 @@ ConstantString.ConvertSwaggerToOpenAPI = "The Swagger 2.0 file has been converte
|
|
|
130
131
|
ConstantString.SwaggerNotSupported = "Swagger 2.0 is not supported. Please convert to OpenAPI 3.0 manually before proceeding.";
|
|
131
132
|
ConstantString.SpecVersionNotSupported = "Unsupported OpenAPI version %s. Please use version 3.0.x.";
|
|
132
133
|
ConstantString.MultipleAuthNotSupported = "Multiple authentication methods are unsupported. Ensure all selected APIs use identical authentication.";
|
|
134
|
+
ConstantString.OperationIdContainsSpecialCharacters = "Operation id '%s' in OpenAPI description document contained special characters and was renamed to '%s'.";
|
|
133
135
|
ConstantString.UnsupportedSchema = "Unsupported schema in %s %s: %s";
|
|
134
136
|
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.";
|
|
135
137
|
ConstantString.WrappedCardVersion = "devPreview";
|
|
@@ -218,16 +220,19 @@ ConstantString.PluginManifestSchema = "https://developer.microsoft.com/json-sche
|
|
|
218
220
|
// Copyright (c) Microsoft Corporation.
|
|
219
221
|
class Utils {
|
|
220
222
|
static hasNestedObjectInSchema(schema) {
|
|
221
|
-
if (schema
|
|
223
|
+
if (this.isObjectSchema(schema)) {
|
|
222
224
|
for (const property in schema.properties) {
|
|
223
225
|
const nestedSchema = schema.properties[property];
|
|
224
|
-
if (nestedSchema
|
|
226
|
+
if (this.isObjectSchema(nestedSchema)) {
|
|
225
227
|
return true;
|
|
226
228
|
}
|
|
227
229
|
}
|
|
228
230
|
}
|
|
229
231
|
return false;
|
|
230
232
|
}
|
|
233
|
+
static isObjectSchema(schema) {
|
|
234
|
+
return schema.type === "object" || (!schema.type && !!schema.properties);
|
|
235
|
+
}
|
|
231
236
|
static containMultipleMediaTypes(bodyObject) {
|
|
232
237
|
return Object.keys((bodyObject === null || bodyObject === void 0 ? void 0 : bodyObject.content) || {}).length > 1;
|
|
233
238
|
}
|
|
@@ -456,7 +461,7 @@ class Utils {
|
|
|
456
461
|
optionalParams.push(parameter);
|
|
457
462
|
}
|
|
458
463
|
}
|
|
459
|
-
else if (schema
|
|
464
|
+
else if (Utils.isObjectSchema(schema)) {
|
|
460
465
|
const { properties } = schema;
|
|
461
466
|
for (const property in properties) {
|
|
462
467
|
let isRequired = false;
|
|
@@ -570,29 +575,6 @@ class Utils {
|
|
|
570
575
|
const serverUrl = operationServer || methodServer || rootServer;
|
|
571
576
|
return serverUrl;
|
|
572
577
|
}
|
|
573
|
-
static limitACBodyProperties(body, maxCount) {
|
|
574
|
-
const result = [];
|
|
575
|
-
let currentCount = 0;
|
|
576
|
-
for (const element of body) {
|
|
577
|
-
if (element.type === ConstantString.ContainerType) {
|
|
578
|
-
const items = this.limitACBodyProperties(element.items, maxCount - currentCount);
|
|
579
|
-
result.push({
|
|
580
|
-
type: ConstantString.ContainerType,
|
|
581
|
-
$data: element.$data,
|
|
582
|
-
items: items,
|
|
583
|
-
});
|
|
584
|
-
currentCount += items.length;
|
|
585
|
-
}
|
|
586
|
-
else {
|
|
587
|
-
result.push(element);
|
|
588
|
-
currentCount++;
|
|
589
|
-
}
|
|
590
|
-
if (currentCount >= maxCount) {
|
|
591
|
-
break;
|
|
592
|
-
}
|
|
593
|
-
}
|
|
594
|
-
return result;
|
|
595
|
-
}
|
|
596
578
|
}
|
|
597
579
|
|
|
598
580
|
// Copyright (c) Microsoft Corporation.
|
|
@@ -794,7 +776,7 @@ class Validator {
|
|
|
794
776
|
}
|
|
795
777
|
const isRequiredWithoutDefault = isRequired && schema.default === undefined;
|
|
796
778
|
const isCopilot = this.projectType === ProjectType.Copilot;
|
|
797
|
-
if (isCopilot &&
|
|
779
|
+
if (isCopilot && Utils.hasNestedObjectInSchema(schema)) {
|
|
798
780
|
paramResult.isValid = false;
|
|
799
781
|
paramResult.reason = [ErrorType.RequestBodyContainsNestedObject];
|
|
800
782
|
return paramResult;
|
|
@@ -810,7 +792,7 @@ class Validator {
|
|
|
810
792
|
paramResult.optionalNum = paramResult.optionalNum + 1;
|
|
811
793
|
}
|
|
812
794
|
}
|
|
813
|
-
else if (schema
|
|
795
|
+
else if (Utils.isObjectSchema(schema)) {
|
|
814
796
|
const { properties } = schema;
|
|
815
797
|
for (const property in properties) {
|
|
816
798
|
let isRequired = false;
|
|
@@ -846,7 +828,7 @@ class Validator {
|
|
|
846
828
|
for (let i = 0; i < paramObject.length; i++) {
|
|
847
829
|
const param = paramObject[i];
|
|
848
830
|
const schema = param.schema;
|
|
849
|
-
if (isCopilot &&
|
|
831
|
+
if (isCopilot && Utils.hasNestedObjectInSchema(schema)) {
|
|
850
832
|
paramResult.isValid = false;
|
|
851
833
|
paramResult.reason.push(ErrorType.ParamsContainsNestedObject);
|
|
852
834
|
continue;
|
|
@@ -889,17 +871,6 @@ class Validator {
|
|
|
889
871
|
}
|
|
890
872
|
return paramResult;
|
|
891
873
|
}
|
|
892
|
-
hasNestedObjectInSchema(schema) {
|
|
893
|
-
if (schema.type === "object") {
|
|
894
|
-
for (const property in schema.properties) {
|
|
895
|
-
const nestedSchema = schema.properties[property];
|
|
896
|
-
if (nestedSchema.type === "object") {
|
|
897
|
-
return true;
|
|
898
|
-
}
|
|
899
|
-
}
|
|
900
|
-
}
|
|
901
|
-
return false;
|
|
902
|
-
}
|
|
903
874
|
}
|
|
904
875
|
|
|
905
876
|
// Copyright (c) Microsoft Corporation.
|
|
@@ -958,7 +929,7 @@ class CopilotValidator extends Validator {
|
|
|
958
929
|
const requestJsonBody = requestBody === null || requestBody === void 0 ? void 0 : requestBody.content["application/json"];
|
|
959
930
|
if (requestJsonBody) {
|
|
960
931
|
const requestBodySchema = requestJsonBody.schema;
|
|
961
|
-
if (requestBodySchema
|
|
932
|
+
if (!Utils.isObjectSchema(requestBodySchema)) {
|
|
962
933
|
result.reason.push(ErrorType.PostBodySchemaIsNotJson);
|
|
963
934
|
}
|
|
964
935
|
const requestBodyParamResult = this.checkPostBodySchema(requestBodySchema, requestBody.required);
|
|
@@ -1350,7 +1321,7 @@ class SpecParser {
|
|
|
1350
1321
|
|
|
1351
1322
|
// Copyright (c) Microsoft Corporation.
|
|
1352
1323
|
class AdaptiveCardGenerator {
|
|
1353
|
-
static generateAdaptiveCard(operationItem, allowMultipleMediaType = false) {
|
|
1324
|
+
static generateAdaptiveCard(operationItem, allowMultipleMediaType = false, maxElementCount = Number.MAX_SAFE_INTEGER) {
|
|
1354
1325
|
try {
|
|
1355
1326
|
const { json } = Utils.getResponseJson(operationItem, allowMultipleMediaType);
|
|
1356
1327
|
let cardBody = [];
|
|
@@ -1361,7 +1332,7 @@ class AdaptiveCardGenerator {
|
|
|
1361
1332
|
if (jsonPath !== "$") {
|
|
1362
1333
|
schema = schema.properties[jsonPath];
|
|
1363
1334
|
}
|
|
1364
|
-
cardBody = AdaptiveCardGenerator.generateCardFromResponse(schema, "");
|
|
1335
|
+
cardBody = AdaptiveCardGenerator.generateCardFromResponse(schema, "", "", maxElementCount);
|
|
1365
1336
|
}
|
|
1366
1337
|
// if no schema, try to use example value
|
|
1367
1338
|
if (cardBody.length === 0 && (json.examples || json.example)) {
|
|
@@ -1395,10 +1366,14 @@ class AdaptiveCardGenerator {
|
|
|
1395
1366
|
throw new SpecParserError(err.toString(), ErrorType.GenerateAdaptiveCardFailed);
|
|
1396
1367
|
}
|
|
1397
1368
|
}
|
|
1398
|
-
static generateCardFromResponse(schema, name, parentArrayName = "") {
|
|
1369
|
+
static generateCardFromResponse(schema, name, parentArrayName = "", maxElementCount = Number.MAX_SAFE_INTEGER, counter = { count: 0 }) {
|
|
1370
|
+
if (counter.count >= maxElementCount) {
|
|
1371
|
+
return [];
|
|
1372
|
+
}
|
|
1399
1373
|
if (schema.type === "array") {
|
|
1400
1374
|
// schema.items can be arbitrary object: schema { type: array, items: {} }
|
|
1401
1375
|
if (Object.keys(schema.items).length === 0) {
|
|
1376
|
+
counter.count++;
|
|
1402
1377
|
return [
|
|
1403
1378
|
{
|
|
1404
1379
|
type: ConstantString.TextBlockType,
|
|
@@ -1407,7 +1382,7 @@ class AdaptiveCardGenerator {
|
|
|
1407
1382
|
},
|
|
1408
1383
|
];
|
|
1409
1384
|
}
|
|
1410
|
-
const obj = AdaptiveCardGenerator.generateCardFromResponse(schema.items, "", name);
|
|
1385
|
+
const obj = AdaptiveCardGenerator.generateCardFromResponse(schema.items, "", name, maxElementCount, counter);
|
|
1411
1386
|
const template = {
|
|
1412
1387
|
type: ConstantString.ContainerType,
|
|
1413
1388
|
$data: name ? `\${${name}}` : "${$root}",
|
|
@@ -1417,11 +1392,11 @@ class AdaptiveCardGenerator {
|
|
|
1417
1392
|
return [template];
|
|
1418
1393
|
}
|
|
1419
1394
|
// some schema may not contain type but contain properties
|
|
1420
|
-
if (
|
|
1395
|
+
if (Utils.isObjectSchema(schema)) {
|
|
1421
1396
|
const { properties } = schema;
|
|
1422
1397
|
const result = [];
|
|
1423
1398
|
for (const property in properties) {
|
|
1424
|
-
const obj = AdaptiveCardGenerator.generateCardFromResponse(properties[property], name ? `${name}.${property}` : property, parentArrayName);
|
|
1399
|
+
const obj = AdaptiveCardGenerator.generateCardFromResponse(properties[property], name ? `${name}.${property}` : property, parentArrayName, maxElementCount, counter);
|
|
1425
1400
|
result.push(...obj);
|
|
1426
1401
|
}
|
|
1427
1402
|
if (schema.additionalProperties) {
|
|
@@ -1434,6 +1409,7 @@ class AdaptiveCardGenerator {
|
|
|
1434
1409
|
schema.type === "integer" ||
|
|
1435
1410
|
schema.type === "boolean" ||
|
|
1436
1411
|
schema.type === "number") {
|
|
1412
|
+
counter.count++;
|
|
1437
1413
|
if (!AdaptiveCardGenerator.isImageUrlProperty(schema, name, parentArrayName)) {
|
|
1438
1414
|
// string in root: "ddd"
|
|
1439
1415
|
let text = "result: ${$root}";
|
|
@@ -1458,24 +1434,17 @@ class AdaptiveCardGenerator {
|
|
|
1458
1434
|
];
|
|
1459
1435
|
}
|
|
1460
1436
|
else {
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
{
|
|
1473
|
-
type: "Image",
|
|
1474
|
-
url: "${$data}",
|
|
1475
|
-
$when: "${$data != null && $data != ''}",
|
|
1476
|
-
},
|
|
1477
|
-
];
|
|
1478
|
-
}
|
|
1437
|
+
const url = name ? `\${${name}}` : "${$data}";
|
|
1438
|
+
const condition = name
|
|
1439
|
+
? `\${${name} != null && ${name} != ''}`
|
|
1440
|
+
: "${$data != null && $data != ''}";
|
|
1441
|
+
return [
|
|
1442
|
+
{
|
|
1443
|
+
type: "Image",
|
|
1444
|
+
url,
|
|
1445
|
+
$when: condition,
|
|
1446
|
+
},
|
|
1447
|
+
];
|
|
1479
1448
|
}
|
|
1480
1449
|
}
|
|
1481
1450
|
if (schema.oneOf || schema.anyOf || schema.not || schema.allOf) {
|
|
@@ -1485,7 +1454,7 @@ class AdaptiveCardGenerator {
|
|
|
1485
1454
|
}
|
|
1486
1455
|
// Find the first array property in the response schema object with the well-known name
|
|
1487
1456
|
static getResponseJsonPathFromSchema(schema) {
|
|
1488
|
-
if (
|
|
1457
|
+
if (Utils.isObjectSchema(schema)) {
|
|
1489
1458
|
const { properties } = schema;
|
|
1490
1459
|
for (const property in properties) {
|
|
1491
1460
|
const schema = properties[property];
|