@microsoft/m365-spec-parser 0.1.1-alpha.f4dd51600.0 → 0.1.1-alpha.fbb412c19.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 +47 -17
- package/dist/index.esm2017.js.map +1 -1
- package/dist/index.esm2017.mjs +144 -104
- package/dist/index.esm2017.mjs.map +1 -1
- package/dist/index.esm5.js +47 -17
- package/dist/index.esm5.js.map +1 -1
- package/dist/index.node.cjs.js +146 -104
- package/dist/index.node.cjs.js.map +1 -1
- package/dist/src/constants.d.ts +5 -3
- package/dist/src/interfaces.d.ts +8 -0
- package/dist/src/manifestUpdater.d.ts +6 -4
- package/dist/src/specParser.d.ts +1 -0
- package/dist/src/utils.d.ts +1 -0
- package/package.json +3 -4
package/dist/index.esm5.js
CHANGED
|
@@ -117,7 +117,7 @@ ConstantString.RemoteRefNotSupported = "Remote reference is not supported: %s.";
|
|
|
117
117
|
ConstantString.MissingOperationId = "Missing operationIds: %s.";
|
|
118
118
|
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.";
|
|
119
119
|
ConstantString.AdditionalPropertiesNotSupported = "'additionalProperties' is not supported, and will be ignored.";
|
|
120
|
-
ConstantString.SchemaNotSupported = "'oneOf', 'anyOf', and 'not' schema are not supported: %s.";
|
|
120
|
+
ConstantString.SchemaNotSupported = "'oneOf', 'allOf', 'anyOf', and 'not' schema are not supported: %s.";
|
|
121
121
|
ConstantString.UnknownSchema = "Unknown schema: %s.";
|
|
122
122
|
ConstantString.UrlProtocolNotSupported = "Server url is not correct: protocol %s is not supported, you should use https protocol instead.";
|
|
123
123
|
ConstantString.RelativeServerUrlNotSupported = "Server url is not correct: relative server url is not supported.";
|
|
@@ -139,8 +139,12 @@ ConstantString.AdaptiveCardType = "AdaptiveCard";
|
|
|
139
139
|
ConstantString.TextBlockType = "TextBlock";
|
|
140
140
|
ConstantString.ImageType = "Image";
|
|
141
141
|
ConstantString.ContainerType = "Container";
|
|
142
|
-
ConstantString.RegistrationIdPostfix =
|
|
143
|
-
|
|
142
|
+
ConstantString.RegistrationIdPostfix = {
|
|
143
|
+
apiKey: "REGISTRATION_ID",
|
|
144
|
+
oauth2: "CONFIGURATION_ID",
|
|
145
|
+
http: "REGISTRATION_ID",
|
|
146
|
+
openIdConnect: "REGISTRATION_ID",
|
|
147
|
+
};
|
|
144
148
|
ConstantString.ResponseCodeFor20X = [
|
|
145
149
|
"200",
|
|
146
150
|
"201",
|
|
@@ -199,6 +203,7 @@ ConstantString.ShortDescriptionMaxLens = 80;
|
|
|
199
203
|
ConstantString.FullDescriptionMaxLens = 4000;
|
|
200
204
|
ConstantString.CommandDescriptionMaxLens = 128;
|
|
201
205
|
ConstantString.ParameterDescriptionMaxLens = 128;
|
|
206
|
+
ConstantString.ConversationStarterMaxLens = 50;
|
|
202
207
|
ConstantString.CommandTitleMaxLens = 32;
|
|
203
208
|
ConstantString.ParameterTitleMaxLens = 32;
|
|
204
209
|
ConstantString.SMERequiredParamsMaxNum = 5;
|
|
@@ -235,9 +240,10 @@ class Utils {
|
|
|
235
240
|
var _a;
|
|
236
241
|
const result = [];
|
|
237
242
|
const securitySchemas = (_a = spec.components) === null || _a === void 0 ? void 0 : _a.securitySchemes;
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
243
|
+
const securitiesArr = securities !== null && securities !== void 0 ? securities : spec.security;
|
|
244
|
+
if (securitiesArr && securitySchemas) {
|
|
245
|
+
for (let i = 0; i < securitiesArr.length; i++) {
|
|
246
|
+
const security = securitiesArr[i];
|
|
241
247
|
const authArray = [];
|
|
242
248
|
for (const name in security) {
|
|
243
249
|
const auth = securitySchemas[name];
|
|
@@ -254,6 +260,25 @@ class Utils {
|
|
|
254
260
|
result.sort((a, b) => a[0].name.localeCompare(b[0].name));
|
|
255
261
|
return result;
|
|
256
262
|
}
|
|
263
|
+
static getAuthInfo(spec) {
|
|
264
|
+
let authInfo = undefined;
|
|
265
|
+
for (const url in spec.paths) {
|
|
266
|
+
for (const method in spec.paths[url]) {
|
|
267
|
+
const operation = spec.paths[url][method];
|
|
268
|
+
const authArray = Utils.getAuthArray(operation.security, spec);
|
|
269
|
+
if (authArray && authArray.length > 0) {
|
|
270
|
+
const currentAuth = authArray[0][0];
|
|
271
|
+
if (!authInfo) {
|
|
272
|
+
authInfo = authArray[0][0];
|
|
273
|
+
}
|
|
274
|
+
else if (authInfo.name !== currentAuth.name) {
|
|
275
|
+
throw new SpecParserError(ConstantString.MultipleAuthNotSupported, ErrorType.MultipleAuthNotSupported);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
return authInfo;
|
|
281
|
+
}
|
|
257
282
|
static updateFirstLetter(str) {
|
|
258
283
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
259
284
|
}
|
|
@@ -635,13 +660,15 @@ class Validator {
|
|
|
635
660
|
const result = { isValid: true, reason: [] };
|
|
636
661
|
const operationObject = this.spec.paths[path][method];
|
|
637
662
|
const { json, multipleMediaType } = Utils.getResponseJson(operationObject);
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
663
|
+
if (this.options.projectType === ProjectType.SME) {
|
|
664
|
+
// only support response body only contains “application/json” content type
|
|
665
|
+
if (multipleMediaType) {
|
|
666
|
+
result.reason.push(ErrorType.ResponseContainMultipleMediaTypes);
|
|
667
|
+
}
|
|
668
|
+
else if (Object.keys(json).length === 0) {
|
|
669
|
+
// response body should not be empty
|
|
670
|
+
result.reason.push(ErrorType.ResponseJsonIsEmpty);
|
|
671
|
+
}
|
|
645
672
|
}
|
|
646
673
|
return result;
|
|
647
674
|
}
|
|
@@ -859,9 +886,6 @@ class CopilotValidator extends Validator {
|
|
|
859
886
|
// validate requestBody
|
|
860
887
|
const requestBody = operationObject.requestBody;
|
|
861
888
|
const requestJsonBody = requestBody === null || requestBody === void 0 ? void 0 : requestBody.content["application/json"];
|
|
862
|
-
if (Utils.containMultipleMediaTypes(requestBody)) {
|
|
863
|
-
result.reason.push(ErrorType.PostBodyContainMultipleMediaTypes);
|
|
864
|
-
}
|
|
865
889
|
if (requestJsonBody) {
|
|
866
890
|
const requestBodySchema = requestJsonBody.schema;
|
|
867
891
|
if (requestBodySchema.type !== "object") {
|
|
@@ -1057,7 +1081,9 @@ class SpecParser {
|
|
|
1057
1081
|
allowMethods: ["get", "post"],
|
|
1058
1082
|
allowConversationStarters: false,
|
|
1059
1083
|
allowResponseSemantics: false,
|
|
1084
|
+
allowConfirmation: false,
|
|
1060
1085
|
projectType: ProjectType.SME,
|
|
1086
|
+
isGptPlugin: false,
|
|
1061
1087
|
};
|
|
1062
1088
|
this.pathOrSpec = pathOrDoc;
|
|
1063
1089
|
this.parser = new SwaggerParser();
|
|
@@ -1073,7 +1099,11 @@ class SpecParser {
|
|
|
1073
1099
|
try {
|
|
1074
1100
|
try {
|
|
1075
1101
|
yield this.loadSpec();
|
|
1076
|
-
yield this.parser.validate(this.spec
|
|
1102
|
+
yield this.parser.validate(this.spec, {
|
|
1103
|
+
validate: {
|
|
1104
|
+
schema: false,
|
|
1105
|
+
},
|
|
1106
|
+
});
|
|
1077
1107
|
}
|
|
1078
1108
|
catch (e) {
|
|
1079
1109
|
return {
|