@microsoft/m365-spec-parser 0.2.2-alpha.1fac52ff4.0 → 0.2.2-alpha.2beeded72.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 +13 -21
- package/dist/index.esm2017.js.map +1 -1
- package/dist/index.esm2017.mjs +14 -22
- package/dist/index.esm2017.mjs.map +1 -1
- package/dist/index.esm5.js +13 -21
- package/dist/index.esm5.js.map +1 -1
- package/dist/index.node.cjs.js +14 -22
- package/dist/index.node.cjs.js.map +1 -1
- package/dist/src/constants.d.ts +1 -1
- package/dist/src/utils.d.ts +1 -0
- package/package.json +3 -3
package/dist/index.esm5.js
CHANGED
|
@@ -213,21 +213,24 @@ ConstantString.ParameterTitleMaxLens = 32;
|
|
|
213
213
|
ConstantString.SMERequiredParamsMaxNum = 5;
|
|
214
214
|
ConstantString.FunctionDescriptionMaxLens = 100;
|
|
215
215
|
ConstantString.DefaultPluginId = "plugin_1";
|
|
216
|
-
ConstantString.PluginManifestSchema = "https://
|
|
216
|
+
ConstantString.PluginManifestSchema = "https://developer.microsoft.com/json-schemas/copilot/plugin/v2.1/schema.json";
|
|
217
217
|
|
|
218
218
|
// Copyright (c) Microsoft Corporation.
|
|
219
219
|
class Utils {
|
|
220
220
|
static hasNestedObjectInSchema(schema) {
|
|
221
|
-
if (schema
|
|
221
|
+
if (this.isObjectSchema(schema)) {
|
|
222
222
|
for (const property in schema.properties) {
|
|
223
223
|
const nestedSchema = schema.properties[property];
|
|
224
|
-
if (nestedSchema
|
|
224
|
+
if (this.isObjectSchema(nestedSchema)) {
|
|
225
225
|
return true;
|
|
226
226
|
}
|
|
227
227
|
}
|
|
228
228
|
}
|
|
229
229
|
return false;
|
|
230
230
|
}
|
|
231
|
+
static isObjectSchema(schema) {
|
|
232
|
+
return schema.type === "object" || (!schema.type && !!schema.properties);
|
|
233
|
+
}
|
|
231
234
|
static containMultipleMediaTypes(bodyObject) {
|
|
232
235
|
return Object.keys((bodyObject === null || bodyObject === void 0 ? void 0 : bodyObject.content) || {}).length > 1;
|
|
233
236
|
}
|
|
@@ -456,7 +459,7 @@ class Utils {
|
|
|
456
459
|
optionalParams.push(parameter);
|
|
457
460
|
}
|
|
458
461
|
}
|
|
459
|
-
else if (schema
|
|
462
|
+
else if (Utils.isObjectSchema(schema)) {
|
|
460
463
|
const { properties } = schema;
|
|
461
464
|
for (const property in properties) {
|
|
462
465
|
let isRequired = false;
|
|
@@ -794,7 +797,7 @@ class Validator {
|
|
|
794
797
|
}
|
|
795
798
|
const isRequiredWithoutDefault = isRequired && schema.default === undefined;
|
|
796
799
|
const isCopilot = this.projectType === ProjectType.Copilot;
|
|
797
|
-
if (isCopilot &&
|
|
800
|
+
if (isCopilot && Utils.hasNestedObjectInSchema(schema)) {
|
|
798
801
|
paramResult.isValid = false;
|
|
799
802
|
paramResult.reason = [ErrorType.RequestBodyContainsNestedObject];
|
|
800
803
|
return paramResult;
|
|
@@ -810,7 +813,7 @@ class Validator {
|
|
|
810
813
|
paramResult.optionalNum = paramResult.optionalNum + 1;
|
|
811
814
|
}
|
|
812
815
|
}
|
|
813
|
-
else if (schema
|
|
816
|
+
else if (Utils.isObjectSchema(schema)) {
|
|
814
817
|
const { properties } = schema;
|
|
815
818
|
for (const property in properties) {
|
|
816
819
|
let isRequired = false;
|
|
@@ -846,7 +849,7 @@ class Validator {
|
|
|
846
849
|
for (let i = 0; i < paramObject.length; i++) {
|
|
847
850
|
const param = paramObject[i];
|
|
848
851
|
const schema = param.schema;
|
|
849
|
-
if (isCopilot &&
|
|
852
|
+
if (isCopilot && Utils.hasNestedObjectInSchema(schema)) {
|
|
850
853
|
paramResult.isValid = false;
|
|
851
854
|
paramResult.reason.push(ErrorType.ParamsContainsNestedObject);
|
|
852
855
|
continue;
|
|
@@ -889,17 +892,6 @@ class Validator {
|
|
|
889
892
|
}
|
|
890
893
|
return paramResult;
|
|
891
894
|
}
|
|
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
895
|
}
|
|
904
896
|
|
|
905
897
|
// Copyright (c) Microsoft Corporation.
|
|
@@ -958,7 +950,7 @@ class CopilotValidator extends Validator {
|
|
|
958
950
|
const requestJsonBody = requestBody === null || requestBody === void 0 ? void 0 : requestBody.content["application/json"];
|
|
959
951
|
if (requestJsonBody) {
|
|
960
952
|
const requestBodySchema = requestJsonBody.schema;
|
|
961
|
-
if (requestBodySchema
|
|
953
|
+
if (!Utils.isObjectSchema(requestBodySchema)) {
|
|
962
954
|
result.reason.push(ErrorType.PostBodySchemaIsNotJson);
|
|
963
955
|
}
|
|
964
956
|
const requestBodyParamResult = this.checkPostBodySchema(requestBodySchema, requestBody.required);
|
|
@@ -1417,7 +1409,7 @@ class AdaptiveCardGenerator {
|
|
|
1417
1409
|
return [template];
|
|
1418
1410
|
}
|
|
1419
1411
|
// some schema may not contain type but contain properties
|
|
1420
|
-
if (
|
|
1412
|
+
if (Utils.isObjectSchema(schema)) {
|
|
1421
1413
|
const { properties } = schema;
|
|
1422
1414
|
const result = [];
|
|
1423
1415
|
for (const property in properties) {
|
|
@@ -1485,7 +1477,7 @@ class AdaptiveCardGenerator {
|
|
|
1485
1477
|
}
|
|
1486
1478
|
// Find the first array property in the response schema object with the well-known name
|
|
1487
1479
|
static getResponseJsonPathFromSchema(schema) {
|
|
1488
|
-
if (
|
|
1480
|
+
if (Utils.isObjectSchema(schema)) {
|
|
1489
1481
|
const { properties } = schema;
|
|
1490
1482
|
for (const property in properties) {
|
|
1491
1483
|
const schema = properties[property];
|