@microsoft/m365-spec-parser 0.2.2-rc.0 → 0.2.2
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 +20 -12
- package/dist/index.esm2017.js.map +1 -1
- package/dist/index.esm2017.mjs +46 -23
- package/dist/index.esm2017.mjs.map +1 -1
- package/dist/index.esm5.js +20 -12
- package/dist/index.esm5.js.map +1 -1
- package/dist/index.node.cjs.js +46 -23
- package/dist/index.node.cjs.js.map +1 -1
- package/dist/src/utils.d.ts +0 -1
- package/package.json +3 -3
package/dist/index.node.cjs.js
CHANGED
|
@@ -7,6 +7,7 @@ var converter = require('swagger2openapi');
|
|
|
7
7
|
var jsyaml = require('js-yaml');
|
|
8
8
|
var fs = require('fs-extra');
|
|
9
9
|
var path = require('path');
|
|
10
|
+
var teamsManifest = require('@microsoft/teams-manifest');
|
|
10
11
|
var crypto = require('crypto');
|
|
11
12
|
|
|
12
13
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
@@ -235,19 +236,16 @@ class SpecParserError extends Error {
|
|
|
235
236
|
// Copyright (c) Microsoft Corporation.
|
|
236
237
|
class Utils {
|
|
237
238
|
static hasNestedObjectInSchema(schema) {
|
|
238
|
-
if (
|
|
239
|
+
if (schema.type === "object") {
|
|
239
240
|
for (const property in schema.properties) {
|
|
240
241
|
const nestedSchema = schema.properties[property];
|
|
241
|
-
if (
|
|
242
|
+
if (nestedSchema.type === "object") {
|
|
242
243
|
return true;
|
|
243
244
|
}
|
|
244
245
|
}
|
|
245
246
|
}
|
|
246
247
|
return false;
|
|
247
248
|
}
|
|
248
|
-
static isObjectSchema(schema) {
|
|
249
|
-
return schema.type === "object" || (!schema.type && !!schema.properties);
|
|
250
|
-
}
|
|
251
249
|
static containMultipleMediaTypes(bodyObject) {
|
|
252
250
|
return Object.keys((bodyObject === null || bodyObject === void 0 ? void 0 : bodyObject.content) || {}).length > 1;
|
|
253
251
|
}
|
|
@@ -476,7 +474,7 @@ class Utils {
|
|
|
476
474
|
optionalParams.push(parameter);
|
|
477
475
|
}
|
|
478
476
|
}
|
|
479
|
-
else if (
|
|
477
|
+
else if (schema.type === "object") {
|
|
480
478
|
const { properties } = schema;
|
|
481
479
|
for (const property in properties) {
|
|
482
480
|
let isRequired = false;
|
|
@@ -814,7 +812,7 @@ class Validator {
|
|
|
814
812
|
}
|
|
815
813
|
const isRequiredWithoutDefault = isRequired && schema.default === undefined;
|
|
816
814
|
const isCopilot = this.projectType === exports.ProjectType.Copilot;
|
|
817
|
-
if (isCopilot &&
|
|
815
|
+
if (isCopilot && this.hasNestedObjectInSchema(schema)) {
|
|
818
816
|
paramResult.isValid = false;
|
|
819
817
|
paramResult.reason = [exports.ErrorType.RequestBodyContainsNestedObject];
|
|
820
818
|
return paramResult;
|
|
@@ -830,7 +828,7 @@ class Validator {
|
|
|
830
828
|
paramResult.optionalNum = paramResult.optionalNum + 1;
|
|
831
829
|
}
|
|
832
830
|
}
|
|
833
|
-
else if (
|
|
831
|
+
else if (schema.type === "object") {
|
|
834
832
|
const { properties } = schema;
|
|
835
833
|
for (const property in properties) {
|
|
836
834
|
let isRequired = false;
|
|
@@ -866,7 +864,7 @@ class Validator {
|
|
|
866
864
|
for (let i = 0; i < paramObject.length; i++) {
|
|
867
865
|
const param = paramObject[i];
|
|
868
866
|
const schema = param.schema;
|
|
869
|
-
if (isCopilot &&
|
|
867
|
+
if (isCopilot && this.hasNestedObjectInSchema(schema)) {
|
|
870
868
|
paramResult.isValid = false;
|
|
871
869
|
paramResult.reason.push(exports.ErrorType.ParamsContainsNestedObject);
|
|
872
870
|
continue;
|
|
@@ -909,6 +907,17 @@ class Validator {
|
|
|
909
907
|
}
|
|
910
908
|
return paramResult;
|
|
911
909
|
}
|
|
910
|
+
hasNestedObjectInSchema(schema) {
|
|
911
|
+
if (schema.type === "object") {
|
|
912
|
+
for (const property in schema.properties) {
|
|
913
|
+
const nestedSchema = schema.properties[property];
|
|
914
|
+
if (nestedSchema.type === "object") {
|
|
915
|
+
return true;
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
return false;
|
|
920
|
+
}
|
|
912
921
|
}
|
|
913
922
|
|
|
914
923
|
// Copyright (c) Microsoft Corporation.
|
|
@@ -967,7 +976,7 @@ class CopilotValidator extends Validator {
|
|
|
967
976
|
const requestJsonBody = requestBody === null || requestBody === void 0 ? void 0 : requestBody.content["application/json"];
|
|
968
977
|
if (requestJsonBody) {
|
|
969
978
|
const requestBodySchema = requestJsonBody.schema;
|
|
970
|
-
if (
|
|
979
|
+
if (requestBodySchema.type !== "object") {
|
|
971
980
|
result.reason.push(exports.ErrorType.PostBodySchemaIsNotJson);
|
|
972
981
|
}
|
|
973
982
|
const requestBodyParamResult = this.checkPostBodySchema(requestBodySchema, requestBody.required);
|
|
@@ -1414,7 +1423,7 @@ class AdaptiveCardGenerator {
|
|
|
1414
1423
|
return [template];
|
|
1415
1424
|
}
|
|
1416
1425
|
// some schema may not contain type but contain properties
|
|
1417
|
-
if (
|
|
1426
|
+
if (schema.type === "object" || (!schema.type && schema.properties)) {
|
|
1418
1427
|
const { properties } = schema;
|
|
1419
1428
|
const result = [];
|
|
1420
1429
|
for (const property in properties) {
|
|
@@ -1482,7 +1491,7 @@ class AdaptiveCardGenerator {
|
|
|
1482
1491
|
}
|
|
1483
1492
|
// Find the first array property in the response schema object with the well-known name
|
|
1484
1493
|
static getResponseJsonPathFromSchema(schema) {
|
|
1485
|
-
if (
|
|
1494
|
+
if (schema.type === "object" || (!schema.type && schema.properties)) {
|
|
1486
1495
|
const { properties } = schema;
|
|
1487
1496
|
for (const property in properties) {
|
|
1488
1497
|
const schema = properties[property];
|
|
@@ -1638,16 +1647,30 @@ class ManifestUpdater {
|
|
|
1638
1647
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1639
1648
|
const manifest = yield fs__default['default'].readJSON(manifestPath);
|
|
1640
1649
|
const apiPluginRelativePath = ManifestUpdater.getRelativePath(manifestPath, apiPluginFilePath);
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1650
|
+
const useCopilotExtensionsInSchema = yield teamsManifest.ManifestUtil.useCopilotExtensionsInSchema(manifest);
|
|
1651
|
+
if (manifest.copilotExtensions || useCopilotExtensionsInSchema) {
|
|
1652
|
+
manifest.copilotExtensions = manifest.copilotExtensions || {};
|
|
1653
|
+
if (!options.isGptPlugin) {
|
|
1654
|
+
manifest.copilotExtensions.plugins = [
|
|
1655
|
+
{
|
|
1656
|
+
file: apiPluginRelativePath,
|
|
1657
|
+
id: ConstantString.DefaultPluginId,
|
|
1658
|
+
},
|
|
1659
|
+
];
|
|
1660
|
+
ManifestUpdater.updateManifestDescription(manifest, spec);
|
|
1661
|
+
}
|
|
1662
|
+
}
|
|
1663
|
+
else {
|
|
1664
|
+
manifest.copilotAgents = manifest.copilotAgents || {};
|
|
1665
|
+
if (!options.isGptPlugin) {
|
|
1666
|
+
manifest.copilotAgents.plugins = [
|
|
1667
|
+
{
|
|
1668
|
+
file: apiPluginRelativePath,
|
|
1669
|
+
id: ConstantString.DefaultPluginId,
|
|
1670
|
+
},
|
|
1671
|
+
];
|
|
1672
|
+
ManifestUpdater.updateManifestDescription(manifest, spec);
|
|
1673
|
+
}
|
|
1651
1674
|
}
|
|
1652
1675
|
const appName = this.removeEnvs(manifest.name.short);
|
|
1653
1676
|
const specRelativePath = ManifestUpdater.getRelativePath(manifestPath, outputSpecPath);
|
|
@@ -1723,7 +1746,7 @@ class ManifestUpdater {
|
|
|
1723
1746
|
if (requestBody) {
|
|
1724
1747
|
const requestJsonBody = requestBody.content["application/json"];
|
|
1725
1748
|
const requestBodySchema = requestJsonBody.schema;
|
|
1726
|
-
if (
|
|
1749
|
+
if (requestBodySchema.type === "object") {
|
|
1727
1750
|
for (const property in requestBodySchema.properties) {
|
|
1728
1751
|
const schema = requestBodySchema.properties[property];
|
|
1729
1752
|
ManifestUpdater.checkSchema(schema, method, pathUrl);
|