@microsoft/m365-spec-parser 0.1.1-alpha.44548b1b3.0 → 0.1.1-alpha.54a90c74e.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 +149 -67
- package/dist/index.esm2017.js.map +1 -1
- package/dist/index.esm2017.mjs +401 -144
- package/dist/index.esm2017.mjs.map +1 -1
- package/dist/index.esm5.js +151 -67
- package/dist/index.esm5.js.map +1 -1
- package/dist/index.node.cjs.js +404 -143
- package/dist/index.node.cjs.js.map +1 -1
- package/dist/src/constants.d.ts +5 -1
- package/dist/src/index.browser.d.ts +1 -1
- package/dist/src/index.d.ts +1 -1
- package/dist/src/interfaces.d.ts +46 -18
- package/dist/src/manifestUpdater.d.ts +8 -4
- package/dist/src/specFilter.d.ts +2 -1
- package/dist/src/specParser.browser.d.ts +9 -1
- package/dist/src/specParser.d.ts +10 -3
- package/dist/src/utils.d.ts +20 -16
- package/package.json +4 -4
package/dist/index.esm2017.js
CHANGED
|
@@ -15,7 +15,8 @@ var ErrorType;
|
|
|
15
15
|
ErrorType["NoExtraAPICanBeAdded"] = "no-extra-api-can-be-added";
|
|
16
16
|
ErrorType["ResolveServerUrlFailed"] = "resolve-server-url-failed";
|
|
17
17
|
ErrorType["SwaggerNotSupported"] = "swagger-not-supported";
|
|
18
|
-
ErrorType["
|
|
18
|
+
ErrorType["MultipleAuthNotSupported"] = "multiple-auth-not-supported";
|
|
19
|
+
ErrorType["SpecVersionNotSupported"] = "spec-version-not-supported";
|
|
19
20
|
ErrorType["ListFailed"] = "list-failed";
|
|
20
21
|
ErrorType["listSupportedAPIInfoFailed"] = "list-supported-api-info-failed";
|
|
21
22
|
ErrorType["FilterSpecFailed"] = "filter-spec-failed";
|
|
@@ -46,7 +47,13 @@ var ValidationStatus;
|
|
|
46
47
|
ValidationStatus[ValidationStatus["Valid"] = 0] = "Valid";
|
|
47
48
|
ValidationStatus[ValidationStatus["Warning"] = 1] = "Warning";
|
|
48
49
|
ValidationStatus[ValidationStatus["Error"] = 2] = "Error";
|
|
49
|
-
})(ValidationStatus || (ValidationStatus = {}));
|
|
50
|
+
})(ValidationStatus || (ValidationStatus = {}));
|
|
51
|
+
var ProjectType;
|
|
52
|
+
(function (ProjectType) {
|
|
53
|
+
ProjectType[ProjectType["Copilot"] = 0] = "Copilot";
|
|
54
|
+
ProjectType[ProjectType["SME"] = 1] = "SME";
|
|
55
|
+
ProjectType[ProjectType["TeamsAi"] = 2] = "TeamsAi";
|
|
56
|
+
})(ProjectType || (ProjectType = {}));
|
|
50
57
|
|
|
51
58
|
// Copyright (c) Microsoft Corporation.
|
|
52
59
|
class SpecParserError extends Error {
|
|
@@ -73,7 +80,9 @@ ConstantString.ResolveServerUrlFailed = "Unable to resolve the server URL: pleas
|
|
|
73
80
|
ConstantString.OperationOnlyContainsOptionalParam = "Operation %s contains multiple optional parameters. The first optional parameter is used for this command.";
|
|
74
81
|
ConstantString.ConvertSwaggerToOpenAPI = "The Swagger 2.0 file has been converted to OpenAPI 3.0.";
|
|
75
82
|
ConstantString.SwaggerNotSupported = "Swagger 2.0 is not supported. Please convert to OpenAPI 3.0 manually before proceeding.";
|
|
76
|
-
ConstantString.
|
|
83
|
+
ConstantString.SpecVersionNotSupported = "Unsupported OpenAPI version %s. Please use version 3.0.x.";
|
|
84
|
+
ConstantString.MultipleAuthNotSupported = "Multiple authentication methods are unsupported. Ensure all selected APIs use identical authentication.";
|
|
85
|
+
ConstantString.UnsupportedSchema = "Unsupported schema in %s %s: %s";
|
|
77
86
|
ConstantString.WrappedCardVersion = "devPreview";
|
|
78
87
|
ConstantString.WrappedCardSchema = "https://developer.microsoft.com/json-schemas/teams/vDevPreview/MicrosoftTeams.ResponseRenderingTemplate.schema.json";
|
|
79
88
|
ConstantString.WrappedCardResponseLayout = "list";
|
|
@@ -85,6 +94,7 @@ ConstantString.AdaptiveCardType = "AdaptiveCard";
|
|
|
85
94
|
ConstantString.TextBlockType = "TextBlock";
|
|
86
95
|
ConstantString.ContainerType = "Container";
|
|
87
96
|
ConstantString.RegistrationIdPostfix = "REGISTRATION_ID";
|
|
97
|
+
ConstantString.OAuthRegistrationIdPostFix = "OAUTH_REGISTRATION_ID";
|
|
88
98
|
ConstantString.ResponseCodeFor20X = [
|
|
89
99
|
"200",
|
|
90
100
|
"201",
|
|
@@ -144,11 +154,23 @@ ConstantString.FullDescriptionMaxLens = 4000;
|
|
|
144
154
|
ConstantString.CommandDescriptionMaxLens = 128;
|
|
145
155
|
ConstantString.ParameterDescriptionMaxLens = 128;
|
|
146
156
|
ConstantString.CommandTitleMaxLens = 32;
|
|
147
|
-
ConstantString.ParameterTitleMaxLens = 32;
|
|
157
|
+
ConstantString.ParameterTitleMaxLens = 32;
|
|
158
|
+
ConstantString.SMERequiredParamsMaxNum = 5;
|
|
148
159
|
|
|
149
160
|
// Copyright (c) Microsoft Corporation.
|
|
150
161
|
class Utils {
|
|
151
|
-
static
|
|
162
|
+
static hasNestedObjectInSchema(schema) {
|
|
163
|
+
if (schema.type === "object") {
|
|
164
|
+
for (const property in schema.properties) {
|
|
165
|
+
const nestedSchema = schema.properties[property];
|
|
166
|
+
if (nestedSchema.type === "object") {
|
|
167
|
+
return true;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
static checkParameters(paramObject, isCopilot) {
|
|
152
174
|
const paramResult = {
|
|
153
175
|
requiredNum: 0,
|
|
154
176
|
optionalNum: 0,
|
|
@@ -160,7 +182,20 @@ class Utils {
|
|
|
160
182
|
for (let i = 0; i < paramObject.length; i++) {
|
|
161
183
|
const param = paramObject[i];
|
|
162
184
|
const schema = param.schema;
|
|
185
|
+
if (isCopilot && this.hasNestedObjectInSchema(schema)) {
|
|
186
|
+
paramResult.isValid = false;
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
163
189
|
const isRequiredWithoutDefault = param.required && schema.default === undefined;
|
|
190
|
+
if (isCopilot) {
|
|
191
|
+
if (isRequiredWithoutDefault) {
|
|
192
|
+
paramResult.requiredNum = paramResult.requiredNum + 1;
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
paramResult.optionalNum = paramResult.optionalNum + 1;
|
|
196
|
+
}
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
164
199
|
if (param.in === "header" || param.in === "cookie") {
|
|
165
200
|
if (isRequiredWithoutDefault) {
|
|
166
201
|
paramResult.isValid = false;
|
|
@@ -187,7 +222,7 @@ class Utils {
|
|
|
187
222
|
}
|
|
188
223
|
return paramResult;
|
|
189
224
|
}
|
|
190
|
-
static checkPostBody(schema, isRequired = false) {
|
|
225
|
+
static checkPostBody(schema, isRequired = false, isCopilot = false) {
|
|
191
226
|
var _a;
|
|
192
227
|
const paramResult = {
|
|
193
228
|
requiredNum: 0,
|
|
@@ -198,6 +233,10 @@ class Utils {
|
|
|
198
233
|
return paramResult;
|
|
199
234
|
}
|
|
200
235
|
const isRequiredWithoutDefault = isRequired && schema.default === undefined;
|
|
236
|
+
if (isCopilot && this.hasNestedObjectInSchema(schema)) {
|
|
237
|
+
paramResult.isValid = false;
|
|
238
|
+
return paramResult;
|
|
239
|
+
}
|
|
201
240
|
if (schema.type === "string" ||
|
|
202
241
|
schema.type === "integer" ||
|
|
203
242
|
schema.type === "boolean" ||
|
|
@@ -216,19 +255,22 @@ class Utils {
|
|
|
216
255
|
if (schema.required && ((_a = schema.required) === null || _a === void 0 ? void 0 : _a.indexOf(property)) >= 0) {
|
|
217
256
|
isRequired = true;
|
|
218
257
|
}
|
|
219
|
-
const result = Utils.checkPostBody(properties[property], isRequired);
|
|
258
|
+
const result = Utils.checkPostBody(properties[property], isRequired, isCopilot);
|
|
220
259
|
paramResult.requiredNum += result.requiredNum;
|
|
221
260
|
paramResult.optionalNum += result.optionalNum;
|
|
222
261
|
paramResult.isValid = paramResult.isValid && result.isValid;
|
|
223
262
|
}
|
|
224
263
|
}
|
|
225
264
|
else {
|
|
226
|
-
if (isRequiredWithoutDefault) {
|
|
265
|
+
if (isRequiredWithoutDefault && !isCopilot) {
|
|
227
266
|
paramResult.isValid = false;
|
|
228
267
|
}
|
|
229
268
|
}
|
|
230
269
|
return paramResult;
|
|
231
270
|
}
|
|
271
|
+
static containMultipleMediaTypes(bodyObject) {
|
|
272
|
+
return Object.keys((bodyObject === null || bodyObject === void 0 ? void 0 : bodyObject.content) || {}).length > 1;
|
|
273
|
+
}
|
|
232
274
|
/**
|
|
233
275
|
* Checks if the given API is supported.
|
|
234
276
|
* @param {string} method - The HTTP method of the API.
|
|
@@ -243,32 +285,40 @@ class Utils {
|
|
|
243
285
|
* 5. response body should be “application/json” and not empty, and response code should be 20X
|
|
244
286
|
* 6. only support request body with “application/json” content type
|
|
245
287
|
*/
|
|
246
|
-
static isSupportedApi(method, path, spec,
|
|
288
|
+
static isSupportedApi(method, path, spec, options) {
|
|
289
|
+
var _a;
|
|
247
290
|
const pathObj = spec.paths[path];
|
|
248
291
|
method = method.toLocaleLowerCase();
|
|
249
292
|
if (pathObj) {
|
|
250
|
-
if ((
|
|
251
|
-
pathObj[method]) {
|
|
293
|
+
if (((_a = options.allowMethods) === null || _a === void 0 ? void 0 : _a.includes(method)) && pathObj[method]) {
|
|
252
294
|
const securities = pathObj[method].security;
|
|
253
|
-
const
|
|
254
|
-
|
|
255
|
-
|
|
295
|
+
const isTeamsAi = options.projectType === ProjectType.TeamsAi;
|
|
296
|
+
const isCopilot = options.projectType === ProjectType.Copilot;
|
|
297
|
+
// Teams AI project doesn't care about auth, it will use authProvider for user to implement
|
|
298
|
+
if (!isTeamsAi) {
|
|
299
|
+
const authArray = Utils.getAuthArray(securities, spec);
|
|
300
|
+
if (!Utils.isSupportedAuth(authArray, options)) {
|
|
301
|
+
return false;
|
|
302
|
+
}
|
|
256
303
|
}
|
|
257
304
|
const operationObject = pathObj[method];
|
|
258
|
-
if (!allowMissingId && !operationObject.operationId) {
|
|
305
|
+
if (!options.allowMissingId && !operationObject.operationId) {
|
|
259
306
|
return false;
|
|
260
307
|
}
|
|
261
308
|
const paramObject = operationObject.parameters;
|
|
262
309
|
const requestBody = operationObject.requestBody;
|
|
263
310
|
const requestJsonBody = requestBody === null || requestBody === void 0 ? void 0 : requestBody.content["application/json"];
|
|
264
|
-
|
|
265
|
-
if (mediaTypesCount > 1) {
|
|
311
|
+
if (!isTeamsAi && Utils.containMultipleMediaTypes(requestBody)) {
|
|
266
312
|
return false;
|
|
267
313
|
}
|
|
268
|
-
const responseJson = Utils.getResponseJson(operationObject);
|
|
314
|
+
const responseJson = Utils.getResponseJson(operationObject, isTeamsAi);
|
|
269
315
|
if (Object.keys(responseJson).length === 0) {
|
|
270
316
|
return false;
|
|
271
317
|
}
|
|
318
|
+
// Teams AI project doesn't care about request parameters/body
|
|
319
|
+
if (isTeamsAi) {
|
|
320
|
+
return true;
|
|
321
|
+
}
|
|
272
322
|
let requestBodyParamResult = {
|
|
273
323
|
requiredNum: 0,
|
|
274
324
|
optionalNum: 0,
|
|
@@ -276,18 +326,26 @@ class Utils {
|
|
|
276
326
|
};
|
|
277
327
|
if (requestJsonBody) {
|
|
278
328
|
const requestBodySchema = requestJsonBody.schema;
|
|
279
|
-
|
|
329
|
+
if (isCopilot && requestBodySchema.type !== "object") {
|
|
330
|
+
return false;
|
|
331
|
+
}
|
|
332
|
+
requestBodyParamResult = Utils.checkPostBody(requestBodySchema, requestBody.required, isCopilot);
|
|
280
333
|
}
|
|
281
334
|
if (!requestBodyParamResult.isValid) {
|
|
282
335
|
return false;
|
|
283
336
|
}
|
|
284
|
-
const paramResult = Utils.checkParameters(paramObject);
|
|
337
|
+
const paramResult = Utils.checkParameters(paramObject, isCopilot);
|
|
285
338
|
if (!paramResult.isValid) {
|
|
286
339
|
return false;
|
|
287
340
|
}
|
|
341
|
+
// Copilot support arbitrary parameters
|
|
342
|
+
if (isCopilot) {
|
|
343
|
+
return true;
|
|
344
|
+
}
|
|
288
345
|
if (requestBodyParamResult.requiredNum + paramResult.requiredNum > 1) {
|
|
289
|
-
if (allowMultipleParameters &&
|
|
290
|
-
requestBodyParamResult.requiredNum + paramResult.requiredNum <=
|
|
346
|
+
if (options.allowMultipleParameters &&
|
|
347
|
+
requestBodyParamResult.requiredNum + paramResult.requiredNum <=
|
|
348
|
+
ConstantString.SMERequiredParamsMaxNum) {
|
|
291
349
|
return true;
|
|
292
350
|
}
|
|
293
351
|
return false;
|
|
@@ -306,29 +364,20 @@ class Utils {
|
|
|
306
364
|
}
|
|
307
365
|
return false;
|
|
308
366
|
}
|
|
309
|
-
static isSupportedAuth(
|
|
310
|
-
if (
|
|
367
|
+
static isSupportedAuth(authSchemeArray, options) {
|
|
368
|
+
if (authSchemeArray.length === 0) {
|
|
311
369
|
return true;
|
|
312
370
|
}
|
|
313
|
-
if (allowAPIKeyAuth || allowOauth2) {
|
|
371
|
+
if (options.allowAPIKeyAuth || options.allowOauth2 || options.allowBearerTokenAuth) {
|
|
314
372
|
// Currently we don't support multiple auth in one operation
|
|
315
|
-
if (
|
|
373
|
+
if (authSchemeArray.length > 0 && authSchemeArray.every((auths) => auths.length > 1)) {
|
|
316
374
|
return false;
|
|
317
375
|
}
|
|
318
|
-
for (const auths of
|
|
376
|
+
for (const auths of authSchemeArray) {
|
|
319
377
|
if (auths.length === 1) {
|
|
320
|
-
if (
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
else if (!allowAPIKeyAuth &&
|
|
324
|
-
allowOauth2 &&
|
|
325
|
-
Utils.isBearerTokenAuth(auths[0].authSchema)) {
|
|
326
|
-
return true;
|
|
327
|
-
}
|
|
328
|
-
else if (allowAPIKeyAuth &&
|
|
329
|
-
allowOauth2 &&
|
|
330
|
-
(Utils.isAPIKeyAuth(auths[0].authSchema) ||
|
|
331
|
-
Utils.isBearerTokenAuth(auths[0].authSchema))) {
|
|
378
|
+
if ((options.allowAPIKeyAuth && Utils.isAPIKeyAuth(auths[0].authScheme)) ||
|
|
379
|
+
(options.allowOauth2 && Utils.isOAuthWithAuthCodeFlow(auths[0].authScheme)) ||
|
|
380
|
+
(options.allowBearerTokenAuth && Utils.isBearerTokenAuth(auths[0].authScheme))) {
|
|
332
381
|
return true;
|
|
333
382
|
}
|
|
334
383
|
}
|
|
@@ -336,13 +385,17 @@ class Utils {
|
|
|
336
385
|
}
|
|
337
386
|
return false;
|
|
338
387
|
}
|
|
339
|
-
static
|
|
340
|
-
return
|
|
388
|
+
static isBearerTokenAuth(authScheme) {
|
|
389
|
+
return authScheme.type === "http" && authScheme.scheme === "bearer";
|
|
341
390
|
}
|
|
342
|
-
static
|
|
343
|
-
return
|
|
344
|
-
|
|
345
|
-
|
|
391
|
+
static isAPIKeyAuth(authScheme) {
|
|
392
|
+
return authScheme.type === "apiKey";
|
|
393
|
+
}
|
|
394
|
+
static isOAuthWithAuthCodeFlow(authScheme) {
|
|
395
|
+
if (authScheme.type === "oauth2" && authScheme.flows && authScheme.flows.authorizationCode) {
|
|
396
|
+
return true;
|
|
397
|
+
}
|
|
398
|
+
return false;
|
|
346
399
|
}
|
|
347
400
|
static getAuthArray(securities, spec) {
|
|
348
401
|
var _a;
|
|
@@ -355,7 +408,7 @@ class Utils {
|
|
|
355
408
|
for (const name in security) {
|
|
356
409
|
const auth = securitySchemas[name];
|
|
357
410
|
authArray.push({
|
|
358
|
-
|
|
411
|
+
authScheme: auth,
|
|
359
412
|
name: name,
|
|
360
413
|
});
|
|
361
414
|
}
|
|
@@ -370,18 +423,19 @@ class Utils {
|
|
|
370
423
|
static updateFirstLetter(str) {
|
|
371
424
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
372
425
|
}
|
|
373
|
-
static getResponseJson(operationObject) {
|
|
426
|
+
static getResponseJson(operationObject, isTeamsAiProject = false) {
|
|
374
427
|
var _a, _b;
|
|
375
428
|
let json = {};
|
|
376
429
|
for (const code of ConstantString.ResponseCodeFor20X) {
|
|
377
430
|
const responseObject = (_a = operationObject === null || operationObject === void 0 ? void 0 : operationObject.responses) === null || _a === void 0 ? void 0 : _a[code];
|
|
378
|
-
const mediaTypesCount = Object.keys((responseObject === null || responseObject === void 0 ? void 0 : responseObject.content) || {}).length;
|
|
379
|
-
if (mediaTypesCount > 1) {
|
|
380
|
-
return {};
|
|
381
|
-
}
|
|
382
431
|
if ((_b = responseObject === null || responseObject === void 0 ? void 0 : responseObject.content) === null || _b === void 0 ? void 0 : _b["application/json"]) {
|
|
383
432
|
json = responseObject.content["application/json"];
|
|
384
|
-
|
|
433
|
+
if (!isTeamsAiProject && Utils.containMultipleMediaTypes(responseObject)) {
|
|
434
|
+
json = {};
|
|
435
|
+
}
|
|
436
|
+
else {
|
|
437
|
+
break;
|
|
438
|
+
}
|
|
385
439
|
}
|
|
386
440
|
}
|
|
387
441
|
return json;
|
|
@@ -455,7 +509,7 @@ class Utils {
|
|
|
455
509
|
}
|
|
456
510
|
return errors;
|
|
457
511
|
}
|
|
458
|
-
static validateServer(spec,
|
|
512
|
+
static validateServer(spec, options) {
|
|
459
513
|
const errors = [];
|
|
460
514
|
let hasTopLevelServers = false;
|
|
461
515
|
let hasPathLevelServers = false;
|
|
@@ -476,7 +530,7 @@ class Utils {
|
|
|
476
530
|
}
|
|
477
531
|
for (const method in methods) {
|
|
478
532
|
const operationObject = methods[method];
|
|
479
|
-
if (Utils.isSupportedApi(method, path, spec,
|
|
533
|
+
if (Utils.isSupportedApi(method, path, spec, options)) {
|
|
480
534
|
if ((operationObject === null || operationObject === void 0 ? void 0 : operationObject.servers) && operationObject.servers.length >= 1) {
|
|
481
535
|
hasOperationLevelServers = true;
|
|
482
536
|
const serverErrors = Utils.checkServerUrl(operationObject.servers);
|
|
@@ -519,6 +573,7 @@ class Utils {
|
|
|
519
573
|
Utils.updateParameterWithInputType(schema, parameter);
|
|
520
574
|
}
|
|
521
575
|
if (isRequired && schema.default === undefined) {
|
|
576
|
+
parameter.isRequired = true;
|
|
522
577
|
requiredParams.push(parameter);
|
|
523
578
|
}
|
|
524
579
|
else {
|
|
@@ -563,7 +618,7 @@ class Utils {
|
|
|
563
618
|
param.value = schema.default;
|
|
564
619
|
}
|
|
565
620
|
}
|
|
566
|
-
static parseApiInfo(operationItem,
|
|
621
|
+
static parseApiInfo(operationItem, options) {
|
|
567
622
|
var _a, _b;
|
|
568
623
|
const requiredParams = [];
|
|
569
624
|
const optionalParams = [];
|
|
@@ -577,11 +632,12 @@ class Utils {
|
|
|
577
632
|
description: ((_a = param.description) !== null && _a !== void 0 ? _a : "").slice(0, ConstantString.ParameterDescriptionMaxLens),
|
|
578
633
|
};
|
|
579
634
|
const schema = param.schema;
|
|
580
|
-
if (allowMultipleParameters && schema) {
|
|
635
|
+
if (options.allowMultipleParameters && schema) {
|
|
581
636
|
Utils.updateParameterWithInputType(schema, parameter);
|
|
582
637
|
}
|
|
583
638
|
if (param.in !== "header" && param.in !== "cookie") {
|
|
584
639
|
if (param.required && (schema === null || schema === void 0 ? void 0 : schema.default) === undefined) {
|
|
640
|
+
parameter.isRequired = true;
|
|
585
641
|
requiredParams.push(parameter);
|
|
586
642
|
}
|
|
587
643
|
else {
|
|
@@ -595,7 +651,7 @@ class Utils {
|
|
|
595
651
|
const requestJson = requestBody.content["application/json"];
|
|
596
652
|
if (Object.keys(requestJson).length !== 0) {
|
|
597
653
|
const schema = requestJson.schema;
|
|
598
|
-
const [requiredP, optionalP] = Utils.generateParametersFromSchema(schema, "requestBody", allowMultipleParameters, requestBody.required);
|
|
654
|
+
const [requiredP, optionalP] = Utils.generateParametersFromSchema(schema, "requestBody", !!options.allowMultipleParameters, requestBody.required);
|
|
599
655
|
requiredParams.push(...requiredP);
|
|
600
656
|
optionalParams.push(...optionalP);
|
|
601
657
|
}
|
|
@@ -626,14 +682,13 @@ class Utils {
|
|
|
626
682
|
}
|
|
627
683
|
return [command, warning];
|
|
628
684
|
}
|
|
629
|
-
static listSupportedAPIs(spec,
|
|
685
|
+
static listSupportedAPIs(spec, options) {
|
|
630
686
|
const paths = spec.paths;
|
|
631
687
|
const result = {};
|
|
632
688
|
for (const path in paths) {
|
|
633
689
|
const methods = paths[path];
|
|
634
690
|
for (const method in methods) {
|
|
635
|
-
|
|
636
|
-
if (Utils.isSupportedApi(method, path, spec, allowMissingId, allowAPIKeyAuth, allowMultipleParameters, allowOauth2)) {
|
|
691
|
+
if (Utils.isSupportedApi(method, path, spec, options)) {
|
|
637
692
|
const operationObject = methods[method];
|
|
638
693
|
result[`${method.toUpperCase()} ${path}`] = operationObject;
|
|
639
694
|
}
|
|
@@ -641,7 +696,7 @@ class Utils {
|
|
|
641
696
|
}
|
|
642
697
|
return result;
|
|
643
698
|
}
|
|
644
|
-
static validateSpec(spec, parser, isSwaggerFile,
|
|
699
|
+
static validateSpec(spec, parser, isSwaggerFile, options) {
|
|
645
700
|
const errors = [];
|
|
646
701
|
const warnings = [];
|
|
647
702
|
if (isSwaggerFile) {
|
|
@@ -651,7 +706,7 @@ class Utils {
|
|
|
651
706
|
});
|
|
652
707
|
}
|
|
653
708
|
// Server validation
|
|
654
|
-
const serverErrors = Utils.validateServer(spec,
|
|
709
|
+
const serverErrors = Utils.validateServer(spec, options);
|
|
655
710
|
errors.push(...serverErrors);
|
|
656
711
|
// Remote reference not supported
|
|
657
712
|
const refPaths = parser.$refs.paths();
|
|
@@ -664,7 +719,7 @@ class Utils {
|
|
|
664
719
|
});
|
|
665
720
|
}
|
|
666
721
|
// No supported API
|
|
667
|
-
const apiMap = Utils.listSupportedAPIs(spec,
|
|
722
|
+
const apiMap = Utils.listSupportedAPIs(spec, options);
|
|
668
723
|
if (Object.keys(apiMap).length === 0) {
|
|
669
724
|
errors.push({
|
|
670
725
|
type: ErrorType.NoSupportedApi,
|
|
@@ -716,6 +771,19 @@ class Utils {
|
|
|
716
771
|
}
|
|
717
772
|
return safeRegistrationIdEnvName;
|
|
718
773
|
}
|
|
774
|
+
static getAllAPICount(spec) {
|
|
775
|
+
let count = 0;
|
|
776
|
+
const paths = spec.paths;
|
|
777
|
+
for (const path in paths) {
|
|
778
|
+
const methods = paths[path];
|
|
779
|
+
for (const method in methods) {
|
|
780
|
+
if (ConstantString.AllOperationMethods.includes(method)) {
|
|
781
|
+
count++;
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
return count;
|
|
786
|
+
}
|
|
719
787
|
}
|
|
720
788
|
|
|
721
789
|
// Copyright (c) Microsoft Corporation.
|
|
@@ -734,7 +802,10 @@ class SpecParser {
|
|
|
734
802
|
allowSwagger: false,
|
|
735
803
|
allowAPIKeyAuth: false,
|
|
736
804
|
allowMultipleParameters: false,
|
|
805
|
+
allowBearerTokenAuth: false,
|
|
737
806
|
allowOauth2: false,
|
|
807
|
+
allowMethods: ["get", "post"],
|
|
808
|
+
projectType: ProjectType.SME,
|
|
738
809
|
};
|
|
739
810
|
this.pathOrSpec = pathOrDoc;
|
|
740
811
|
this.parser = new SwaggerParser();
|
|
@@ -771,7 +842,7 @@ class SpecParser {
|
|
|
771
842
|
],
|
|
772
843
|
};
|
|
773
844
|
}
|
|
774
|
-
return Utils.validateSpec(this.spec, this.parser, !!this.isSwaggerFile, this.options
|
|
845
|
+
return Utils.validateSpec(this.spec, this.parser, !!this.isSwaggerFile, this.options);
|
|
775
846
|
}
|
|
776
847
|
catch (err) {
|
|
777
848
|
throw new SpecParserError(err.toString(), ErrorType.ValidateFailed);
|
|
@@ -790,7 +861,7 @@ class SpecParser {
|
|
|
790
861
|
if (!operationId) {
|
|
791
862
|
continue;
|
|
792
863
|
}
|
|
793
|
-
const [command, warning] = Utils.parseApiInfo(pathObjectItem, this.options
|
|
864
|
+
const [command, warning] = Utils.parseApiInfo(pathObjectItem, this.options);
|
|
794
865
|
const apiInfo = {
|
|
795
866
|
method: method,
|
|
796
867
|
path: path,
|
|
@@ -827,6 +898,17 @@ class SpecParser {
|
|
|
827
898
|
async getFilteredSpecs(filter, signal) {
|
|
828
899
|
throw new Error("Method not implemented.");
|
|
829
900
|
}
|
|
901
|
+
/**
|
|
902
|
+
* Generates and update artifacts from the OpenAPI specification file. Generate Adaptive Cards, update Teams app manifest, and generate a new OpenAPI specification file.
|
|
903
|
+
* @param manifestPath A file path of the Teams app manifest file to update.
|
|
904
|
+
* @param filter An array of strings that represent the filters to apply when generating the artifacts. If filter is empty, it would process nothing.
|
|
905
|
+
* @param outputSpecPath File path of the new OpenAPI specification file to generate. If not specified or empty, no spec file will be generated.
|
|
906
|
+
* @param pluginFilePath File path of the api plugin file to generate.
|
|
907
|
+
*/
|
|
908
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
|
909
|
+
async generateForCopilot(manifestPath, filter, outputSpecPath, pluginFilePath, signal) {
|
|
910
|
+
throw new Error("Method not implemented.");
|
|
911
|
+
}
|
|
830
912
|
/**
|
|
831
913
|
* Generates and update artifacts from the OpenAPI specification file. Generate Adaptive Cards, update Teams app manifest, and generate a new OpenAPI specification file.
|
|
832
914
|
* @param manifestPath A file path of the Teams app manifest file to update.
|
|
@@ -836,7 +918,7 @@ class SpecParser {
|
|
|
836
918
|
* @param isMe Boolean that indicates whether the project is an Messaging Extension. For Messaging Extension, composeExtensions will be added in Teams app manifest.
|
|
837
919
|
*/
|
|
838
920
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
839
|
-
async generate(manifestPath, filter, outputSpecPath, adaptiveCardFolder, signal
|
|
921
|
+
async generate(manifestPath, filter, outputSpecPath, adaptiveCardFolder, signal) {
|
|
840
922
|
throw new Error("Method not implemented.");
|
|
841
923
|
}
|
|
842
924
|
async loadSpec() {
|
|
@@ -853,7 +935,7 @@ class SpecParser {
|
|
|
853
935
|
if (this.apiMap !== undefined) {
|
|
854
936
|
return this.apiMap;
|
|
855
937
|
}
|
|
856
|
-
const result = Utils.listSupportedAPIs(spec, this.options
|
|
938
|
+
const result = Utils.listSupportedAPIs(spec, this.options);
|
|
857
939
|
this.apiMap = result;
|
|
858
940
|
return result;
|
|
859
941
|
}
|