@microsoft/m365-spec-parser 0.2.2-alpha.0b236986a.0 → 0.2.2-alpha.17924f754.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 +24 -15
- package/dist/index.esm2017.js.map +1 -1
- package/dist/index.esm2017.mjs +44 -18
- package/dist/index.esm2017.mjs.map +1 -1
- package/dist/index.esm5.js +24 -15
- package/dist/index.esm5.js.map +1 -1
- package/dist/index.node.cjs.js +44 -18
- package/dist/index.node.cjs.js.map +1 -1
- package/dist/src/constants.d.ts +2 -0
- package/dist/src/interfaces.d.ts +1 -0
- package/dist/src/specParser.d.ts +1 -1
- package/package.json +3 -3
package/dist/index.esm2017.mjs
CHANGED
|
@@ -58,6 +58,7 @@ var WarningType;
|
|
|
58
58
|
WarningType["GenerateCardFailed"] = "generate-card-failed";
|
|
59
59
|
WarningType["OperationOnlyContainsOptionalParam"] = "operation-only-contains-optional-param";
|
|
60
60
|
WarningType["ConvertSwaggerToOpenAPI"] = "convert-swagger-to-openapi";
|
|
61
|
+
WarningType["FuncDescriptionTooLong"] = "function-description-too-long";
|
|
61
62
|
WarningType["Unknown"] = "unknown";
|
|
62
63
|
})(WarningType || (WarningType = {}));
|
|
63
64
|
/**
|
|
@@ -96,6 +97,7 @@ ConstantString.SwaggerNotSupported = "Swagger 2.0 is not supported. Please conve
|
|
|
96
97
|
ConstantString.SpecVersionNotSupported = "Unsupported OpenAPI version %s. Please use version 3.0.x.";
|
|
97
98
|
ConstantString.MultipleAuthNotSupported = "Multiple authentication methods are unsupported. Ensure all selected APIs use identical authentication.";
|
|
98
99
|
ConstantString.UnsupportedSchema = "Unsupported schema in %s %s: %s";
|
|
100
|
+
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.";
|
|
99
101
|
ConstantString.WrappedCardVersion = "devPreview";
|
|
100
102
|
ConstantString.WrappedCardSchema = "https://developer.microsoft.com/json-schemas/teams/vDevPreview/MicrosoftTeams.ResponseRenderingTemplate.schema.json";
|
|
101
103
|
ConstantString.WrappedCardResponseLayout = "list";
|
|
@@ -175,6 +177,7 @@ ConstantString.ConversationStarterMaxLens = 50;
|
|
|
175
177
|
ConstantString.CommandTitleMaxLens = 32;
|
|
176
178
|
ConstantString.ParameterTitleMaxLens = 32;
|
|
177
179
|
ConstantString.SMERequiredParamsMaxNum = 5;
|
|
180
|
+
ConstantString.FunctionDescriptionMaxLens = 100;
|
|
178
181
|
ConstantString.DefaultPluginId = "plugin_1";
|
|
179
182
|
ConstantString.PluginManifestSchema = "https://aka.ms/json-schemas/copilot-extensions/v2.1/plugin.schema.json";
|
|
180
183
|
|
|
@@ -260,23 +263,28 @@ class Utils {
|
|
|
260
263
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
261
264
|
}
|
|
262
265
|
static getResponseJson(operationObject, allowMultipleMediaType = false) {
|
|
263
|
-
var _a
|
|
266
|
+
var _a;
|
|
264
267
|
let json = {};
|
|
265
268
|
let multipleMediaType = false;
|
|
266
269
|
for (const code of ConstantString.ResponseCodeFor20X) {
|
|
267
270
|
const responseObject = (_a = operationObject === null || operationObject === void 0 ? void 0 : operationObject.responses) === null || _a === void 0 ? void 0 : _a[code];
|
|
268
|
-
if (
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
271
|
+
if (responseObject === null || responseObject === void 0 ? void 0 : responseObject.content) {
|
|
272
|
+
for (const contentType of Object.keys(responseObject.content)) {
|
|
273
|
+
// json media type can also be "application/json; charset=utf-8"
|
|
274
|
+
if (contentType.indexOf("application/json") >= 0) {
|
|
275
|
+
multipleMediaType = false;
|
|
276
|
+
json = responseObject.content[contentType];
|
|
277
|
+
if (Utils.containMultipleMediaTypes(responseObject)) {
|
|
278
|
+
multipleMediaType = true;
|
|
279
|
+
if (!allowMultipleMediaType) {
|
|
280
|
+
json = {};
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
else {
|
|
284
|
+
return { json, multipleMediaType };
|
|
285
|
+
}
|
|
275
286
|
}
|
|
276
287
|
}
|
|
277
|
-
else {
|
|
278
|
-
break;
|
|
279
|
-
}
|
|
280
288
|
}
|
|
281
289
|
}
|
|
282
290
|
return { json, multipleMediaType };
|
|
@@ -550,10 +558,11 @@ class Utils {
|
|
|
550
558
|
currentCount += items.length;
|
|
551
559
|
}
|
|
552
560
|
else {
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
561
|
+
result.push(element);
|
|
562
|
+
currentCount++;
|
|
563
|
+
}
|
|
564
|
+
if (currentCount >= maxCount) {
|
|
565
|
+
break;
|
|
557
566
|
}
|
|
558
567
|
}
|
|
559
568
|
return result;
|
|
@@ -1687,9 +1696,18 @@ class ManifestUpdater {
|
|
|
1687
1696
|
throw new SpecParserError(Utils.format(ConstantString.UnsupportedSchema, method, pathUrl, JSON.stringify(requestBodySchema)), ErrorType.UpdateManifestFailed);
|
|
1688
1697
|
}
|
|
1689
1698
|
}
|
|
1699
|
+
let funcDescription = operationItem.description || operationItem.summary || "";
|
|
1700
|
+
if (funcDescription.length > ConstantString.FunctionDescriptionMaxLens) {
|
|
1701
|
+
warnings.push({
|
|
1702
|
+
type: WarningType.FuncDescriptionTooLong,
|
|
1703
|
+
content: Utils.format(ConstantString.FuncDescriptionTooLong, safeFunctionName, funcDescription.length.toString(), ConstantString.FunctionDescriptionMaxLens.toString()),
|
|
1704
|
+
data: safeFunctionName,
|
|
1705
|
+
});
|
|
1706
|
+
funcDescription = funcDescription.slice(0, ConstantString.FunctionDescriptionMaxLens);
|
|
1707
|
+
}
|
|
1690
1708
|
const funcObj = {
|
|
1691
1709
|
name: safeFunctionName,
|
|
1692
|
-
description:
|
|
1710
|
+
description: funcDescription,
|
|
1693
1711
|
};
|
|
1694
1712
|
if (options.allowResponseSemantics) {
|
|
1695
1713
|
try {
|
|
@@ -2130,7 +2148,7 @@ class SpecParser {
|
|
|
2130
2148
|
* @param outputSpecPath File path of the new OpenAPI specification file to generate. If not specified or empty, no spec file will be generated.
|
|
2131
2149
|
* @param pluginFilePath File path of the api plugin file to generate.
|
|
2132
2150
|
*/
|
|
2133
|
-
async generateForCopilot(manifestPath, filter, outputSpecPath, pluginFilePath, signal) {
|
|
2151
|
+
async generateForCopilot(manifestPath, filter, outputSpecPath, pluginFilePath, existingPluginFilePath, signal) {
|
|
2134
2152
|
const result = {
|
|
2135
2153
|
allSuccess: true,
|
|
2136
2154
|
warnings: [],
|
|
@@ -2147,7 +2165,15 @@ class SpecParser {
|
|
|
2147
2165
|
const [updatedManifest, apiPlugin, warnings] = await ManifestUpdater.updateManifestWithAiPlugin(manifestPath, outputSpecPath, pluginFilePath, newSpec, this.options, authInfo);
|
|
2148
2166
|
result.warnings.push(...warnings);
|
|
2149
2167
|
await fs.outputJSON(manifestPath, updatedManifest, { spaces: 4 });
|
|
2150
|
-
|
|
2168
|
+
if (existingPluginFilePath) {
|
|
2169
|
+
const originPluginManifest = (await fs.readJSON(existingPluginFilePath));
|
|
2170
|
+
// TODO (kiota): refactor to avoid generate apiPlugin
|
|
2171
|
+
originPluginManifest.functions = apiPlugin.functions;
|
|
2172
|
+
await fs.outputJSON(pluginFilePath, originPluginManifest, { spaces: 4 });
|
|
2173
|
+
}
|
|
2174
|
+
else {
|
|
2175
|
+
await fs.outputJSON(pluginFilePath, apiPlugin, { spaces: 4 });
|
|
2176
|
+
}
|
|
2151
2177
|
}
|
|
2152
2178
|
catch (err) {
|
|
2153
2179
|
if (err instanceof SpecParserError) {
|