@microsoft/m365-spec-parser 0.1.1-alpha.42af26ca6.0 → 0.1.1-alpha.45ce3e37a.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 +58 -23
- package/dist/index.esm2017.js.map +1 -1
- package/dist/index.esm2017.mjs +462 -319
- package/dist/index.esm2017.mjs.map +1 -1
- package/dist/index.esm5.js +58 -23
- package/dist/index.esm5.js.map +1 -1
- package/dist/index.node.cjs.js +472 -325
- package/dist/index.node.cjs.js.map +1 -1
- package/dist/src/adaptiveCardWrapper.d.ts +2 -0
- package/dist/src/constants.d.ts +7 -3
- package/dist/src/index.d.ts +1 -1
- package/dist/src/interfaces.d.ts +25 -0
- package/dist/src/manifestUpdater.d.ts +6 -4
- package/dist/src/specParser.browser.d.ts +0 -1
- package/dist/src/specParser.d.ts +1 -1
- package/dist/src/utils.d.ts +1 -0
- package/package.json +3 -4
package/dist/index.esm2017.js
CHANGED
|
@@ -87,7 +87,7 @@ ConstantString.RemoteRefNotSupported = "Remote reference is not supported: %s.";
|
|
|
87
87
|
ConstantString.MissingOperationId = "Missing operationIds: %s.";
|
|
88
88
|
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.";
|
|
89
89
|
ConstantString.AdditionalPropertiesNotSupported = "'additionalProperties' is not supported, and will be ignored.";
|
|
90
|
-
ConstantString.SchemaNotSupported = "'oneOf', 'anyOf', and 'not' schema are not supported: %s.";
|
|
90
|
+
ConstantString.SchemaNotSupported = "'oneOf', 'allOf', 'anyOf', and 'not' schema are not supported: %s.";
|
|
91
91
|
ConstantString.UnknownSchema = "Unknown schema: %s.";
|
|
92
92
|
ConstantString.UrlProtocolNotSupported = "Server url is not correct: protocol %s is not supported, you should use https protocol instead.";
|
|
93
93
|
ConstantString.RelativeServerUrlNotSupported = "Server url is not correct: relative server url is not supported.";
|
|
@@ -107,9 +107,14 @@ ConstantString.AdaptiveCardVersion = "1.5";
|
|
|
107
107
|
ConstantString.AdaptiveCardSchema = "http://adaptivecards.io/schemas/adaptive-card.json";
|
|
108
108
|
ConstantString.AdaptiveCardType = "AdaptiveCard";
|
|
109
109
|
ConstantString.TextBlockType = "TextBlock";
|
|
110
|
+
ConstantString.ImageType = "Image";
|
|
110
111
|
ConstantString.ContainerType = "Container";
|
|
111
|
-
ConstantString.RegistrationIdPostfix =
|
|
112
|
-
|
|
112
|
+
ConstantString.RegistrationIdPostfix = {
|
|
113
|
+
apiKey: "REGISTRATION_ID",
|
|
114
|
+
oauth2: "CONFIGURATION_ID",
|
|
115
|
+
http: "REGISTRATION_ID",
|
|
116
|
+
openIdConnect: "REGISTRATION_ID",
|
|
117
|
+
};
|
|
113
118
|
ConstantString.ResponseCodeFor20X = [
|
|
114
119
|
"200",
|
|
115
120
|
"201",
|
|
@@ -168,9 +173,11 @@ ConstantString.ShortDescriptionMaxLens = 80;
|
|
|
168
173
|
ConstantString.FullDescriptionMaxLens = 4000;
|
|
169
174
|
ConstantString.CommandDescriptionMaxLens = 128;
|
|
170
175
|
ConstantString.ParameterDescriptionMaxLens = 128;
|
|
176
|
+
ConstantString.ConversationStarterMaxLens = 50;
|
|
171
177
|
ConstantString.CommandTitleMaxLens = 32;
|
|
172
178
|
ConstantString.ParameterTitleMaxLens = 32;
|
|
173
|
-
ConstantString.SMERequiredParamsMaxNum = 5;
|
|
179
|
+
ConstantString.SMERequiredParamsMaxNum = 5;
|
|
180
|
+
ConstantString.DefaultPluginId = "plugin_1";
|
|
174
181
|
|
|
175
182
|
// Copyright (c) Microsoft Corporation.
|
|
176
183
|
class Utils {
|
|
@@ -203,9 +210,10 @@ class Utils {
|
|
|
203
210
|
var _a;
|
|
204
211
|
const result = [];
|
|
205
212
|
const securitySchemas = (_a = spec.components) === null || _a === void 0 ? void 0 : _a.securitySchemes;
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
213
|
+
const securitiesArr = securities !== null && securities !== void 0 ? securities : spec.security;
|
|
214
|
+
if (securitiesArr && securitySchemas) {
|
|
215
|
+
for (let i = 0; i < securitiesArr.length; i++) {
|
|
216
|
+
const security = securitiesArr[i];
|
|
209
217
|
const authArray = [];
|
|
210
218
|
for (const name in security) {
|
|
211
219
|
const auth = securitySchemas[name];
|
|
@@ -222,6 +230,25 @@ class Utils {
|
|
|
222
230
|
result.sort((a, b) => a[0].name.localeCompare(b[0].name));
|
|
223
231
|
return result;
|
|
224
232
|
}
|
|
233
|
+
static getAuthInfo(spec) {
|
|
234
|
+
let authInfo = undefined;
|
|
235
|
+
for (const url in spec.paths) {
|
|
236
|
+
for (const method in spec.paths[url]) {
|
|
237
|
+
const operation = spec.paths[url][method];
|
|
238
|
+
const authArray = Utils.getAuthArray(operation.security, spec);
|
|
239
|
+
if (authArray && authArray.length > 0) {
|
|
240
|
+
const currentAuth = authArray[0][0];
|
|
241
|
+
if (!authInfo) {
|
|
242
|
+
authInfo = authArray[0][0];
|
|
243
|
+
}
|
|
244
|
+
else if (authInfo.name !== currentAuth.name) {
|
|
245
|
+
throw new SpecParserError(ConstantString.MultipleAuthNotSupported, ErrorType.MultipleAuthNotSupported);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
return authInfo;
|
|
251
|
+
}
|
|
225
252
|
static updateFirstLetter(str) {
|
|
226
253
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
227
254
|
}
|
|
@@ -550,9 +577,16 @@ class Validator {
|
|
|
550
577
|
const apiMap = this.listAPIs();
|
|
551
578
|
const validAPIs = Object.entries(apiMap).filter(([, value]) => value.isValid);
|
|
552
579
|
if (validAPIs.length === 0) {
|
|
580
|
+
const data = [];
|
|
581
|
+
for (const key in apiMap) {
|
|
582
|
+
const { reason } = apiMap[key];
|
|
583
|
+
const apiInvalidReason = { api: key, reason: reason };
|
|
584
|
+
data.push(apiInvalidReason);
|
|
585
|
+
}
|
|
553
586
|
result.errors.push({
|
|
554
587
|
type: ErrorType.NoSupportedApi,
|
|
555
588
|
content: ConstantString.NoSupportedApi,
|
|
589
|
+
data,
|
|
556
590
|
});
|
|
557
591
|
}
|
|
558
592
|
return result;
|
|
@@ -596,13 +630,15 @@ class Validator {
|
|
|
596
630
|
const result = { isValid: true, reason: [] };
|
|
597
631
|
const operationObject = this.spec.paths[path][method];
|
|
598
632
|
const { json, multipleMediaType } = Utils.getResponseJson(operationObject);
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
633
|
+
if (this.options.projectType === ProjectType.SME) {
|
|
634
|
+
// only support response body only contains “application/json” content type
|
|
635
|
+
if (multipleMediaType) {
|
|
636
|
+
result.reason.push(ErrorType.ResponseContainMultipleMediaTypes);
|
|
637
|
+
}
|
|
638
|
+
else if (Object.keys(json).length === 0) {
|
|
639
|
+
// response body should not be empty
|
|
640
|
+
result.reason.push(ErrorType.ResponseJsonIsEmpty);
|
|
641
|
+
}
|
|
606
642
|
}
|
|
607
643
|
return result;
|
|
608
644
|
}
|
|
@@ -820,9 +856,6 @@ class CopilotValidator extends Validator {
|
|
|
820
856
|
// validate requestBody
|
|
821
857
|
const requestBody = operationObject.requestBody;
|
|
822
858
|
const requestJsonBody = requestBody === null || requestBody === void 0 ? void 0 : requestBody.content["application/json"];
|
|
823
|
-
if (Utils.containMultipleMediaTypes(requestBody)) {
|
|
824
|
-
result.reason.push(ErrorType.PostBodyContainMultipleMediaTypes);
|
|
825
|
-
}
|
|
826
859
|
if (requestJsonBody) {
|
|
827
860
|
const requestBodySchema = requestJsonBody.schema;
|
|
828
861
|
if (requestBodySchema.type !== "object") {
|
|
@@ -862,8 +895,10 @@ class SMEValidator extends Validator {
|
|
|
862
895
|
validationResult = this.validateSpecNoSupportAPI();
|
|
863
896
|
result.errors.push(...validationResult.errors);
|
|
864
897
|
// validate operationId missing
|
|
865
|
-
|
|
866
|
-
|
|
898
|
+
if (this.options.allowMissingId) {
|
|
899
|
+
validationResult = this.validateSpecOperationId();
|
|
900
|
+
result.warnings.push(...validationResult.warnings);
|
|
901
|
+
}
|
|
867
902
|
return result;
|
|
868
903
|
}
|
|
869
904
|
validateAPI(method, path) {
|
|
@@ -1014,7 +1049,11 @@ class SpecParser {
|
|
|
1014
1049
|
allowBearerTokenAuth: false,
|
|
1015
1050
|
allowOauth2: false,
|
|
1016
1051
|
allowMethods: ["get", "post"],
|
|
1052
|
+
allowConversationStarters: false,
|
|
1053
|
+
allowResponseSemantics: false,
|
|
1054
|
+
allowConfirmation: false,
|
|
1017
1055
|
projectType: ProjectType.SME,
|
|
1056
|
+
isGptPlugin: false,
|
|
1018
1057
|
};
|
|
1019
1058
|
this.pathOrSpec = pathOrDoc;
|
|
1020
1059
|
this.parser = new SwaggerParser();
|
|
@@ -1167,12 +1206,8 @@ class SpecParser {
|
|
|
1167
1206
|
}
|
|
1168
1207
|
}
|
|
1169
1208
|
getAPIs(spec) {
|
|
1170
|
-
if (this.apiMap !== undefined) {
|
|
1171
|
-
return this.apiMap;
|
|
1172
|
-
}
|
|
1173
1209
|
const validator = this.getValidator(spec);
|
|
1174
1210
|
const apiMap = validator.listAPIs();
|
|
1175
|
-
this.apiMap = apiMap;
|
|
1176
1211
|
return apiMap;
|
|
1177
1212
|
}
|
|
1178
1213
|
getValidator(spec) {
|