@microsoft/m365-spec-parser 0.0.2-alpha.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 +846 -0
- package/dist/index.esm2017.js.map +1 -0
- package/dist/index.esm2017.mjs +1314 -0
- package/dist/index.esm2017.mjs.map +1 -0
- package/dist/index.esm5.js +886 -0
- package/dist/index.esm5.js.map +1 -0
- package/dist/index.node.cjs.js +1372 -0
- package/dist/index.node.cjs.js.map +1 -0
- package/dist/src/adaptiveCardGenerator.d.ts +8 -0
- package/dist/src/adaptiveCardWrapper.d.ts +14 -0
- package/dist/src/constants.d.ts +40 -0
- package/dist/src/index.browser.d.ts +5 -0
- package/dist/src/index.d.ts +4 -0
- package/dist/src/interfaces.d.ts +179 -0
- package/dist/src/manifestUpdater.d.ts +8 -0
- package/dist/src/specFilter.d.ts +4 -0
- package/dist/src/specParser.browser.d.ts +45 -0
- package/dist/src/specParser.d.ts +45 -0
- package/dist/src/specParserError.d.ts +5 -0
- package/dist/src/utils.d.ts +44 -0
- package/package.json +86 -0
|
@@ -0,0 +1,886 @@
|
|
|
1
|
+
import SwaggerParser from '@apidevtools/swagger-parser';
|
|
2
|
+
|
|
3
|
+
/******************************************************************************
|
|
4
|
+
Copyright (c) Microsoft Corporation.
|
|
5
|
+
|
|
6
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
7
|
+
purpose with or without fee is hereby granted.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
10
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
11
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
12
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
13
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
14
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
16
|
+
***************************************************************************** */
|
|
17
|
+
|
|
18
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
19
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
20
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
21
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
22
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
23
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
24
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
29
|
+
var e = new Error(message);
|
|
30
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// Copyright (c) Microsoft Corporation.
|
|
34
|
+
/**
|
|
35
|
+
* An enum that represents the types of errors that can occur during validation.
|
|
36
|
+
*/
|
|
37
|
+
var ErrorType;
|
|
38
|
+
(function (ErrorType) {
|
|
39
|
+
ErrorType["SpecNotValid"] = "spec-not-valid";
|
|
40
|
+
ErrorType["RemoteRefNotSupported"] = "remote-ref-not-supported";
|
|
41
|
+
ErrorType["NoServerInformation"] = "no-server-information";
|
|
42
|
+
ErrorType["UrlProtocolNotSupported"] = "url-protocol-not-supported";
|
|
43
|
+
ErrorType["RelativeServerUrlNotSupported"] = "relative-server-url-not-supported";
|
|
44
|
+
ErrorType["NoSupportedApi"] = "no-supported-api";
|
|
45
|
+
ErrorType["NoExtraAPICanBeAdded"] = "no-extra-api-can-be-added";
|
|
46
|
+
ErrorType["ResolveServerUrlFailed"] = "resolve-server-url-failed";
|
|
47
|
+
ErrorType["SwaggerNotSupported"] = "swagger-not-supported";
|
|
48
|
+
ErrorType["MultipleAPIKeyNotSupported"] = "multiple-api-key-not-supported";
|
|
49
|
+
ErrorType["ListFailed"] = "list-failed";
|
|
50
|
+
ErrorType["listSupportedAPIInfoFailed"] = "list-supported-api-info-failed";
|
|
51
|
+
ErrorType["FilterSpecFailed"] = "filter-spec-failed";
|
|
52
|
+
ErrorType["UpdateManifestFailed"] = "update-manifest-failed";
|
|
53
|
+
ErrorType["GenerateAdaptiveCardFailed"] = "generate-adaptive-card-failed";
|
|
54
|
+
ErrorType["GenerateFailed"] = "generate-failed";
|
|
55
|
+
ErrorType["ValidateFailed"] = "validate-failed";
|
|
56
|
+
ErrorType["Cancelled"] = "cancelled";
|
|
57
|
+
ErrorType["Unknown"] = "unknown";
|
|
58
|
+
})(ErrorType || (ErrorType = {}));
|
|
59
|
+
/**
|
|
60
|
+
* An enum that represents the types of warnings that can occur during validation.
|
|
61
|
+
*/
|
|
62
|
+
var WarningType;
|
|
63
|
+
(function (WarningType) {
|
|
64
|
+
WarningType["OperationIdMissing"] = "operationid-missing";
|
|
65
|
+
WarningType["GenerateCardFailed"] = "generate-card-failed";
|
|
66
|
+
WarningType["OperationOnlyContainsOptionalParam"] = "operation-only-contains-optional-param";
|
|
67
|
+
WarningType["ConvertSwaggerToOpenAPI"] = "convert-swagger-to-openapi";
|
|
68
|
+
WarningType["Unknown"] = "unknown";
|
|
69
|
+
})(WarningType || (WarningType = {}));
|
|
70
|
+
/**
|
|
71
|
+
* An enum that represents the validation status of an OpenAPI specification file.
|
|
72
|
+
*/
|
|
73
|
+
var ValidationStatus;
|
|
74
|
+
(function (ValidationStatus) {
|
|
75
|
+
ValidationStatus[ValidationStatus["Valid"] = 0] = "Valid";
|
|
76
|
+
ValidationStatus[ValidationStatus["Warning"] = 1] = "Warning";
|
|
77
|
+
ValidationStatus[ValidationStatus["Error"] = 2] = "Error";
|
|
78
|
+
})(ValidationStatus || (ValidationStatus = {}));
|
|
79
|
+
|
|
80
|
+
// Copyright (c) Microsoft Corporation.
|
|
81
|
+
class SpecParserError extends Error {
|
|
82
|
+
constructor(message, errorType) {
|
|
83
|
+
super(message);
|
|
84
|
+
this.errorType = errorType;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Copyright (c) Microsoft Corporation.
|
|
89
|
+
class ConstantString {
|
|
90
|
+
}
|
|
91
|
+
ConstantString.CancelledMessage = "Operation is cancelled.";
|
|
92
|
+
ConstantString.NoServerInformation = "No server information is found in the OpenAPI description document.";
|
|
93
|
+
ConstantString.RemoteRefNotSupported = "Remote reference is not supported: %s.";
|
|
94
|
+
ConstantString.MissingOperationId = "Missing operationIds: %s.";
|
|
95
|
+
ConstantString.NoSupportedApi = "No supported API is found in the OpenAPI description document: only GET and POST methods are supported, additionally, there can be at most one required parameter, and no auth is allowed.";
|
|
96
|
+
ConstantString.AdditionalPropertiesNotSupported = "'additionalProperties' is not supported, and will be ignored.";
|
|
97
|
+
ConstantString.SchemaNotSupported = "'oneOf', 'anyOf', and 'not' schema are not supported: %s.";
|
|
98
|
+
ConstantString.UnknownSchema = "Unknown schema: %s.";
|
|
99
|
+
ConstantString.UrlProtocolNotSupported = "Server url is not correct: protocol %s is not supported, you should use https protocol instead.";
|
|
100
|
+
ConstantString.RelativeServerUrlNotSupported = "Server url is not correct: relative server url is not supported.";
|
|
101
|
+
ConstantString.ResolveServerUrlFailed = "Unable to resolve the server URL: please make sure that the environment variable %s is defined.";
|
|
102
|
+
ConstantString.OperationOnlyContainsOptionalParam = "Operation %s contains multiple optional parameters. The first optional parameter is used for this command.";
|
|
103
|
+
ConstantString.ConvertSwaggerToOpenAPI = "The Swagger 2.0 file has been converted to OpenAPI 3.0.";
|
|
104
|
+
ConstantString.SwaggerNotSupported = "Swagger 2.0 is not supported. Please convert to OpenAPI 3.0 manually before proceeding.";
|
|
105
|
+
ConstantString.MultipleAPIKeyNotSupported = "Multiple API keys are not supported. Please make sure that all selected APIs use the same API key.";
|
|
106
|
+
ConstantString.WrappedCardVersion = "devPreview";
|
|
107
|
+
ConstantString.WrappedCardSchema = "https://developer.microsoft.com/json-schemas/teams/vDevPreview/MicrosoftTeams.ResponseRenderingTemplate.schema.json";
|
|
108
|
+
ConstantString.WrappedCardResponseLayout = "list";
|
|
109
|
+
ConstantString.GetMethod = "get";
|
|
110
|
+
ConstantString.PostMethod = "post";
|
|
111
|
+
ConstantString.AdaptiveCardVersion = "1.5";
|
|
112
|
+
ConstantString.AdaptiveCardSchema = "http://adaptivecards.io/schemas/adaptive-card.json";
|
|
113
|
+
ConstantString.AdaptiveCardType = "AdaptiveCard";
|
|
114
|
+
ConstantString.TextBlockType = "TextBlock";
|
|
115
|
+
ConstantString.ContainerType = "Container";
|
|
116
|
+
ConstantString.RegistrationIdPostfix = "REGISTRATION_ID";
|
|
117
|
+
ConstantString.ResponseCodeFor20X = [
|
|
118
|
+
"200",
|
|
119
|
+
"201",
|
|
120
|
+
"202",
|
|
121
|
+
"203",
|
|
122
|
+
"204",
|
|
123
|
+
"205",
|
|
124
|
+
"206",
|
|
125
|
+
"207",
|
|
126
|
+
"208",
|
|
127
|
+
"226",
|
|
128
|
+
"default",
|
|
129
|
+
];
|
|
130
|
+
ConstantString.AllOperationMethods = [
|
|
131
|
+
"get",
|
|
132
|
+
"post",
|
|
133
|
+
"put",
|
|
134
|
+
"delete",
|
|
135
|
+
"patch",
|
|
136
|
+
"head",
|
|
137
|
+
"options",
|
|
138
|
+
"trace",
|
|
139
|
+
];
|
|
140
|
+
// TODO: update after investigating the usage of these constants.
|
|
141
|
+
ConstantString.WellknownResultNames = [
|
|
142
|
+
"result",
|
|
143
|
+
"data",
|
|
144
|
+
"items",
|
|
145
|
+
"root",
|
|
146
|
+
"matches",
|
|
147
|
+
"queries",
|
|
148
|
+
"list",
|
|
149
|
+
"output",
|
|
150
|
+
];
|
|
151
|
+
ConstantString.WellknownTitleName = ["title", "name", "summary", "caption", "subject", "label"];
|
|
152
|
+
ConstantString.WellknownSubtitleName = [
|
|
153
|
+
"subtitle",
|
|
154
|
+
"id",
|
|
155
|
+
"uid",
|
|
156
|
+
"description",
|
|
157
|
+
"desc",
|
|
158
|
+
"detail",
|
|
159
|
+
];
|
|
160
|
+
ConstantString.WellknownImageName = [
|
|
161
|
+
"image",
|
|
162
|
+
"icon",
|
|
163
|
+
"avatar",
|
|
164
|
+
"picture",
|
|
165
|
+
"photo",
|
|
166
|
+
"logo",
|
|
167
|
+
"pic",
|
|
168
|
+
"thumbnail",
|
|
169
|
+
"img",
|
|
170
|
+
];
|
|
171
|
+
ConstantString.ShortDescriptionMaxLens = 80;
|
|
172
|
+
ConstantString.FullDescriptionMaxLens = 4000;
|
|
173
|
+
ConstantString.CommandDescriptionMaxLens = 128;
|
|
174
|
+
ConstantString.ParameterDescriptionMaxLens = 128;
|
|
175
|
+
ConstantString.CommandTitleMaxLens = 32;
|
|
176
|
+
ConstantString.ParameterTitleMaxLens = 32;
|
|
177
|
+
|
|
178
|
+
// Copyright (c) Microsoft Corporation.
|
|
179
|
+
class Utils {
|
|
180
|
+
static checkParameters(paramObject) {
|
|
181
|
+
const paramResult = {
|
|
182
|
+
requiredNum: 0,
|
|
183
|
+
optionalNum: 0,
|
|
184
|
+
isValid: true,
|
|
185
|
+
};
|
|
186
|
+
if (!paramObject) {
|
|
187
|
+
return paramResult;
|
|
188
|
+
}
|
|
189
|
+
for (let i = 0; i < paramObject.length; i++) {
|
|
190
|
+
const param = paramObject[i];
|
|
191
|
+
const schema = param.schema;
|
|
192
|
+
const isRequiredWithoutDefault = param.required && schema.default === undefined;
|
|
193
|
+
if (param.in === "header" || param.in === "cookie") {
|
|
194
|
+
if (isRequiredWithoutDefault) {
|
|
195
|
+
paramResult.isValid = false;
|
|
196
|
+
}
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
if (schema.type !== "boolean" &&
|
|
200
|
+
schema.type !== "string" &&
|
|
201
|
+
schema.type !== "number" &&
|
|
202
|
+
schema.type !== "integer") {
|
|
203
|
+
if (isRequiredWithoutDefault) {
|
|
204
|
+
paramResult.isValid = false;
|
|
205
|
+
}
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
if (param.in === "query" || param.in === "path") {
|
|
209
|
+
if (isRequiredWithoutDefault) {
|
|
210
|
+
paramResult.requiredNum = paramResult.requiredNum + 1;
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
paramResult.optionalNum = paramResult.optionalNum + 1;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return paramResult;
|
|
218
|
+
}
|
|
219
|
+
static checkPostBody(schema, isRequired = false) {
|
|
220
|
+
var _a;
|
|
221
|
+
const paramResult = {
|
|
222
|
+
requiredNum: 0,
|
|
223
|
+
optionalNum: 0,
|
|
224
|
+
isValid: true,
|
|
225
|
+
};
|
|
226
|
+
if (Object.keys(schema).length === 0) {
|
|
227
|
+
return paramResult;
|
|
228
|
+
}
|
|
229
|
+
const isRequiredWithoutDefault = isRequired && schema.default === undefined;
|
|
230
|
+
if (schema.type === "string" ||
|
|
231
|
+
schema.type === "integer" ||
|
|
232
|
+
schema.type === "boolean" ||
|
|
233
|
+
schema.type === "number") {
|
|
234
|
+
if (isRequiredWithoutDefault) {
|
|
235
|
+
paramResult.requiredNum = paramResult.requiredNum + 1;
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
paramResult.optionalNum = paramResult.optionalNum + 1;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
else if (schema.type === "object") {
|
|
242
|
+
const { properties } = schema;
|
|
243
|
+
for (const property in properties) {
|
|
244
|
+
let isRequired = false;
|
|
245
|
+
if (schema.required && ((_a = schema.required) === null || _a === void 0 ? void 0 : _a.indexOf(property)) >= 0) {
|
|
246
|
+
isRequired = true;
|
|
247
|
+
}
|
|
248
|
+
const result = Utils.checkPostBody(properties[property], isRequired);
|
|
249
|
+
paramResult.requiredNum += result.requiredNum;
|
|
250
|
+
paramResult.optionalNum += result.optionalNum;
|
|
251
|
+
paramResult.isValid = paramResult.isValid && result.isValid;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
if (isRequiredWithoutDefault) {
|
|
256
|
+
paramResult.isValid = false;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return paramResult;
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Checks if the given API is supported.
|
|
263
|
+
* @param {string} method - The HTTP method of the API.
|
|
264
|
+
* @param {string} path - The path of the API.
|
|
265
|
+
* @param {OpenAPIV3.Document} spec - The OpenAPI specification document.
|
|
266
|
+
* @returns {boolean} - Returns true if the API is supported, false otherwise.
|
|
267
|
+
* @description The following APIs are supported:
|
|
268
|
+
* 1. only support Get/Post operation without auth property
|
|
269
|
+
* 2. parameter inside query or path only support string, number, boolean and integer
|
|
270
|
+
* 3. parameter inside post body only support string, number, boolean, integer and object
|
|
271
|
+
* 4. request body + required parameters <= 1
|
|
272
|
+
* 5. response body should be “application/json” and not empty, and response code should be 20X
|
|
273
|
+
* 6. only support request body with “application/json” content type
|
|
274
|
+
*/
|
|
275
|
+
static isSupportedApi(method, path, spec, allowMissingId, allowAPIKeyAuth, allowMultipleParameters, allowOauth2) {
|
|
276
|
+
const pathObj = spec.paths[path];
|
|
277
|
+
method = method.toLocaleLowerCase();
|
|
278
|
+
if (pathObj) {
|
|
279
|
+
if ((method === ConstantString.PostMethod || method === ConstantString.GetMethod) &&
|
|
280
|
+
pathObj[method]) {
|
|
281
|
+
const securities = pathObj[method].security;
|
|
282
|
+
const authArray = Utils.getAuthArray(securities, spec);
|
|
283
|
+
if (!Utils.isSupportedAuth(authArray, allowAPIKeyAuth, allowOauth2)) {
|
|
284
|
+
return false;
|
|
285
|
+
}
|
|
286
|
+
const operationObject = pathObj[method];
|
|
287
|
+
if (!allowMissingId && !operationObject.operationId) {
|
|
288
|
+
return false;
|
|
289
|
+
}
|
|
290
|
+
const paramObject = operationObject.parameters;
|
|
291
|
+
const requestBody = operationObject.requestBody;
|
|
292
|
+
const requestJsonBody = requestBody === null || requestBody === void 0 ? void 0 : requestBody.content["application/json"];
|
|
293
|
+
const mediaTypesCount = Object.keys((requestBody === null || requestBody === void 0 ? void 0 : requestBody.content) || {}).length;
|
|
294
|
+
if (mediaTypesCount > 1) {
|
|
295
|
+
return false;
|
|
296
|
+
}
|
|
297
|
+
const responseJson = Utils.getResponseJson(operationObject);
|
|
298
|
+
if (Object.keys(responseJson).length === 0) {
|
|
299
|
+
return false;
|
|
300
|
+
}
|
|
301
|
+
let requestBodyParamResult = {
|
|
302
|
+
requiredNum: 0,
|
|
303
|
+
optionalNum: 0,
|
|
304
|
+
isValid: true,
|
|
305
|
+
};
|
|
306
|
+
if (requestJsonBody) {
|
|
307
|
+
const requestBodySchema = requestJsonBody.schema;
|
|
308
|
+
requestBodyParamResult = Utils.checkPostBody(requestBodySchema, requestBody.required);
|
|
309
|
+
}
|
|
310
|
+
if (!requestBodyParamResult.isValid) {
|
|
311
|
+
return false;
|
|
312
|
+
}
|
|
313
|
+
const paramResult = Utils.checkParameters(paramObject);
|
|
314
|
+
if (!paramResult.isValid) {
|
|
315
|
+
return false;
|
|
316
|
+
}
|
|
317
|
+
if (requestBodyParamResult.requiredNum + paramResult.requiredNum > 1) {
|
|
318
|
+
if (allowMultipleParameters &&
|
|
319
|
+
requestBodyParamResult.requiredNum + paramResult.requiredNum <= 5) {
|
|
320
|
+
return true;
|
|
321
|
+
}
|
|
322
|
+
return false;
|
|
323
|
+
}
|
|
324
|
+
else if (requestBodyParamResult.requiredNum +
|
|
325
|
+
requestBodyParamResult.optionalNum +
|
|
326
|
+
paramResult.requiredNum +
|
|
327
|
+
paramResult.optionalNum ===
|
|
328
|
+
0) {
|
|
329
|
+
return false;
|
|
330
|
+
}
|
|
331
|
+
else {
|
|
332
|
+
return true;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
return false;
|
|
337
|
+
}
|
|
338
|
+
static isSupportedAuth(authSchemaArray, allowAPIKeyAuth, allowOauth2) {
|
|
339
|
+
if (authSchemaArray.length === 0) {
|
|
340
|
+
return true;
|
|
341
|
+
}
|
|
342
|
+
if (allowAPIKeyAuth || allowOauth2) {
|
|
343
|
+
// Currently we don't support multiple auth in one operation
|
|
344
|
+
if (authSchemaArray.length > 0 && authSchemaArray.every((auths) => auths.length > 1)) {
|
|
345
|
+
return false;
|
|
346
|
+
}
|
|
347
|
+
for (const auths of authSchemaArray) {
|
|
348
|
+
if (auths.length === 1) {
|
|
349
|
+
if (!allowOauth2 && allowAPIKeyAuth && Utils.isAPIKeyAuth(auths[0].authSchema)) {
|
|
350
|
+
return true;
|
|
351
|
+
}
|
|
352
|
+
else if (!allowAPIKeyAuth && allowOauth2 && Utils.isBearerTokenAuth(auths[0].authSchema)) {
|
|
353
|
+
return true;
|
|
354
|
+
}
|
|
355
|
+
else if (allowAPIKeyAuth &&
|
|
356
|
+
allowOauth2 &&
|
|
357
|
+
(Utils.isAPIKeyAuth(auths[0].authSchema) || Utils.isBearerTokenAuth(auths[0].authSchema))) {
|
|
358
|
+
return true;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
return false;
|
|
364
|
+
}
|
|
365
|
+
static isAPIKeyAuth(authSchema) {
|
|
366
|
+
return authSchema.type === "apiKey";
|
|
367
|
+
}
|
|
368
|
+
static isBearerTokenAuth(authSchema) {
|
|
369
|
+
return (authSchema.type === "oauth2" ||
|
|
370
|
+
authSchema.type === "openIdConnect" ||
|
|
371
|
+
(authSchema.type === "http" && authSchema.scheme === "bearer"));
|
|
372
|
+
}
|
|
373
|
+
static getAuthArray(securities, spec) {
|
|
374
|
+
var _a;
|
|
375
|
+
const result = [];
|
|
376
|
+
const securitySchemas = (_a = spec.components) === null || _a === void 0 ? void 0 : _a.securitySchemes;
|
|
377
|
+
if (securities && securitySchemas) {
|
|
378
|
+
for (let i = 0; i < securities.length; i++) {
|
|
379
|
+
const security = securities[i];
|
|
380
|
+
const authArray = [];
|
|
381
|
+
for (const name in security) {
|
|
382
|
+
const auth = securitySchemas[name];
|
|
383
|
+
authArray.push({
|
|
384
|
+
authSchema: auth,
|
|
385
|
+
name: name,
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
if (authArray.length > 0) {
|
|
389
|
+
result.push(authArray);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
result.sort((a, b) => a[0].name.localeCompare(b[0].name));
|
|
394
|
+
return result;
|
|
395
|
+
}
|
|
396
|
+
static updateFirstLetter(str) {
|
|
397
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
398
|
+
}
|
|
399
|
+
static getResponseJson(operationObject) {
|
|
400
|
+
var _a, _b;
|
|
401
|
+
let json = {};
|
|
402
|
+
for (const code of ConstantString.ResponseCodeFor20X) {
|
|
403
|
+
const responseObject = (_a = operationObject === null || operationObject === void 0 ? void 0 : operationObject.responses) === null || _a === void 0 ? void 0 : _a[code];
|
|
404
|
+
const mediaTypesCount = Object.keys((responseObject === null || responseObject === void 0 ? void 0 : responseObject.content) || {}).length;
|
|
405
|
+
if (mediaTypesCount > 1) {
|
|
406
|
+
return {};
|
|
407
|
+
}
|
|
408
|
+
if ((_b = responseObject === null || responseObject === void 0 ? void 0 : responseObject.content) === null || _b === void 0 ? void 0 : _b["application/json"]) {
|
|
409
|
+
json = responseObject.content["application/json"];
|
|
410
|
+
break;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
return json;
|
|
414
|
+
}
|
|
415
|
+
static convertPathToCamelCase(path) {
|
|
416
|
+
const pathSegments = path.split(/[./{]/);
|
|
417
|
+
const camelCaseSegments = pathSegments.map((segment) => {
|
|
418
|
+
segment = segment.replace(/}/g, "");
|
|
419
|
+
return segment.charAt(0).toUpperCase() + segment.slice(1);
|
|
420
|
+
});
|
|
421
|
+
const camelCasePath = camelCaseSegments.join("");
|
|
422
|
+
return camelCasePath;
|
|
423
|
+
}
|
|
424
|
+
static getUrlProtocol(urlString) {
|
|
425
|
+
try {
|
|
426
|
+
const url = new URL(urlString);
|
|
427
|
+
return url.protocol;
|
|
428
|
+
}
|
|
429
|
+
catch (err) {
|
|
430
|
+
return undefined;
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
static resolveServerUrl(url) {
|
|
434
|
+
const placeHolderReg = /\${{\s*([a-zA-Z_][a-zA-Z0-9_]*)\s*}}/g;
|
|
435
|
+
let matches = placeHolderReg.exec(url);
|
|
436
|
+
let newUrl = url;
|
|
437
|
+
while (matches != null) {
|
|
438
|
+
const envVar = matches[1];
|
|
439
|
+
const envVal = process.env[envVar];
|
|
440
|
+
if (!envVal) {
|
|
441
|
+
throw new Error(Utils.format(ConstantString.ResolveServerUrlFailed, envVar));
|
|
442
|
+
}
|
|
443
|
+
else {
|
|
444
|
+
newUrl = newUrl.replace(matches[0], envVal);
|
|
445
|
+
}
|
|
446
|
+
matches = placeHolderReg.exec(url);
|
|
447
|
+
}
|
|
448
|
+
return newUrl;
|
|
449
|
+
}
|
|
450
|
+
static checkServerUrl(servers) {
|
|
451
|
+
const errors = [];
|
|
452
|
+
let serverUrl;
|
|
453
|
+
try {
|
|
454
|
+
serverUrl = Utils.resolveServerUrl(servers[0].url);
|
|
455
|
+
}
|
|
456
|
+
catch (err) {
|
|
457
|
+
errors.push({
|
|
458
|
+
type: ErrorType.ResolveServerUrlFailed,
|
|
459
|
+
content: err.message,
|
|
460
|
+
data: servers,
|
|
461
|
+
});
|
|
462
|
+
return errors;
|
|
463
|
+
}
|
|
464
|
+
const protocol = Utils.getUrlProtocol(serverUrl);
|
|
465
|
+
if (!protocol) {
|
|
466
|
+
// Relative server url is not supported
|
|
467
|
+
errors.push({
|
|
468
|
+
type: ErrorType.RelativeServerUrlNotSupported,
|
|
469
|
+
content: ConstantString.RelativeServerUrlNotSupported,
|
|
470
|
+
data: servers,
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
else if (protocol !== "https:") {
|
|
474
|
+
// Http server url is not supported
|
|
475
|
+
const protocolString = protocol.slice(0, -1);
|
|
476
|
+
errors.push({
|
|
477
|
+
type: ErrorType.UrlProtocolNotSupported,
|
|
478
|
+
content: Utils.format(ConstantString.UrlProtocolNotSupported, protocol.slice(0, -1)),
|
|
479
|
+
data: protocolString,
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
return errors;
|
|
483
|
+
}
|
|
484
|
+
static validateServer(spec, allowMissingId, allowAPIKeyAuth, allowMultipleParameters, allowOauth2) {
|
|
485
|
+
const errors = [];
|
|
486
|
+
let hasTopLevelServers = false;
|
|
487
|
+
let hasPathLevelServers = false;
|
|
488
|
+
let hasOperationLevelServers = false;
|
|
489
|
+
if (spec.servers && spec.servers.length >= 1) {
|
|
490
|
+
hasTopLevelServers = true;
|
|
491
|
+
// for multiple server, we only use the first url
|
|
492
|
+
const serverErrors = Utils.checkServerUrl(spec.servers);
|
|
493
|
+
errors.push(...serverErrors);
|
|
494
|
+
}
|
|
495
|
+
const paths = spec.paths;
|
|
496
|
+
for (const path in paths) {
|
|
497
|
+
const methods = paths[path];
|
|
498
|
+
if ((methods === null || methods === void 0 ? void 0 : methods.servers) && methods.servers.length >= 1) {
|
|
499
|
+
hasPathLevelServers = true;
|
|
500
|
+
const serverErrors = Utils.checkServerUrl(methods.servers);
|
|
501
|
+
errors.push(...serverErrors);
|
|
502
|
+
}
|
|
503
|
+
for (const method in methods) {
|
|
504
|
+
const operationObject = methods[method];
|
|
505
|
+
if (Utils.isSupportedApi(method, path, spec, allowMissingId, allowAPIKeyAuth, allowMultipleParameters, allowOauth2)) {
|
|
506
|
+
if ((operationObject === null || operationObject === void 0 ? void 0 : operationObject.servers) && operationObject.servers.length >= 1) {
|
|
507
|
+
hasOperationLevelServers = true;
|
|
508
|
+
const serverErrors = Utils.checkServerUrl(operationObject.servers);
|
|
509
|
+
errors.push(...serverErrors);
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
if (!hasTopLevelServers && !hasPathLevelServers && !hasOperationLevelServers) {
|
|
515
|
+
errors.push({
|
|
516
|
+
type: ErrorType.NoServerInformation,
|
|
517
|
+
content: ConstantString.NoServerInformation,
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
return errors;
|
|
521
|
+
}
|
|
522
|
+
static isWellKnownName(name, wellknownNameList) {
|
|
523
|
+
for (let i = 0; i < wellknownNameList.length; i++) {
|
|
524
|
+
name = name.replace(/_/g, "").replace(/-/g, "");
|
|
525
|
+
if (name.toLowerCase().includes(wellknownNameList[i])) {
|
|
526
|
+
return true;
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
return false;
|
|
530
|
+
}
|
|
531
|
+
static generateParametersFromSchema(schema, name, allowMultipleParameters, isRequired = false) {
|
|
532
|
+
var _a, _b;
|
|
533
|
+
const requiredParams = [];
|
|
534
|
+
const optionalParams = [];
|
|
535
|
+
if (schema.type === "string" ||
|
|
536
|
+
schema.type === "integer" ||
|
|
537
|
+
schema.type === "boolean" ||
|
|
538
|
+
schema.type === "number") {
|
|
539
|
+
const parameter = {
|
|
540
|
+
name: name,
|
|
541
|
+
title: Utils.updateFirstLetter(name).slice(0, ConstantString.ParameterTitleMaxLens),
|
|
542
|
+
description: ((_a = schema.description) !== null && _a !== void 0 ? _a : "").slice(0, ConstantString.ParameterDescriptionMaxLens),
|
|
543
|
+
};
|
|
544
|
+
if (allowMultipleParameters) {
|
|
545
|
+
Utils.updateParameterWithInputType(schema, parameter);
|
|
546
|
+
}
|
|
547
|
+
if (isRequired && schema.default === undefined) {
|
|
548
|
+
requiredParams.push(parameter);
|
|
549
|
+
}
|
|
550
|
+
else {
|
|
551
|
+
optionalParams.push(parameter);
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
else if (schema.type === "object") {
|
|
555
|
+
const { properties } = schema;
|
|
556
|
+
for (const property in properties) {
|
|
557
|
+
let isRequired = false;
|
|
558
|
+
if (schema.required && ((_b = schema.required) === null || _b === void 0 ? void 0 : _b.indexOf(property)) >= 0) {
|
|
559
|
+
isRequired = true;
|
|
560
|
+
}
|
|
561
|
+
const [requiredP, optionalP] = Utils.generateParametersFromSchema(properties[property], property, allowMultipleParameters, isRequired);
|
|
562
|
+
requiredParams.push(...requiredP);
|
|
563
|
+
optionalParams.push(...optionalP);
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
return [requiredParams, optionalParams];
|
|
567
|
+
}
|
|
568
|
+
static updateParameterWithInputType(schema, param) {
|
|
569
|
+
if (schema.enum) {
|
|
570
|
+
param.inputType = "choiceset";
|
|
571
|
+
param.choices = [];
|
|
572
|
+
for (let i = 0; i < schema.enum.length; i++) {
|
|
573
|
+
param.choices.push({
|
|
574
|
+
title: schema.enum[i],
|
|
575
|
+
value: schema.enum[i],
|
|
576
|
+
});
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
else if (schema.type === "string") {
|
|
580
|
+
param.inputType = "text";
|
|
581
|
+
}
|
|
582
|
+
else if (schema.type === "integer" || schema.type === "number") {
|
|
583
|
+
param.inputType = "number";
|
|
584
|
+
}
|
|
585
|
+
else if (schema.type === "boolean") {
|
|
586
|
+
param.inputType = "toggle";
|
|
587
|
+
}
|
|
588
|
+
if (schema.default) {
|
|
589
|
+
param.value = schema.default;
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
static parseApiInfo(operationItem, allowMultipleParameters) {
|
|
593
|
+
var _a, _b;
|
|
594
|
+
const requiredParams = [];
|
|
595
|
+
const optionalParams = [];
|
|
596
|
+
const paramObject = operationItem.parameters;
|
|
597
|
+
if (paramObject) {
|
|
598
|
+
paramObject.forEach((param) => {
|
|
599
|
+
var _a;
|
|
600
|
+
const parameter = {
|
|
601
|
+
name: param.name,
|
|
602
|
+
title: Utils.updateFirstLetter(param.name).slice(0, ConstantString.ParameterTitleMaxLens),
|
|
603
|
+
description: ((_a = param.description) !== null && _a !== void 0 ? _a : "").slice(0, ConstantString.ParameterDescriptionMaxLens),
|
|
604
|
+
};
|
|
605
|
+
const schema = param.schema;
|
|
606
|
+
if (allowMultipleParameters && schema) {
|
|
607
|
+
Utils.updateParameterWithInputType(schema, parameter);
|
|
608
|
+
}
|
|
609
|
+
if (param.in !== "header" && param.in !== "cookie") {
|
|
610
|
+
if (param.required && (schema === null || schema === void 0 ? void 0 : schema.default) === undefined) {
|
|
611
|
+
requiredParams.push(parameter);
|
|
612
|
+
}
|
|
613
|
+
else {
|
|
614
|
+
optionalParams.push(parameter);
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
});
|
|
618
|
+
}
|
|
619
|
+
if (operationItem.requestBody) {
|
|
620
|
+
const requestBody = operationItem.requestBody;
|
|
621
|
+
const requestJson = requestBody.content["application/json"];
|
|
622
|
+
if (Object.keys(requestJson).length !== 0) {
|
|
623
|
+
const schema = requestJson.schema;
|
|
624
|
+
const [requiredP, optionalP] = Utils.generateParametersFromSchema(schema, "requestBody", allowMultipleParameters, requestBody.required);
|
|
625
|
+
requiredParams.push(...requiredP);
|
|
626
|
+
optionalParams.push(...optionalP);
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
const operationId = operationItem.operationId;
|
|
630
|
+
const parameters = [];
|
|
631
|
+
if (requiredParams.length !== 0) {
|
|
632
|
+
parameters.push(...requiredParams);
|
|
633
|
+
}
|
|
634
|
+
else {
|
|
635
|
+
parameters.push(optionalParams[0]);
|
|
636
|
+
}
|
|
637
|
+
const command = {
|
|
638
|
+
context: ["compose"],
|
|
639
|
+
type: "query",
|
|
640
|
+
title: ((_a = operationItem.summary) !== null && _a !== void 0 ? _a : "").slice(0, ConstantString.CommandTitleMaxLens),
|
|
641
|
+
id: operationId,
|
|
642
|
+
parameters: parameters,
|
|
643
|
+
description: ((_b = operationItem.description) !== null && _b !== void 0 ? _b : "").slice(0, ConstantString.CommandDescriptionMaxLens),
|
|
644
|
+
};
|
|
645
|
+
let warning = undefined;
|
|
646
|
+
if (requiredParams.length === 0 && optionalParams.length > 1) {
|
|
647
|
+
warning = {
|
|
648
|
+
type: WarningType.OperationOnlyContainsOptionalParam,
|
|
649
|
+
content: Utils.format(ConstantString.OperationOnlyContainsOptionalParam, operationId),
|
|
650
|
+
data: operationId,
|
|
651
|
+
};
|
|
652
|
+
}
|
|
653
|
+
return [command, warning];
|
|
654
|
+
}
|
|
655
|
+
static listSupportedAPIs(spec, allowMissingId, allowAPIKeyAuth, allowMultipleParameters, allowOauth2) {
|
|
656
|
+
const paths = spec.paths;
|
|
657
|
+
const result = {};
|
|
658
|
+
for (const path in paths) {
|
|
659
|
+
const methods = paths[path];
|
|
660
|
+
for (const method in methods) {
|
|
661
|
+
// For developer preview, only support GET operation with only 1 parameter without auth
|
|
662
|
+
if (Utils.isSupportedApi(method, path, spec, allowMissingId, allowAPIKeyAuth, allowMultipleParameters, allowOauth2)) {
|
|
663
|
+
const operationObject = methods[method];
|
|
664
|
+
result[`${method.toUpperCase()} ${path}`] = operationObject;
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
return result;
|
|
669
|
+
}
|
|
670
|
+
static validateSpec(spec, parser, isSwaggerFile, allowMissingId, allowAPIKeyAuth, allowMultipleParameters, allowOauth2) {
|
|
671
|
+
const errors = [];
|
|
672
|
+
const warnings = [];
|
|
673
|
+
if (isSwaggerFile) {
|
|
674
|
+
warnings.push({
|
|
675
|
+
type: WarningType.ConvertSwaggerToOpenAPI,
|
|
676
|
+
content: ConstantString.ConvertSwaggerToOpenAPI,
|
|
677
|
+
});
|
|
678
|
+
}
|
|
679
|
+
// Server validation
|
|
680
|
+
const serverErrors = Utils.validateServer(spec, allowMissingId, allowAPIKeyAuth, allowMultipleParameters, allowOauth2);
|
|
681
|
+
errors.push(...serverErrors);
|
|
682
|
+
// Remote reference not supported
|
|
683
|
+
const refPaths = parser.$refs.paths();
|
|
684
|
+
// refPaths [0] is the current spec file path
|
|
685
|
+
if (refPaths.length > 1) {
|
|
686
|
+
errors.push({
|
|
687
|
+
type: ErrorType.RemoteRefNotSupported,
|
|
688
|
+
content: Utils.format(ConstantString.RemoteRefNotSupported, refPaths.join(", ")),
|
|
689
|
+
data: refPaths,
|
|
690
|
+
});
|
|
691
|
+
}
|
|
692
|
+
// No supported API
|
|
693
|
+
const apiMap = Utils.listSupportedAPIs(spec, allowMissingId, allowAPIKeyAuth, allowMultipleParameters, allowOauth2);
|
|
694
|
+
if (Object.keys(apiMap).length === 0) {
|
|
695
|
+
errors.push({
|
|
696
|
+
type: ErrorType.NoSupportedApi,
|
|
697
|
+
content: ConstantString.NoSupportedApi,
|
|
698
|
+
});
|
|
699
|
+
}
|
|
700
|
+
// OperationId missing
|
|
701
|
+
const apisMissingOperationId = [];
|
|
702
|
+
for (const key in apiMap) {
|
|
703
|
+
const pathObjectItem = apiMap[key];
|
|
704
|
+
if (!pathObjectItem.operationId) {
|
|
705
|
+
apisMissingOperationId.push(key);
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
if (apisMissingOperationId.length > 0) {
|
|
709
|
+
warnings.push({
|
|
710
|
+
type: WarningType.OperationIdMissing,
|
|
711
|
+
content: Utils.format(ConstantString.MissingOperationId, apisMissingOperationId.join(", ")),
|
|
712
|
+
data: apisMissingOperationId,
|
|
713
|
+
});
|
|
714
|
+
}
|
|
715
|
+
let status = ValidationStatus.Valid;
|
|
716
|
+
if (warnings.length > 0 && errors.length === 0) {
|
|
717
|
+
status = ValidationStatus.Warning;
|
|
718
|
+
}
|
|
719
|
+
else if (errors.length > 0) {
|
|
720
|
+
status = ValidationStatus.Error;
|
|
721
|
+
}
|
|
722
|
+
return {
|
|
723
|
+
status,
|
|
724
|
+
warnings,
|
|
725
|
+
errors,
|
|
726
|
+
};
|
|
727
|
+
}
|
|
728
|
+
static format(str, ...args) {
|
|
729
|
+
let index = 0;
|
|
730
|
+
return str.replace(/%s/g, () => {
|
|
731
|
+
const arg = args[index++];
|
|
732
|
+
return arg !== undefined ? arg : "";
|
|
733
|
+
});
|
|
734
|
+
}
|
|
735
|
+
static getSafeRegistrationIdEnvName(authName) {
|
|
736
|
+
if (!authName) {
|
|
737
|
+
return "";
|
|
738
|
+
}
|
|
739
|
+
let safeRegistrationIdEnvName = authName.toUpperCase().replace(/[^A-Z0-9_]/g, "_");
|
|
740
|
+
if (!safeRegistrationIdEnvName.match(/^[A-Z]/)) {
|
|
741
|
+
safeRegistrationIdEnvName = "PREFIX_" + safeRegistrationIdEnvName;
|
|
742
|
+
}
|
|
743
|
+
return safeRegistrationIdEnvName;
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
// Copyright (c) Microsoft Corporation.
|
|
748
|
+
/**
|
|
749
|
+
* A class that parses an OpenAPI specification file and provides methods to validate, list, and generate artifacts.
|
|
750
|
+
*/
|
|
751
|
+
class SpecParser {
|
|
752
|
+
/**
|
|
753
|
+
* Creates a new instance of the SpecParser class.
|
|
754
|
+
* @param pathOrDoc The path to the OpenAPI specification file or the OpenAPI specification object.
|
|
755
|
+
* @param options The options for parsing the OpenAPI specification file.
|
|
756
|
+
*/
|
|
757
|
+
constructor(pathOrDoc, options) {
|
|
758
|
+
this.defaultOptions = {
|
|
759
|
+
allowMissingId: false,
|
|
760
|
+
allowSwagger: false,
|
|
761
|
+
allowAPIKeyAuth: false,
|
|
762
|
+
allowMultipleParameters: false,
|
|
763
|
+
allowOauth2: false,
|
|
764
|
+
};
|
|
765
|
+
this.pathOrSpec = pathOrDoc;
|
|
766
|
+
this.parser = new SwaggerParser();
|
|
767
|
+
this.options = Object.assign(Object.assign({}, this.defaultOptions), (options !== null && options !== void 0 ? options : {}));
|
|
768
|
+
}
|
|
769
|
+
/**
|
|
770
|
+
* Validates the OpenAPI specification file and returns a validation result.
|
|
771
|
+
*
|
|
772
|
+
* @returns A validation result object that contains information about any errors or warnings in the specification file.
|
|
773
|
+
*/
|
|
774
|
+
validate() {
|
|
775
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
776
|
+
try {
|
|
777
|
+
try {
|
|
778
|
+
yield this.loadSpec();
|
|
779
|
+
yield this.parser.validate(this.spec);
|
|
780
|
+
}
|
|
781
|
+
catch (e) {
|
|
782
|
+
return {
|
|
783
|
+
status: ValidationStatus.Error,
|
|
784
|
+
warnings: [],
|
|
785
|
+
errors: [{ type: ErrorType.SpecNotValid, content: e.toString() }],
|
|
786
|
+
};
|
|
787
|
+
}
|
|
788
|
+
if (!this.options.allowSwagger && this.isSwaggerFile) {
|
|
789
|
+
return {
|
|
790
|
+
status: ValidationStatus.Error,
|
|
791
|
+
warnings: [],
|
|
792
|
+
errors: [
|
|
793
|
+
{ type: ErrorType.SwaggerNotSupported, content: ConstantString.SwaggerNotSupported },
|
|
794
|
+
],
|
|
795
|
+
};
|
|
796
|
+
}
|
|
797
|
+
return Utils.validateSpec(this.spec, this.parser, !!this.isSwaggerFile, this.options.allowMissingId, this.options.allowAPIKeyAuth, this.options.allowMultipleParameters, this.options.allowOauth2);
|
|
798
|
+
}
|
|
799
|
+
catch (err) {
|
|
800
|
+
throw new SpecParserError(err.toString(), ErrorType.ValidateFailed);
|
|
801
|
+
}
|
|
802
|
+
});
|
|
803
|
+
}
|
|
804
|
+
listSupportedAPIInfo() {
|
|
805
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
806
|
+
try {
|
|
807
|
+
yield this.loadSpec();
|
|
808
|
+
const apiMap = this.getAllSupportedAPIs(this.spec);
|
|
809
|
+
const apiInfos = [];
|
|
810
|
+
for (const key in apiMap) {
|
|
811
|
+
const pathObjectItem = apiMap[key];
|
|
812
|
+
const [method, path] = key.split(" ");
|
|
813
|
+
const operationId = pathObjectItem.operationId;
|
|
814
|
+
// In Browser environment, this api is by default not support api without operationId
|
|
815
|
+
if (!operationId) {
|
|
816
|
+
continue;
|
|
817
|
+
}
|
|
818
|
+
const [command, warning] = Utils.parseApiInfo(pathObjectItem, this.options.allowMultipleParameters);
|
|
819
|
+
const apiInfo = {
|
|
820
|
+
method: method,
|
|
821
|
+
path: path,
|
|
822
|
+
title: command.title,
|
|
823
|
+
id: operationId,
|
|
824
|
+
parameters: command.parameters,
|
|
825
|
+
description: command.description,
|
|
826
|
+
};
|
|
827
|
+
if (warning) {
|
|
828
|
+
apiInfo.warning = warning;
|
|
829
|
+
}
|
|
830
|
+
apiInfos.push(apiInfo);
|
|
831
|
+
}
|
|
832
|
+
return apiInfos;
|
|
833
|
+
}
|
|
834
|
+
catch (err) {
|
|
835
|
+
throw new SpecParserError(err.toString(), ErrorType.listSupportedAPIInfoFailed);
|
|
836
|
+
}
|
|
837
|
+
});
|
|
838
|
+
}
|
|
839
|
+
/**
|
|
840
|
+
* Lists all the OpenAPI operations in the specification file.
|
|
841
|
+
* @returns A string array that represents the HTTP method and path of each operation, such as ['GET /pets/{petId}', 'GET /user/{userId}']
|
|
842
|
+
* according to copilot plugin spec, only list get and post method without auth
|
|
843
|
+
*/
|
|
844
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
|
845
|
+
list() {
|
|
846
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
847
|
+
throw new Error("Method not implemented.");
|
|
848
|
+
});
|
|
849
|
+
}
|
|
850
|
+
/**
|
|
851
|
+
* Generates and update artifacts from the OpenAPI specification file. Generate Adaptive Cards, update Teams app manifest, and generate a new OpenAPI specification file.
|
|
852
|
+
* @param manifestPath A file path of the Teams app manifest file to update.
|
|
853
|
+
* @param filter An array of strings that represent the filters to apply when generating the artifacts. If filter is empty, it would process nothing.
|
|
854
|
+
* @param outputSpecPath File path of the new OpenAPI specification file to generate. If not specified or empty, no spec file will be generated.
|
|
855
|
+
* @param adaptiveCardFolder Folder path where the Adaptive Card files will be generated. If not specified or empty, Adaptive Card files will not be generated.
|
|
856
|
+
*/
|
|
857
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
|
858
|
+
generate(manifestPath, filter, outputSpecPath, adaptiveCardFolder, signal) {
|
|
859
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
860
|
+
throw new Error("Method not implemented.");
|
|
861
|
+
});
|
|
862
|
+
}
|
|
863
|
+
loadSpec() {
|
|
864
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
865
|
+
if (!this.spec) {
|
|
866
|
+
this.unResolveSpec = (yield this.parser.parse(this.pathOrSpec));
|
|
867
|
+
if (!this.unResolveSpec.openapi && this.unResolveSpec.swagger === "2.0") {
|
|
868
|
+
this.isSwaggerFile = true;
|
|
869
|
+
}
|
|
870
|
+
const clonedUnResolveSpec = JSON.parse(JSON.stringify(this.unResolveSpec));
|
|
871
|
+
this.spec = (yield this.parser.dereference(clonedUnResolveSpec));
|
|
872
|
+
}
|
|
873
|
+
});
|
|
874
|
+
}
|
|
875
|
+
getAllSupportedAPIs(spec) {
|
|
876
|
+
if (this.apiMap !== undefined) {
|
|
877
|
+
return this.apiMap;
|
|
878
|
+
}
|
|
879
|
+
const result = Utils.listSupportedAPIs(spec, this.options.allowMissingId, this.options.allowAPIKeyAuth, this.options.allowMultipleParameters, this.options.allowOauth2);
|
|
880
|
+
this.apiMap = result;
|
|
881
|
+
return result;
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
export { ConstantString, ErrorType, SpecParser, SpecParserError, ValidationStatus, WarningType };
|
|
886
|
+
//# sourceMappingURL=index.esm5.js.map
|