@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.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";
|
|
@@ -188,16 +190,19 @@ ConstantString.PluginManifestSchema = "https://developer.microsoft.com/json-sche
|
|
|
188
190
|
// Copyright (c) Microsoft Corporation.
|
|
189
191
|
class Utils {
|
|
190
192
|
static hasNestedObjectInSchema(schema) {
|
|
191
|
-
if (schema
|
|
193
|
+
if (this.isObjectSchema(schema)) {
|
|
192
194
|
for (const property in schema.properties) {
|
|
193
195
|
const nestedSchema = schema.properties[property];
|
|
194
|
-
if (nestedSchema
|
|
196
|
+
if (this.isObjectSchema(nestedSchema)) {
|
|
195
197
|
return true;
|
|
196
198
|
}
|
|
197
199
|
}
|
|
198
200
|
}
|
|
199
201
|
return false;
|
|
200
202
|
}
|
|
203
|
+
static isObjectSchema(schema) {
|
|
204
|
+
return schema.type === "object" || (!schema.type && !!schema.properties);
|
|
205
|
+
}
|
|
201
206
|
static containMultipleMediaTypes(bodyObject) {
|
|
202
207
|
return Object.keys((bodyObject === null || bodyObject === void 0 ? void 0 : bodyObject.content) || {}).length > 1;
|
|
203
208
|
}
|
|
@@ -426,7 +431,7 @@ class Utils {
|
|
|
426
431
|
optionalParams.push(parameter);
|
|
427
432
|
}
|
|
428
433
|
}
|
|
429
|
-
else if (schema
|
|
434
|
+
else if (Utils.isObjectSchema(schema)) {
|
|
430
435
|
const { properties } = schema;
|
|
431
436
|
for (const property in properties) {
|
|
432
437
|
let isRequired = false;
|
|
@@ -540,29 +545,6 @@ class Utils {
|
|
|
540
545
|
const serverUrl = operationServer || methodServer || rootServer;
|
|
541
546
|
return serverUrl;
|
|
542
547
|
}
|
|
543
|
-
static limitACBodyProperties(body, maxCount) {
|
|
544
|
-
const result = [];
|
|
545
|
-
let currentCount = 0;
|
|
546
|
-
for (const element of body) {
|
|
547
|
-
if (element.type === ConstantString.ContainerType) {
|
|
548
|
-
const items = this.limitACBodyProperties(element.items, maxCount - currentCount);
|
|
549
|
-
result.push({
|
|
550
|
-
type: ConstantString.ContainerType,
|
|
551
|
-
$data: element.$data,
|
|
552
|
-
items: items,
|
|
553
|
-
});
|
|
554
|
-
currentCount += items.length;
|
|
555
|
-
}
|
|
556
|
-
else {
|
|
557
|
-
result.push(element);
|
|
558
|
-
currentCount++;
|
|
559
|
-
}
|
|
560
|
-
if (currentCount >= maxCount) {
|
|
561
|
-
break;
|
|
562
|
-
}
|
|
563
|
-
}
|
|
564
|
-
return result;
|
|
565
|
-
}
|
|
566
548
|
}
|
|
567
549
|
|
|
568
550
|
// Copyright (c) Microsoft Corporation.
|
|
@@ -764,7 +746,7 @@ class Validator {
|
|
|
764
746
|
}
|
|
765
747
|
const isRequiredWithoutDefault = isRequired && schema.default === undefined;
|
|
766
748
|
const isCopilot = this.projectType === ProjectType.Copilot;
|
|
767
|
-
if (isCopilot &&
|
|
749
|
+
if (isCopilot && Utils.hasNestedObjectInSchema(schema)) {
|
|
768
750
|
paramResult.isValid = false;
|
|
769
751
|
paramResult.reason = [ErrorType.RequestBodyContainsNestedObject];
|
|
770
752
|
return paramResult;
|
|
@@ -780,7 +762,7 @@ class Validator {
|
|
|
780
762
|
paramResult.optionalNum = paramResult.optionalNum + 1;
|
|
781
763
|
}
|
|
782
764
|
}
|
|
783
|
-
else if (schema
|
|
765
|
+
else if (Utils.isObjectSchema(schema)) {
|
|
784
766
|
const { properties } = schema;
|
|
785
767
|
for (const property in properties) {
|
|
786
768
|
let isRequired = false;
|
|
@@ -816,7 +798,7 @@ class Validator {
|
|
|
816
798
|
for (let i = 0; i < paramObject.length; i++) {
|
|
817
799
|
const param = paramObject[i];
|
|
818
800
|
const schema = param.schema;
|
|
819
|
-
if (isCopilot &&
|
|
801
|
+
if (isCopilot && Utils.hasNestedObjectInSchema(schema)) {
|
|
820
802
|
paramResult.isValid = false;
|
|
821
803
|
paramResult.reason.push(ErrorType.ParamsContainsNestedObject);
|
|
822
804
|
continue;
|
|
@@ -859,17 +841,6 @@ class Validator {
|
|
|
859
841
|
}
|
|
860
842
|
return paramResult;
|
|
861
843
|
}
|
|
862
|
-
hasNestedObjectInSchema(schema) {
|
|
863
|
-
if (schema.type === "object") {
|
|
864
|
-
for (const property in schema.properties) {
|
|
865
|
-
const nestedSchema = schema.properties[property];
|
|
866
|
-
if (nestedSchema.type === "object") {
|
|
867
|
-
return true;
|
|
868
|
-
}
|
|
869
|
-
}
|
|
870
|
-
}
|
|
871
|
-
return false;
|
|
872
|
-
}
|
|
873
844
|
}
|
|
874
845
|
|
|
875
846
|
// Copyright (c) Microsoft Corporation.
|
|
@@ -928,7 +899,7 @@ class CopilotValidator extends Validator {
|
|
|
928
899
|
const requestJsonBody = requestBody === null || requestBody === void 0 ? void 0 : requestBody.content["application/json"];
|
|
929
900
|
if (requestJsonBody) {
|
|
930
901
|
const requestBodySchema = requestJsonBody.schema;
|
|
931
|
-
if (requestBodySchema
|
|
902
|
+
if (!Utils.isObjectSchema(requestBodySchema)) {
|
|
932
903
|
result.reason.push(ErrorType.PostBodySchemaIsNotJson);
|
|
933
904
|
}
|
|
934
905
|
const requestBodyParamResult = this.checkPostBodySchema(requestBodySchema, requestBody.required);
|
|
@@ -1306,7 +1277,7 @@ class SpecParser {
|
|
|
1306
1277
|
|
|
1307
1278
|
// Copyright (c) Microsoft Corporation.
|
|
1308
1279
|
class AdaptiveCardGenerator {
|
|
1309
|
-
static generateAdaptiveCard(operationItem, allowMultipleMediaType = false) {
|
|
1280
|
+
static generateAdaptiveCard(operationItem, allowMultipleMediaType = false, maxElementCount = Number.MAX_SAFE_INTEGER) {
|
|
1310
1281
|
try {
|
|
1311
1282
|
const { json } = Utils.getResponseJson(operationItem, allowMultipleMediaType);
|
|
1312
1283
|
let cardBody = [];
|
|
@@ -1317,7 +1288,7 @@ class AdaptiveCardGenerator {
|
|
|
1317
1288
|
if (jsonPath !== "$") {
|
|
1318
1289
|
schema = schema.properties[jsonPath];
|
|
1319
1290
|
}
|
|
1320
|
-
cardBody = AdaptiveCardGenerator.generateCardFromResponse(schema, "");
|
|
1291
|
+
cardBody = AdaptiveCardGenerator.generateCardFromResponse(schema, "", "", maxElementCount);
|
|
1321
1292
|
}
|
|
1322
1293
|
// if no schema, try to use example value
|
|
1323
1294
|
if (cardBody.length === 0 && (json.examples || json.example)) {
|
|
@@ -1351,10 +1322,14 @@ class AdaptiveCardGenerator {
|
|
|
1351
1322
|
throw new SpecParserError(err.toString(), ErrorType.GenerateAdaptiveCardFailed);
|
|
1352
1323
|
}
|
|
1353
1324
|
}
|
|
1354
|
-
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
|
+
}
|
|
1355
1329
|
if (schema.type === "array") {
|
|
1356
1330
|
// schema.items can be arbitrary object: schema { type: array, items: {} }
|
|
1357
1331
|
if (Object.keys(schema.items).length === 0) {
|
|
1332
|
+
counter.count++;
|
|
1358
1333
|
return [
|
|
1359
1334
|
{
|
|
1360
1335
|
type: ConstantString.TextBlockType,
|
|
@@ -1363,7 +1338,7 @@ class AdaptiveCardGenerator {
|
|
|
1363
1338
|
},
|
|
1364
1339
|
];
|
|
1365
1340
|
}
|
|
1366
|
-
const obj = AdaptiveCardGenerator.generateCardFromResponse(schema.items, "", name);
|
|
1341
|
+
const obj = AdaptiveCardGenerator.generateCardFromResponse(schema.items, "", name, maxElementCount, counter);
|
|
1367
1342
|
const template = {
|
|
1368
1343
|
type: ConstantString.ContainerType,
|
|
1369
1344
|
$data: name ? `\${${name}}` : "${$root}",
|
|
@@ -1373,11 +1348,11 @@ class AdaptiveCardGenerator {
|
|
|
1373
1348
|
return [template];
|
|
1374
1349
|
}
|
|
1375
1350
|
// some schema may not contain type but contain properties
|
|
1376
|
-
if (
|
|
1351
|
+
if (Utils.isObjectSchema(schema)) {
|
|
1377
1352
|
const { properties } = schema;
|
|
1378
1353
|
const result = [];
|
|
1379
1354
|
for (const property in properties) {
|
|
1380
|
-
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);
|
|
1381
1356
|
result.push(...obj);
|
|
1382
1357
|
}
|
|
1383
1358
|
if (schema.additionalProperties) {
|
|
@@ -1390,6 +1365,7 @@ class AdaptiveCardGenerator {
|
|
|
1390
1365
|
schema.type === "integer" ||
|
|
1391
1366
|
schema.type === "boolean" ||
|
|
1392
1367
|
schema.type === "number") {
|
|
1368
|
+
counter.count++;
|
|
1393
1369
|
if (!AdaptiveCardGenerator.isImageUrlProperty(schema, name, parentArrayName)) {
|
|
1394
1370
|
// string in root: "ddd"
|
|
1395
1371
|
let text = "result: ${$root}";
|
|
@@ -1414,24 +1390,17 @@ class AdaptiveCardGenerator {
|
|
|
1414
1390
|
];
|
|
1415
1391
|
}
|
|
1416
1392
|
else {
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
{
|
|
1429
|
-
type: "Image",
|
|
1430
|
-
url: "${$data}",
|
|
1431
|
-
$when: "${$data != null && $data != ''}",
|
|
1432
|
-
},
|
|
1433
|
-
];
|
|
1434
|
-
}
|
|
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
|
+
];
|
|
1435
1404
|
}
|
|
1436
1405
|
}
|
|
1437
1406
|
if (schema.oneOf || schema.anyOf || schema.not || schema.allOf) {
|
|
@@ -1441,7 +1410,7 @@ class AdaptiveCardGenerator {
|
|
|
1441
1410
|
}
|
|
1442
1411
|
// Find the first array property in the response schema object with the well-known name
|
|
1443
1412
|
static getResponseJsonPathFromSchema(schema) {
|
|
1444
|
-
if (
|
|
1413
|
+
if (Utils.isObjectSchema(schema)) {
|
|
1445
1414
|
const { properties } = schema;
|
|
1446
1415
|
for (const property in properties) {
|
|
1447
1416
|
const schema = properties[property];
|